TXT files stepped python open pit

Learn pit file operations:

1, the file name is incorrect, as f.txt, written f.txt.txt

2, when use Notepad to edit, save for the encoding format may be selected

3, the pit is the largest file path, open f.txt, the path win7 environment first attribute is: C: \ Users \ Administrator \ Documents \ f.txt, but has been run python error:

  

File "<IPython-INPUT-47-7eb47648a352>" , Line . 1  TF = Open ( "C: \ the Users \ Administrator \ Documents \ f.txt", "R & lt", encoding = "UTF-. 8") ^ SyntaxError : ( unicode error) 'unicodeescape' codec can not decode bytes in position 2-3: truncated \ UXXXXXXXX escape 

thought it was a coding error, one by one changed the encoding ANSI, unicode, GB2312, utf- 8 will not

the ultimate solution: the path to dual \\ run correctly! ! ! ! ! !

tf=open("C:\\Users\\Administrator\\Documents\\f.txt","r",encoding="UTF-8")
print(tf.readline())
tf.close()

 

 



Guess you like

Origin www.cnblogs.com/CSUT-Ryan/p/11371530.html
Recommended