与平台无关的文件路径? [英] Platform-independent file paths?
本文介绍了与平台无关的文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Python的app文件夹中使用文件?平台当然是独立的... 类似于以下内容:
How can I use a file inside my app folder in Python? Platform independent of course... something similar to this:
#!/bin/sh
mypath=${0%/*}
LIBDIR=$mypath/modules
推荐答案
您可以使用os.path
及其函数,这些函数负责特定于OS的路径:
You can use os.path
and its functions, which take care of OS-specific paths:
>>> import os
>>> os.path.join('app', 'subdir', 'dir', 'filename.foo')
'app/subdir/dir/filename.foo'
在Windows上,它应该以反斜杠打印出来.
On Windows, it should print out with backslashes.
这篇关于与平台无关的文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文