Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 29th, 2013, 04:29 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2013
Location: Texas
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.
  #2 (permalink)  
Old October 30th, 2013, 05:59 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2013
Location: Texas
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.
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off



All times are GMT -4. The time now is 11:00 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.