Python:从Repl.it复制到Visual Studio的代码未正确运行:Invalid arguments错误

2024-06-25 05:35:10 发布

您现在位置:Python中文网/ 问答频道 /正文

您好,目前我正在Repl.it上开发一些python脚本,以便设备共享

但是现在考虑到我正在转向VisualStudio(对于工具箱和其他事项),并且我已经复制了代码,我得到了一个无效的参数代码,这对我来说没有任何意义

Loaded '__main__'
Loaded 'runpy'
Traceback (most recent call last):
  File "C:\Users\joeri\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\joeri\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\program files (x86)\microsoft visual studio\2019\enterprise\common7\ide\extensions\microsoft\python\core\debugpy\__main__.py", line 45, in <module>
    cli.main()
  File "c:\program files (x86)\microsoft visual studio\2019\enterprise\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 430, in main
    run()
  File "c:\program files (x86)\microsoft visual studio\2019\enterprise\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 267, in run_file
    runpy.run_path(options.target, run_name=compat.force_str("__main__"))
  File "C:\Users\joeri\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "C:\Users\joeri\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\Users\joeri\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\Programmeer portfolio\Programma's\Python Scripts\PythonApplicationGIPODAPITest\PythonApplicationGIPODAPITest.py", line 167, in <module>
The thread 'MainThread' (0x1) has exited with code 0 (0x0).
    fetch_points(api_response_url)
  File "D:\Programmeer portfolio\Programma's\Python Scripts\PythonApplicationGIPODAPITest\PythonApplicationGIPODAPITest.py", line 107, in fetch_points
    save_jsonfile(folder_path, "points", text)
  File "D:\Programmeer portfolio\Programma's\Python Scripts\PythonApplicationGIPODAPITest\PythonApplicationGIPODAPITest.py", line 156, in save_jsonfile
    file1 = open(completeName, "wt")
OSError: [Errno 22] Invalid argument: 'api_request_jsons\x0cetch_points\\points.json'
The program 'python.exe' has exited with code 1 (0x1).

如果代码可以在repl.it上运行,并且我有相同的文件和文件夹结构..那么为什么在Visual Studio中不工作呢?当然,repl.it有python 3.8,Visual Studio有python 3.7..但这不可能是正确的吗

已编辑:出于隐私原因删除代码

enter image description here


Tags: runnameinpymainlocallinecode
1条回答
网友
1楼 · 发布于 2024-06-25 05:35:10

您已经从repl.it上基于linux的文件结构(使用正斜杠/来描绘文件夹,如api_request_jsons/fetch_points)移动到本地计算机(运行Windows)上基于Windows的文件结构(使用反斜杠\来描绘文件夹)。因此api_request_jsons/fetch_points需要转换为api_request_jsons\fetch_points。最好的方法是对每个嵌套文件夹使用os.path.join作为参数(即用os.path.join("api_request_jsons", "fetch_points")替换api_request_jsons\fetch_points),以允许代码在*nix和Windows文件系统之间传输

相关问题 更多 >