我无法使以下代码正常工作:
path = "C:\\Users\\jiversen\\Documents\\Jsons\\"+jsonName+'.json'
with open(path,'w') as outfile:
json.dump(df,outfile)
我得到以下错误:
^{pr2}$我尝试了以下方法:
path = "C:\Users\jiversen\Documents\Jsons\"+jsonName+'.json'
这将产生以下错误:
File "<ipython-input-166-405d2aae6e9c>", line 7
path = "C:\Users\jiversen\Documents\Jsons\"+jsonName+'.json'
^
SyntaxError: EOL while scanning string literal
path = R"C:\Users\jiversen\Documents\Jsons\"+jsonName+'.json'
这会产生毛线错误:
File "<ipython-input-167-ff5d5da61135>", line 7
path = R"C:\Users\jiversen\Documents\Jsons\"+jsonName+'.json'
^
SyntaxError: EOL while scanning string literal
import os
script_dir = os.path.abspath('C:\\Users\\jiversen\\Documents\\jsons\\') # i.e. /path/to/dir/foobar.py
rel_path = 'Jsons\\'+jsonName+'.json'
abs_file_path = os.path.join(script_dir, rel_path)
这会产生毛线错误:
OSError Traceback (most recent call last)
<ipython-input-168-d286c1f58b6a> in <module>()
7 #path = R"C:\Users\jiversen\Documents\Jsons\"+jsonName+'.json'
8
----> 9 with open(path,'w') as outfile:
10 json.dump(df,outfile)
OSError: [Errno 22] Invalid argument: 'C:\\Users\\jiversen\\Documents\\Jsons\\2018.04.06 12:00:00.000.json'
with open(jsonName+'.json','w') as outfile:
json.dump(df,outfile)
这将产生以下错误:
OSError Traceback (most recent call last)
<ipython-input-173-818eaaa66077> in <module>()
6 path = 'C:\\Users\\jiversen\\Documents\\Jsons\\'+jsonName+'.json'
7
----> 8 with open(jsonName+'.json','w') as outfile:
9 json.dump(df,outfile)
OSError: [Errno 22] Invalid argument: '2018.04.06-12:00:00.000.json'
我复制粘贴了路径,并确保它存在(C:\Users\jiversen\Documents\Jsons)
我在jupyter笔记本上工作
OSError Traceback (most recent call last)
<ipython-input-177-f09b6b3b06fe> in <module>()
10 # C:\Users\jiversen\Documents\Jsons\2018.04.06-12:00:00.000.json
11
---> 12 with open(full_path, 'w') as outfile:
13 json.dump(df, outfile)
OSError: [Errno 22] Invalid argument: 'C:\\Users\\jiversen\\Documents\\Jsons\\2018.04.06-12:00:00.000.json'
Windows不允许在文件名中使用冒号(
:
)。在试试看
查看您的错误消息:
您正试图打开一个名为
:
的文件。这不是有效的Windows文件名。在相关问题 更多 >
编程相关推荐