2024-04-20 05:11:57 发布
网友
如何使用python代码获取当前工作目录之外的文件
我正在使用e:\names\test.py directory
e:\names\test.py directory
dirpath = os.path.dirname(os.path.realpath(__file__)) dirpath prints e:\names
在e:\images
e:\images
如何从文件test.py获取路径e:\images\imh.png 我在test.py中硬编码上述路径,如何在test.py文件中设置相对路径
test.py
e:\images\imh.png
您可以使用:
os.path.split(os.getcwd())[0]以获取父目录。在
os.path.split(os.getcwd())[0]
然后,您可以使用:
a=os.path.split(os.getcwd())[0] os.listdir(a)
用于列出父目录的内容
而且,这是有效的同时:在
您可以使用:
os.path.split(os.getcwd())[0]
以获取父目录。在然后,您可以使用:
用于列出父目录的内容
而且,这是有效的同时:在
^{pr2}$相关问题 更多 >
编程相关推荐