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 に答える