简体   繁体   中英

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:

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

When run a file in VScode i see the executable path as this:

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

Why does VS code show forward slashes / whereas windows file explorer path is backward slashes \ ?

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

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. Windows uses slash "/" as the parameter mark of DOS command prompt. In order to avoid confusion, it uses "\" as the path separator. So currently, file browsers on Windows systems use "\" as the path separator.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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