[Tutor] escape codes and filenames

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

Steve, Richard,

Steve asked: "How did you get filelist?"

My code is below.  The file being read by the code below is a text file
loaded with fully qualified filenames obtained from a DOS dir /s/b command.
I use readlines() to put each line in the text file into a list and then
return the list.


def ReadLinesFromFileIntoList(filename):
    return lines

SAMPLE ENTRIES from the text file are in the following format:

I don't understand how raw_input is applied in the situation I am trying
above.  I would like to know more about it.

Using Richard's suggestion of "/" rather than "\" sounds interesting.
However, I still have to process each element in the list before opening any
of the files to ensure that it is scrubbed of escape codes.

Roger Mallett

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

Hi Roger,

How did you get filelist? If you type a string into the
interpreter and you want an explicit '\' you need to escape it

filename = "c:\\trash.txt"

If you read a string from a file or keyboard, no escape is required

try the following code:

x = raw_input('enter a string with a "\\" in it... ')
print `x`

does that work for you?

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

    Mallett,> I have a series of files that need to be opened.
    Mallett,> Several of the files start with characters normally
    Mallett,> reserved as Escape codes.

    Mallett,> Using for filename in filelist: x=open(filename,'r')

    Mallett,> fails anytime anypart of *filename* contains a
    Mallett,> "\<escape_code>" sequence.  For example: if filename is
    Mallett,> set to "c:\trash.txt", then the file will not open with
    Mallett,> the open command above because the "\t" is perceived as
    Mallett,> an escape code.

    Mallett,> I have therefore written code to scrub each instance of
    Mallett,> filename to ensure no escape sequences exist before the
    Mallett,> open command is executed.

    Mallett,> Is there another way to handle this?  I found
    Mallett,> information about *raw* commands in the python
    Mallett,> documentation but couldn't figure out how to work it.

    Mallett,> Any ideas of how this type of situation should be
    Mallett,> handled?

    Mallett,> Thank you for your help,

    Mallett,> Roger Mallett

    Mallett,> _______________________________________________ Tutor
    Mallett,> maillist - Tutor@python.org
    Mallett,> http://www.python.org/mailman/listinfo/tutor