与 Windows 上的 Spyder 相比,为什么 Ubuntu 上的 Spyder 使用“//”而不是“\\”?
Why does "//" instead of "\\" for Spyder on Ubuntu compared to Spyder on Windows?
我写了一个python脚本,我需要在其中读写一个文件。我首先在 Windows 上写了它,然后当我尝试在 Ubuntu(Linux) 上执行相同的代码时,使用相同的 Python Shell (Spyder ), 我收到此消息错误 "No such file or directory:"data.csv”。我尝试了很多次来解决这个问题,最后,我发现我需要将里面的所有 '\' 更改为 '//'我的代码。所以,现在一切正常,但是为什么!?
因为Windows使用反斜杠作为目录分隔符,而POSIX系统(包括Linux)使用正向斜杠。见 os.sep
constant:
The character used by the operating system to separate pathname components. This is '/'
for POSIX and '\'
for Windows.
始终使用os.path
模块构建路径;它将处理平台差异。
我写了一个python脚本,我需要在其中读写一个文件。我首先在 Windows 上写了它,然后当我尝试在 Ubuntu(Linux) 上执行相同的代码时,使用相同的 Python Shell (Spyder ), 我收到此消息错误 "No such file or directory:"data.csv”。我尝试了很多次来解决这个问题,最后,我发现我需要将里面的所有 '\' 更改为 '//'我的代码。所以,现在一切正常,但是为什么!?
因为Windows使用反斜杠作为目录分隔符,而POSIX系统(包括Linux)使用正向斜杠。见 os.sep
constant:
The character used by the operating system to separate pathname components. This is
'/'
for POSIX and'\'
for Windows.
始终使用os.path
模块构建路径;它将处理平台差异。