[Tutor] escape codes and filenames (FALSE ALARM

Mallett, Roger rmallett@rational.com
Sat, 25 Nov 2000 13:35:31 -0800

Steve, Richard,

Appears I have a false alarm.  I prostrate myself and receiving my flogging.

Switching the backslashes for forward slashes DID WORK for me.  What I
failed to notice in the python error message was that I didn't remove the
"\012" from the end of each file name before attempting to open the file.

My greatest apologies.

Thank you very much for the help you did provide, for it was applied to
solve my original problem.

Roger Mallett

-----Original Message-----
From: Mallett, Roger 
Sent: Saturday, November 25, 2000 1:30 PM
To: 'tutor@python.org'
Subject: RE: [Tutor] escape codes and filenames


I get the same results you do.  I am obviously misinterpreting something.

The fragment below is exactly where things are breaking.  Since my last
response, I wrote code to replace backslashes with forward slashes so my
input is slightly different but it breaks in the same way at the same place.

I call the following function with a list of filenames:

def CheckFileForConditionalText(filename):
    print '\tCheckFileForConditionalText entered'   #for testing only
    print '\t\tfilename:  ',filename   #for testing only
    x=open('c:\\trash.txt','r')  #for testing only
    print '\ttrash opened'       #for testing only
    x=open(filename,'r')      #THINGS BREAK HERE, THE FILE DOESN'T OPEN

CheckFileForConditionalText entered
trash opened

If I use similar commands at the interpreter, everything is fine
>>> a='c:/__helpfiles/soda/teamtest/teamtest_variant_class.htm'
>>> x=open(a,'r')
>>> z=x.readlines()
>>> z
['<HTML>\012', '<HEAD>\012', ' <TITLE>TeamTest Variant Class</TITLE>\012',
....... and so on

Why do things appear to work in the interpreter but don't work when executed
from the function?

Roger Mallett

-----Original Message-----
From: Steve Spicklemire [mailto:steve@spvi.com]
Sent: Saturday, November 25, 2000 1:12 PM
To: rmallett@Rational.Com
Cc: tutor@python.org; steve@spvi.com
Subject: Re: [Tutor] escape codes and filenames

Hi Roger,

   Hmm... something is really wierd!

I cooked up the following code:


f = open('foo.txt')

lines = f.readlines()

for line in lines:
    print `line`


I saved the following in foo.txt


When I run my code I get:


Which is exactly what I expect....  what do you get?


>>>>> "RM" == Mallett, Roger <rmallett@rational.com> writes:

    RM> Steve, Richard,

    RM> Steve asked: "How did you get filelist?"