On Jul 31, 2011, at 1:28, "Richard D. Moores" <rdmoo...@gmail.com> wrote:

> 64-bit Vista
> Python 3.2.1
> 
> I would like to write a function that would take a path such as 
> 'C:\Users\Dick\Desktop\Documents\Notes\College Notes.rtf'
> and return 'C:/Users/Dick/Desktop/Documents/Notes/College Notes.rtf' . I've 
> tried this:
> 
> def test(path):
>    return path.replace('\', '/')
> 
> print(test('C:\Users\Dick\Desktop\Documents\Notes\College Notes.rtf'))
> 
> gets me
> 
> File "c:\P32Working\untitled-5.py", line 2
>    return path.replace('\', '/')
>                                ^
> SyntaxError: EOL while scanning string literal
> Process terminated with an exit code of 1
> 
> Thanks,
> 
> Dick
> 
Hi Dick. EOL means End-of-line. Try using double slashes when specifying a 
path. The back slash  \ by itself may be interpreted as an escape character or 
keyword. For example:
print(test('C:\\Users\\Dick\\Desktop\\Documents\\Notes\\CollegeNotes.rtf'))
Hope that helps,
Alexander
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to