[Tutor] escape codes and filenames

Steve Spicklemire steve@spvi.com
Sat, 25 Nov 2000 15:02:19 -0500 (EST)

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