1

I get an error on the [(] bracket opening the file. Please help :)

usedbeforefile = open&&(&&'c:\\Documents and Settings\Adam\Desktop\NewProgram\Resources\Alfred\ub4.txt')

EDIT: Thank you, Ashwini Chaudhary

(If you see the '&&' around the bracket that is just me showing where my error was :D)

4

2 回答 2

1

尝试这个:

usedbeforefile = open(r'c:\Documents and Settings\Adam\Desktop\NewProgram\Resources\Alfred\ub4.txt')

注意r字符串开头的前面。这就是说:这是一个原始字符串,不需要解释\为特殊的转义字符。另一种选择是使用普通字符串并手动转义所有\字符:

usedbeforefile = open('c:\\Documents and Settings\\Adam\\Desktop\\NewProgram\\Resources\\Alfred\\ub4.txt')
于 2013-08-20T20:41:22.983 回答
0

您还可以在 Unix 和 Windows 上使用正斜杠,因为 Python 尝试可移植地解释路径。

usedbeforefile = open('c:/Documents and Settings/Adam/Desktop/NewProgram/Resources/Alfred/ub4.txt')    
于 2013-08-20T22:01:04.670 回答