使用python代码如何获取当前工作目录之外的文件
正在使用e:\names\test.py directory
dirpath = os.path.dirname(os.path.realpath(__file__))
dirpath prints e:\names
e:\images
中的
如何从文件e:\images\imh.png
获取路径test.py
我在test.py
中对上述路径进行了硬编码,如何在test.py
文件中设置相对路径
答案 0 :(得分:1)
您可以使用:
os.path.split(os.getcwd())[0]
获取父目录。
然后,您可以使用:
a=os.path.split(os.getcwd())[0]
os.listdir(a)
列出父目录的内容
此外,这也适用: -
os.listdir(os.pardir)
答案 1 :(得分:1)
When on, ":autocmd", shell and write commands are not allowed in
".vimrc" and ".exrc" in the current directory and map commands are
displayed. Switch it off only if you know that you will not run into
problems, or when the 'exrc' option is off. On Unix this option is
only used if the ".vimrc" or ".exrc" is not owned by you. This can be
dangerous if the systems allows users to do a "chown". You better set
'secure' at the end of your ~/.vimrc then.
This option cannot be set from a |modeline| or in the |sandbox|, for
security reasons.