Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我将文本文件存储在计算机上的哪个文件夹位置以供 python 访问?我正在尝试使用命令 fin = open('words.txt') 打开一个名为 word.txt 的文件。
您需要使用文件的完整路径。
with open('/path/to/words.txt', 'r') as handle: print handle.read()
否则,它将使用您的当前目录。
import os # Print your current directory print os.path.abspath(os.curdir)