I an running this code:
#!/usr/bin/python coding=utf8
# test.py = to demo fault
def loadFile(path):
f = open(path,'r')
text = f.read()
return text
if __name__ == '__main__':
path = 'D:workKindlesrcsest1.html'
document = loadFile(path)
print len(document)
It gives me a trackback
D:workKindleTests>python.exe test.py
Traceback (most recent call last):
File "test.py", line 11, in <module>
document = loadFile(path)
File "test.py", line 5, in loadFile
f = open(path,'r')
IOError: [Errno 22] invalid mode ('r') or filename: 'D:\work\Kindle\srcsest1.html'
D:workKindleTests>
If I change the path line to
path = 'D:workKindlesrcs\test1.html'
(note the double \) it all works fine.
Why? Either the separator is '' or it is not, not a mix?
System. Windows 7, 64bit,
Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win32
Checked - and all the backslashes appear correctly.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…