当前位置:网站首页>os. path. Pits encountered during the use of join()
os. path. Pits encountered during the use of join()
2022-06-24 08:23:00 【go_ flush】
- linux The way to splice paths is a slash /, win Concatenated backslash \
- I am here os.path.join() It was found that If there is a slash or backslash at the beginning of the spliced path The splice path is truncated from the slash or backslash (win In the system ), If it is linux System The slash will be truncated , Backslash does not .
- The code example is as follows :
win System
a_path_win = "http://www.baidu.com"
b_path_win = "data/img"
path_join = os.path.join(a_path_win, b_path_win) # The way to search the path is the backslash \
print(f"sys = {
sys.platform}")
print(f"path_join_win = {
path_join}")
Printed results
sys = win32
path_join_win = http://www.baidu.com\data/img
c_path_win = "/data/img"
path_join_win_1 = os.path.join(a_path_win, c_path_win)
print(f"path_join_win_1 = {path_join_win_1}")
Printed results
path_join_win_1 = /data/img # Truncate at slash
d_path_win = "\data\img"
path_join_win_2 = os.path.join(a_path_win, d_path_win)
print(f"path_join_win_2 = {
path_join_win_2}")
Printed results
path_join_win_2 = \data\img # Truncate at backslash
Linux System
a_path = "http://www.baidu.com"
b_path = "data/img"
path_join = os.path.join(a_path, b_path)
print(f"{
sys.platform}")
print(f"path_join = {
path_join}")
Printed results
linux
path_join = http://www.baidu.com/data/img
c_path = "/data/img"
path_join_1 = os.path.join(a_path, c_path)
print(f"path_join_1= {
path_join_1}")
Printed results
path_join_1= /data/img # Slashes are also truncated
d_path = "\data\img"
path_join_2 = os.path.join(a_path, d_path)
print(f"path_join_2 = {
path_join_2}")
Printed results
path_join_2 = http://www.baidu.com/\data\img # Backslashes do not truncate , They can splice
FAQ
os.path.join stay win The backslash and slash encountered in the system are truncated here , stay linux Slashes encountered under the system will be truncated , Backslash does not , Do you have to remove the slash or backslash at the beginning when splicing paths , Otherwise, the path cannot be found
边栏推荐
- 李白最经典的20首诗排行榜
- Review SGI STL secondary space configurator (internal storage pool) | notes for personal use
- WCF TCP protocol transmission
- Swift Extension ChainLayout(UI的链式布局)(源码)
- Swift 基础 Swift才有的特性
- Simple refraction effect
- pyQt 常用系统的事件
- In the post epidemic era, the home service robot industry has just set sail
- 软件工程导论——第二章——可行性研究
- List of Li Bai's 20 most classic poems
猜你喜欢
随机推荐
How to design a highly available and extended image storage function
2022茶艺师(中级)上岗证题库及在线模拟考试
2022 mobile crane driver special operation certificate examination question bank and online simulation examination
Pagoda panel installation php7.2 installation phalcon3.3.2
Review SGI STL secondary space configurator (internal storage pool) | notes for personal use
权限模型 DAC ACL RBAC ABAC
Online education fades
JS scroll div scroll bar to bottom
Teach you how to use the reflect package to parse the structure of go - step 1: parameter type check
Question bank and simulation examination for operation certificate of refrigeration and air conditioning equipment in 2022
"Adobe international certification" about Adobe Photoshop, creating and modifying brush tutorials?
Interview tutorial - multi thread knowledge sorting
Question 3 - MessageBox pop-up box, modify the default background color
根据网络上的视频的m3u8文件通过ffmpeg进行合成视频
Simple summary of lighting usage
Écouter le réseau d'extension SWIFT (source)
Blue Bridge Cup_ Queen n problem
小样本故障诊断 - 注意力机制代码 - BiGRU代码解析实现
QOpenGL显示点云文件
487. 最大连续1的个数 II ●●








