Python中文
首页
教程
问答
标签
搜索
登录
注册
with open()错误22(windows路径)
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我无法使以下代码正常工作:</p> <pre><code>path = "C:\\Users\\jiversen\\Documents\\Jsons\\"+jsonName+'.json' with open(path,'w') as outfile: json.dump(df,outfile) </code></pre> <p>我得到以下错误:</p> ^{pr2}$ <p>我尝试了以下方法:</p> <h2>1</h2> <pre><code>path = "C:\Users\jiversen\Documents\Jsons\"+jsonName+'.json' </code></pre> <p>这将产生以下错误:</p> <pre><code>File "<ipython-input-166-405d2aae6e9c>", line 7 path = "C:\Users\jiversen\Documents\Jsons\"+jsonName+'.json' ^ SyntaxError: EOL while scanning string literal </code></pre> <h2>二</h2> <pre><code>path = R"C:\Users\jiversen\Documents\Jsons\"+jsonName+'.json' </code></pre> <p>这会产生毛线错误:</p> <pre><code>File "<ipython-input-167-ff5d5da61135>", line 7 path = R"C:\Users\jiversen\Documents\Jsons\"+jsonName+'.json' ^ SyntaxError: EOL while scanning string literal </code></pre> <h2>三</h2> <pre><code> 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) </code></pre> <p>这会产生毛线错误:</p> <pre><code>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' </code></pre> <h2>4没有细分市场和空间</h2> <pre><code>with open(jsonName+'.json','w') as outfile: json.dump(df,outfile) </code></pre> <p>这将产生以下错误:</p> <pre><code>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' </code></pre> <h2>传统信息</h2> <p>我复制粘贴了路径,并确保它存在(C:\Users\jiversen\Documents\Jsons)</p> <p>我在jupyter笔记本上工作</p> <h2>深空响应</h2> <pre><code>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' </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>查看您的错误消息:</p> <pre><code>OSError: [Errno 22] Invalid argument: 'C:\\Users\\jiversen\\Documents\\Jsons\\2018.04.06-12:00:00.000.json' </code></pre> <p>您正试图打开一个名为<code>:</code>的文件。这不是有效的Windows文件名。在</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
Django:。是不是“超级用户”字段不起作用
2 回答
Django:'DeleteQuery'对象没有属性'add'
6 回答
Django:'ModelForm'对象没有属性
2 回答
Django:'python manage.py runserver'返回'TypeError:'WindowsPath'类型的对象没有len()
3 回答
Django:'Python管理.pysyncdb'不创建我的架构表
6 回答
Django:'Python管理.py迁移“耗时数小时(和其他奇怪的行为)
3 回答
Django:'readonly'属性在我的ModelForm上不起作用
9 回答
Django:'RegisterEmployeeView'对象没有属性'object'
4 回答
Django:'str'对象没有属性'get'
5 回答
Django:'创建' 不能被指定为Order模型表单中的值,因为它是一个不可编辑的字段
4 回答
Django:“'QuerySet'类型的对象不是JSON可序列化的”
5 回答
Django:“'utf8'编解码器无法解码位置19983中的字节0xe9:无效的连续字节”,加载临时文件时
6 回答
Django:“<…>”需要有一个字段“id”的值,然后才能使用这个manytomy关系
4 回答
Django:“AnonymousUser”对象没有“get_full_name”属性
4 回答
Django:“ascii”编解码器无法解码位置1035中的字节0xc3:序号不在范围内(128)
9 回答
Django:“BaseTable”对象不支持索引
7 回答
Django:“collections.OrderedDict”对象不可调用
10 回答
Django:“Country”对象没有属性“all”
8 回答
Django:“Data”对象没有属性“save”
8 回答
Django:“datetime”类型的对象不是JSON serializab
7 回答