0

我对这个命令有疑问,任何人都可以向我描述它!

PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))

我想用来引用特定的文件

PROJECT_PATH = os.path.abspath(os.path.dirname('C://Python27//the dataset//h messages' + '/ham'

'C://Python27//the dataset//s messages ' + '/spam'))

不知道能不能这样用?什么是正确的方法,谢谢

4

1 回答 1

0
The __file__ variable contains the path to the current module. The Python documentation can explain the function of os.path.abspath() and os.path.dirname().

顺便说一句,您不需要在字符串中转义正斜杠,这里的连接完全没有意义。引用路径的正确方法是:

PROJECT_PATH = os.path.abspath(os.path.dirname('C:\\Python27\\the dataset\\h messages\\ham'))

或者:

PROJECT_PATH = os.path.abspath(os.path.dirname('C:/Python27/the dataset/h messages/ham'))

对垃圾邮件路径使用相同的想法。

于 2013-04-22T22:07:41.947 回答