[英]BASE_DIR outputs correct using print, but in a variable it just outputs C:
If im using print on base_dir = settings.BASE_DIR
it outputs everything correctly. 如果我在
base_dir = settings.BASE_DIR
上使用print, base_dir = settings.BASE_DIR
正确输出所有内容。 However when I use this variable to create a new variable using os.path.join
, it just outputs C:
但是,当我使用此变量使用
os.path.join
创建新变量时,它仅输出C:
Print example: C:\\Users\\me\\Google Drive\\gitlab\\rootfolder
打印示例:
C:\\Users\\me\\Google Drive\\gitlab\\rootfolder
Example on code where it just outputs C:
and the paths after which shows up correct. 仅输出
C:
代码示例,其后的路径显示正确。
blendfile = os.path.join(base_dir, '/var/media', userpathname, newest).replace("\\\\", "/")
Comes out as: C:/var/media/userpathname/newest
出来为:
C:/var/media/userpathname/newest
Change '/var/media'
to var/media'
in join
function, that is remove the preceeding slash from the second parameter. 更改
'/var/media'
以var/media'
中join
的功能,也就是从第二个参数中删除前述斜线 。 hence the code should be, 因此代码应该是
blendfile = os.path.join(base_dir,
'var/media', userpathname, newest).replace("\\", "/")
EXAMPLE 例
In [16]: import os
In [17]: BASE = "Users\me\Google Drive\gitlab\rootfolder"
In [18]: append_path__1 = "/var/media" # with preceeding slash
In [19]: append_path__2 = "var/media" # without preceeding slash
In [20]: os.path.join(BASE,append_path__1)
Out[20]: '/var/media'
In [21]: os.path.join(BASE,append_path__2)
Out[21]: 'Users\\me\\Google Drive\\gitlab\rootfolder/var/media'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.