gpt4 book ai didi

python - 如何在Python中打印文件中的单词

转载 作者:行者123 更新时间:2023-12-01 00:36:16 25 4
gpt4 key购买 nike

我尝试使用 .strip() 方法给我这条线

f = open("myFile.txt")#this open myfile
for i in range(500): # print 500 character
line = f.readline().strip()
print(line)

我的预期结果是

"faowijfaoijfaoiwjfioawjfafawjfaoiwjfawofjafw" 

最佳答案

你可以做到这一点。

with open("myFile.txt") as f:
chars_100 = f.read(100)
print (chars_100)

关于python - 如何在Python中打印文件中的单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57746320/

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