简体   繁体   English

Windows 中的路径 \ 和 / 与 VS 代码相比

[英]path \ and / in windows compared to VS code

If I browse to a file (such as my python exe path) in file explorer (Windows) and click copy path i get this:如果我在文件资源管理器(Windows)中浏览到一个文件(例如我的 python exe 路径)并单击copy path ,我会得到:

"C:\Users\User_one\Local\envs\lon\python.exe"

When run a file in VScode i see the executable path as this:在 VScode 中运行文件时,我看到的可执行路径如下:

c:/Users/User_one/Local/envs/lon/python.exe

Why does VS code show forward slashes / whereas windows file explorer path is backward slashes \ ?为什么 VS 代码显示正斜杠/而 Windows 文件资源管理器路径是反斜杠\

Which is the correct (or preferred) one to use when referencing a file ?引用文件时哪个是正确(或首选)的?

The correct one is not writing/hardcoding the path, but creating it with the os library正确的不是编写/硬编码路径,而是使用 os 库创建它

import os
file=["C:", "Users", "User_one", "Local", "envs", "lon", "python.exe"]

print(os.path.join(*file))

UNIX uses "/" as the path separator, while web applications are recently used on UNIX systems, so at present, all network addresses use "/" as the separator. UNIX 使用"/"作为路径分隔符,而 Web 应用程序最近在 UNIX 系统上使用,所以目前所有的网络地址都使用"/"作为分隔符。 Windows uses slash "/" as the parameter mark of DOS command prompt. Windows 使用斜线"/"作为 DOS 命令提示符的参数标记。 In order to avoid confusion, it uses "\" as the path separator.为了避免混淆,它使用"\"作为路径分隔符。 So currently, file browsers on Windows systems use "\" as the path separator.所以目前,Windows 系统上的文件浏览器使用"\"作为路径分隔符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM