Re: [Tutor] Syntax Error
> On 06/01/06, Kris Kerwin <[EMAIL PROTECTED]> wrote: > > unix_name = string.replace(new_file_name, ' ', '\ ' > > Well, there seems to be a closing parenthesis missing on this line > :-) Oh. :-) > By the way --- starting with python2.2 (?), most of the functions > in the string module are deprecated in favour of calling methods on > strings themeslves. Huh. That does seem to make the code a lot cleaner. Thanks for all of your help! Kris Kerwin On Thursday 05 January 2006 19:57, John Fouhy wrote: > On 06/01/06, Kris Kerwin <[EMAIL PROTECTED]> wrote: > > unix_name = string.replace(new_file_name, ' ', '\ ' > > Well, there seems to be a closing parenthesis missing on this line > :-) > > By the way --- starting with python2.2 (?), most of the functions > in the string module are deprecated in favour of calling methods on > strings themeslves. > > So, instead of saying: > > new_file_string = string.replace(file_string, ' ', '_SPACE_') > > You would say: > > new_file_string = file_string.replace(' ', '_SPACE_') > > HTH! > > -- > John. > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Syntax Error
Hi all, I'm working on a little script, but every time that I run it, it comes back as a syntax error around line 24. However, I can't find anything wrong with it. I figure that maybe I just need another set of eyes. Please take a look at this code, and let me know if you can find anything wrong with it that would cause a syntax error? Thanks in advance! Kris Kerwin Script - #!/usr/bin/python import commands import string import os os.chdir('/home/kris/Mail/.inbox.directory') file_string = commands.getoutput('tree -afi') new_file_string = string.replace(file_string, ' ', '_SPACE_') file_list = string.split(new_file_string) # Pop of leading '.' directory. file_list.pop(0) # Pop of directory stats. file_list.pop() index = 1 while index < (len(file_list) + 1): file_name = file_list.pop() new_file_name = string.replace(file_name, '_SPACE_', ' ') unix_name = string.replace(new_file_name, ' ', '\ ' file_type = commands.getoutput('file %s' % unix_name) # << Line 24 if file_type == '%s: ASCII mail text, with very long lines' % new_file_name: file_contents = commands.getoutput('cat %s' % unix_name) print file_contents index = index + 1 else: index = index + 1 os.chdir('/home/kris/bin/gmail_export/') dircat Description: application/python pgpV7rqku8bBZ.pgp Description: PGP signature ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor