Wrox Programmer Forums
|
BOOK: Beginning Python: Using Python 2.6 and Python 3.1
This is the forum to discuss the Wrox book Beginning Python: Using Python 2.6 and Python 3.1 by James Payne; ISBN: 978-0-470-41463-7
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Python: Using Python 2.6 and Python 3.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 29th, 2013, 04:29 PM
Registered User
 
Join Date: Aug 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Angry 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.
 
Old October 30th, 2013, 05:59 PM
Registered User
 
Join Date: Aug 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Red face Update!

It finally dawned on me that after defining a function, it must be called before it can execute, so the missing function call was added. Maybe I don't quite understand the OS-X file structure as well as I thought. This program still will not run on the Mac/Unix, but it DOES run as expected on Windows 7. Still need help with running it on the Mac under Mavericks. Thanks in advance for any insight you may be able to provide me.









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.