scan_pdf
In Chapter 11, Text Processing, on page 196, I have hit a road block. I cannot make the scipt execute. I have tried it on both Windows 7, and Mac OS-X version 10.9. It seems like something is missing from the text in the book.
The code script is:
import os, os.path
import re
def print_pdf (root, dirs, files):
for file in files:
path = os.path.join (root, file)
path = os.path.normcase (path)
if re.search (r".*\.pdf, path):
print(path)
for root, dirs, files in os.walk('.'):
The text say run the script from here. The ":" at the end of the incomplete for statement block generates errors.
The script on page 198 does not work either.
def print_pdf (arg, dirs, files):
for file in files:
path = os.path.join (root, file)
path = os.path.normcase (path)
if not re.search (r".*\.pdf, path): continue
print (path)
for root, dirs, files in os.walk('.'):
For this script the ":" colon for beginning a for block is the last entry. Also the definition of the function on page 198 has "(arg, dirs, files):" as the argument list, but the for statement at the end is the same as before.
I understand the differences between Windows and Mac OS-X (Unix) file systems, so I have used Unix file designations when trying to work a Unix version. When I submitted these scripts, the editor took out my indentation. Thanks in advance for anyone who can help me here?
Last edited by jimg242; October 29th, 2013 at 04:32 PM..
Reason: clarification about indentation.
|