Python with open()错误22(windows路径)

Python with open()错误22(windows路径),python,python-3.x,jupyter-notebook,Python,Python 3.x,Jupyter Notebook,我无法使以下代码正常工作: path = "C:\\Users\\jiversen\\Documents\\Jsons\\"+jsonName+'.json' with open(path,'w') as outfile: json.dump(df,outfile) 我得到以下错误: OSError Traceback (most recent call last) <ipython-input-162

我无法使以下代码正常工作:

path = "C:\\Users\\jiversen\\Documents\\Jsons\\"+jsonName+'.json'

with open(path,'w') as outfile:
        json.dump(df,outfile)
我得到以下错误:

OSError                                   Traceback (most recent call last)
<ipython-input-162-ad4856eeb7ee> in <module>()
      7 #path = r "C:\Users\jiversen\Documents\CosmosDB Simulator\Jsons\"+jsonName+'.json'
      8 
----> 9 with open(abs_file_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'
File "<ipython-input-166-405d2aae6e9c>", line 7
    path = "C:\Users\jiversen\Documents\Jsons\"+jsonName+'.json'
                                                                ^
SyntaxError: EOL while scanning string literal
File "<ipython-input-167-ff5d5da61135>", line 7
    path = R"C:\Users\jiversen\Documents\Jsons\"+jsonName+'.json'
                                                                 ^
SyntaxError: EOL while scanning string literal
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'
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'
这会产生以下错误:

OSError                                   Traceback (most recent call last)
<ipython-input-162-ad4856eeb7ee> in <module>()
      7 #path = r "C:\Users\jiversen\Documents\CosmosDB Simulator\Jsons\"+jsonName+'.json'
      8 
----> 9 with open(abs_file_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'
File "<ipython-input-166-405d2aae6e9c>", line 7
    path = "C:\Users\jiversen\Documents\Jsons\"+jsonName+'.json'
                                                                ^
SyntaxError: EOL while scanning string literal
File "<ipython-input-167-ff5d5da61135>", line 7
    path = R"C:\Users\jiversen\Documents\Jsons\"+jsonName+'.json'
                                                                 ^
SyntaxError: EOL while scanning string literal
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'
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'
这将产生触发错误:

OSError                                   Traceback (most recent call last)
<ipython-input-162-ad4856eeb7ee> in <module>()
      7 #path = r "C:\Users\jiversen\Documents\CosmosDB Simulator\Jsons\"+jsonName+'.json'
      8 
----> 9 with open(abs_file_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'
File "<ipython-input-166-405d2aae6e9c>", line 7
    path = "C:\Users\jiversen\Documents\Jsons\"+jsonName+'.json'
                                                                ^
SyntaxError: EOL while scanning string literal
File "<ipython-input-167-ff5d5da61135>", line 7
    path = R"C:\Users\jiversen\Documents\Jsons\"+jsonName+'.json'
                                                                 ^
SyntaxError: EOL while scanning string literal
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'
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'
这将产生触发错误:

OSError                                   Traceback (most recent call last)
<ipython-input-162-ad4856eeb7ee> in <module>()
      7 #path = r "C:\Users\jiversen\Documents\CosmosDB Simulator\Jsons\"+jsonName+'.json'
      8 
----> 9 with open(abs_file_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'
File "<ipython-input-166-405d2aae6e9c>", line 7
    path = "C:\Users\jiversen\Documents\Jsons\"+jsonName+'.json'
                                                                ^
SyntaxError: EOL while scanning string literal
File "<ipython-input-167-ff5d5da61135>", line 7
    path = R"C:\Users\jiversen\Documents\Jsons\"+jsonName+'.json'
                                                                 ^
SyntaxError: EOL while scanning string literal
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'
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'
这会产生以下错误:

OSError                                   Traceback (most recent call last)
<ipython-input-162-ad4856eeb7ee> in <module>()
      7 #path = r "C:\Users\jiversen\Documents\CosmosDB Simulator\Jsons\"+jsonName+'.json'
      8 
----> 9 with open(abs_file_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'
File "<ipython-input-166-405d2aae6e9c>", line 7
    path = "C:\Users\jiversen\Documents\Jsons\"+jsonName+'.json'
                                                                ^
SyntaxError: EOL while scanning string literal
File "<ipython-input-167-ff5d5da61135>", line 7
    path = R"C:\Users\jiversen\Documents\Jsons\"+jsonName+'.json'
                                                                 ^
SyntaxError: EOL while scanning string literal
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'
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'
OSError回溯(最近一次调用)
在()
6 path='C:\\Users\\jiversen\\Documents\\Jsons\\'+jsonName+'.json'
7.
---->8将open(jsonName+'.json',w')作为输出文件:
9.json.dump(df,outfile)
OSError:[Errno 22]无效参数:“2018.04.06-12:00:00.000.json”
传统信息 我已经复制粘贴了路径,并确保它存在(C:\Users\jiversen\Documents\Jsons)

我在jupyter笔记本电脑公司工作

对深空的反应
OSError回溯(最近一次调用)
在()
10#C:\Users\jiversen\Documents\Jsons\2018.04.06-12:00:00.000.json
11
--->12开放式(全路径,'w')作为输出文件:
13.json.dump(df,outfile)
OSError:[Errno 22]无效参数:“C:\\Users\\jiversen\\Documents\\Jsons\\2018.04.06-12:00:00.000.json”

Windows不允许在文件名中使用冒号(

试一试


查看您的错误消息:

OSError: [Errno 22] Invalid argument: 
'C:\\Users\\jiversen\\Documents\\Jsons\\2018.04.06-12:00:00.000.json'

您正试图打开一个名为
的文件。这不是有效的Windows文件名。

谢谢!就这样!