-2

我将文本文件存储在计算机上的哪个文件夹位置以供 python 访问?我正在尝试使用命令 fin = open('words.txt') 打开一个名为 word.txt 的文件。

4

1 回答 1

1

您需要使用文件的完整路径。

with open('/path/to/words.txt', 'r') as handle:
    print handle.read()

否则,它将使用您的当前目录。

import os
# Print your current directory
print os.path.abspath(os.curdir)
于 2013-02-20T05:14:47.970 回答