On Sun, Feb 21, 2010 at 12:22 PM, Sithembewena Lloyd Dube <zebr...@gmail.com
> wrote:

> Hi all,
>
> I'm trying to read a file (Python 2.5.2, Windows XP) as follows:
>
> assignment_file = open('C:\Documents and Settings\coderoid\My
> Documents\Downloads\code_sample.txt', 'r+').readlines()
> new_file = open(new_file.txt, 'w+')
> for line in assignment_file:
>     new_file.write(line)
>
> new_file.close()
> assignment_file.close()
>
> When the code runs, the file path has the slashes converted to double
> slashes. When  try to escape them, i just seemto add more slashes. What am i
> missing?


try using the r to declare it as a raw string:
>>> filename = r'C:\Documents and Settings\coderoid\otherstuff'
>>> filename
'C:\\Documents and Settings\\coderoid\\otherstuff'

that should work.

HTH,
Wayne


-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to