gpt4 book ai didi

python - 使用mac在python中打开文件

转载 作者:太空宇宙 更新时间:2023-11-04 10:12:28 25 4
gpt4 key购买 nike

我如何用 python 在我的 mac 上打开一个文件?我目前正在做一个项目来校对诅咒词,但我似乎无法打开我想让 python 检查的 word 文档。我已经完成并整理了所有代码,但是我无法打开文件供 python 读取。我也是初学者,所以如果您能向我解释一下,那就太好了。

这是我的代码示例:

def read_text():
quotes = open("/Users/AquaAurelius/Documents/Home/Programming/Houston")
contents_of_file = quotes.read()
#print contents of file
print(contents_of_file)
quotes.close()

read_text()

最佳答案

也许您目前正在打开一个文件夹

quotes = open("/Users/AquaAurelius/Documents/Home/Programming/Houston")

您应该打开文件:

quotes = open("/Users/AquaAurelius/Documents/Home/Programming/Houston/YOUR_FILENAME.txt")

看到最后遗漏的部分了吗?

关于python - 使用mac在python中打开文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37520218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com