gpt4 book ai didi

python - file.read 返回空列表

转载 作者:太空宇宙 更新时间:2023-11-03 21:29:01 25 4
gpt4 key购买 nike

file1.seek(0)
exec(i + ".seek(0)")
readd = exec(i + ".readlines()")
print(file1.readlines())

我已经将文件打开为“r+”文件包含内容,但代码返回以下内容:

[]
None

我确实找到了开头,但它仍然没有返回内容任何帮助表示赞赏!

这是完整的代码:

dictt = {'a':'z','b':'x','c':'c','d':'v','e':'b',
'f':'n','g':'m','h':'a',
'i':'s','j':'d','k':'f','l':'g','m':'h',
'n':'j','o':'k','p':'l','q':'ñ',
'r':'q','s':'w','t':'e','u':'r','v':'t',
'w':'y','x':'u','y':'i','z':'o', "ñ" : "p",
" " : "m", "\\" : "m"
}


inv_map = {v: k for k, v in dictt.items()}

def read():
file1 = open("memory1.txt", "r+")
i = input("file: ")
o = input("Note: ")
exec(i + ".seek(0)")
readd = exec(i + ".readlines()")
readd = file1.readlines()
readd = str(readd)
lent = len(readd)
final = ""
for i in range(lent - 4):
final += inv_map[str(readd[i + 2])]
print(final)
print("Note: " + o)
file1.close()

def write():
file1 = open("memory1.txt", "r+")
n = input("to file: ")
m = str(input("Go: "))
print(n)
lent = len(m)
for i in range(lent):
exec(n + ".write(dictt[m[i]])")
print(dictt[m[i]])
print("Wrote: ", m)
file1.close()

while (cont == True):
y = input()
print(".")
final = y + "(" + ")"
exec(final)

写入功能工作正常

最佳答案

您已经使用读取该文件

readd = exec(i + ".readlines()")

这会将文件的内容返回到 readd 变量。下一行,

打印(file1.readlines())

将再次调用 readlines,这将返回一个空列表。

关于python - file.read 返回空列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53648452/

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