|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
file error
Can anyone tell me why i keep getting the following syntax errors:
Code:
f = open( r "C:\Python23\test.txt") SyntaxError: invalid syntax >>> f = open( r 'C:Python23\test.txt') SyntaxError: invalid syntax i've saved the text file in python's path and if i don't give open a path, just the name of the file, it opens fine. What is the invalid syntax here?
__________________
"In theory, there is no difference between theory and practice. But, in practice, there is."
|
|
#2
|
|||
|
|||
|
those spaces are invalid syntax, the "r" has to be the character immediately preceding the quotes if you want to use raw strings
also, use file and not open, open is deprecated |
|
#3
|
|||
|
|||
|
Hi maybe this works:
Code:
f = open("C:\Python23\test.txt", "r")
|
|
#4
|
||||
|
||||
|
A combination of the two replies:
Code:
f = file(r"C:\Python23\test.txt", "r") Read access is the default mode so you could leave the comma "r" bit out, but I wouldn't .Grim
__________________
*** Experimental Python Markup CGI V2 *** Last edited by Grim Archon : March 19th, 2004 at 07:33 AM. |
|
#5
|
|||
|
|||
|
Thanks guys. Appreaciate your help.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > file error |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|