Crossin的编程教室

标题: Mac桌面上有个记事本,怎么打开呢 [打印本页]

作者: icemaneric    时间: 2019-12-29 09:19
标题: Mac桌面上有个记事本,怎么打开呢
Mac上建了一个data.txt的文件怎么打开>>> import os>>> filepath=os.path.abspath(xiadeMBP:~ liyuqiu$ /Users/liyuqiu/Desktop/data.txt)
SyntaxError: invalid syntax
>>> import os
>>> filepath=os.path.abspath(xiadeMBP:~ liyuqiu$ /Users/liyuqiu/Desktop/data.txt)
SyntaxError: invalid syntax
>>> import os
>>> filepath=os.path.abspath(~ liyuqiu$ /Users/liyuqiu/Desktop/data.txt)
SyntaxError: invalid syntax
>>> import os
>>> filepath=os.path.abspath(xiadeMBP:~liyuqiu$/Users/liyuqiu/Desktop/data.txt)
SyntaxError: invalid syntax
>>> import os
>>> filepath=os.path.abspath(~liyuqiu$/Users/liyuqiu/Desktop/data.txt)
SyntaxError: invalid syntax


作者: icemaneric    时间: 2019-12-29 09:49
>>> import os
>>> filepath=os.path.abspath(Users/liyuqiu/Downloads/data.txt)

Traceback (most recent call last):
  File "<pyshell#24>", line 1, in <module>
    filepath=os.path.abspath(Users/liyuqiu/Downloads/data.txt)
NameError: name 'Users' is not defined
作者: icemaneric    时间: 2019-12-29 20:09
鼓捣一下午终于搞定了, 是文件格式的问题,这个txt是从windows下面copy过来的,文件编码不对,要新建一个存储成Unicode(UTF-8)。




欢迎光临 Crossin的编程教室 (https://bbs.crossincode.com/) Powered by Discuz! X2.5