How to call a file

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sun May 11 00:16:46 EDT 2008


En Sat, 10 May 2008 12:32:47 -0300, Gary Herron <gherron at islandtraining.com> escribió:

> Chris Sprinkles wrote:
>> I'm still having trouble with calling a text file and I know its so
>> simple here is the code
>> ----------------------------------------------------
>> work = open('C:\Documents and Settings\Administrator\My
>> Documents\Chris\Python\Python\work.txt', 'r')

Also, remember that \ is the escape character for strings in Python. In this particular case it doesn't matter just because you didn't hit any valid escape, but in general, use:
"C:\\Documents and Settings\\Adm..."
r"C:\Documents and Settings\Adm..."
In most cases, Windows recognizes forward slashes also: "C:/Documents and Settings/Adm..."

-- 
Gabriel Genellina




More information about the Python-list mailing list