[Tutor] Opening a file in Windows Enviroment

Israel Evans israel@lith.com
Thu, 31 Jan 2002 12:53:14 -0800


You've got a couple of options here.

You can make the string you are passing a "raw" string by prepending the
string with r as follows:::  r'C:\text.txt'
This keeps the string as it is with no magical backspace/escape character
fun.  The one problem can be when you end your string with a \   .  This
will escape the trailing '  .  which can be bad.

You can also just use forward slashes.  Windows also like those, though it
doesn't like to talk about it.

Your problem is actually with the backslashes.  They, coupled with whatever
follows them are parsed as special characters.  \n Is end of line.  \t is
tab.  And so on...






~Israel~

-----Original Message-----
From: Tracy Bost [mailto:tbost@ifarm.com] 
Sent: 31 January 2002 12:41 PM
To: Python Tutor Mailing List
Subject: [Tutor] Opening a file in Windows Enviroment


I'm having a hard time opening a file in windows using the "open" function.
It seems it doesn't like the ":" in the path name.
for example
 filename = 'C:\test.txt'
open(filename,'r+')
 gives me an ugly error everytime :

IOError: [Errno 22] Invalid argument: 'C:\text.txt'


 Please help.
 Thank you

----------------------------------------------------------------------------
--
Visit "The Most Powerful Tool on the Farm" at http://www.ifarm.com
Get the latest on Ag News, Market Reports, FREE email, and much more.



_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor