Python:将代码从 Repl.it 复制到 Visual Studio 不正确 运行:参数无效错误

Python: copied code from Repl.it to Visual Studio does not run correctly: Invallid arguments error

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

但现在考虑到我正朝着 Visual Studio 的方向发展(对于工具箱和其他问题à,我已经复制了代码,我得到了一个对我来说无效的参数代码,这没有任何意义。

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 studio19\enterprise\common7\ide\extensions\microsoft\python\core\debugpy\__main__.py", line 45, in <module>
    cli.main()
  File "c:\program files (x86)\microsoft visual studio19\enterprise\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 430, in main
    run()
  File "c:\program files (x86)\microsoft visual studio19\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

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