我在哪里存储Python的文本文件

时间:2013-02-20 05:09:04

标签: python file

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

1 个答案:

答案 0 :(得分: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)
相关问题