import random, time, pickle #Imports needed libaries
from random import * #Imports all from random
filename = ("char.txt")
charList = []#Sets blank list
charListstr = ''.join(charList)#Makes new list a string so it can be written to file
def write():
creation()
charw = open(filename, 'w')
charw.write(charListstr)
charw.close()
def read():
charr = open(filename, 'r')
lines = charr.read()
charr.close()
def creation():
charListinput = input("What would you like your charcater to be called?")
charList.append(charListinput)
我想让程序接受charcaters名称,然后将该数据追加到列表中。然后我需要列表写入.txt文件,以便用户可以从外部读取它。但是当函数运行时没有错误,但是read()只是给出了一个空白输出。我对Python很糟糕,所以任何帮助都会有用。写入文件不起作用。当使用函数read()时,它不会输出
'charListstr'总是空的。如果您向该文件写入空字符串,则在读取文件时将返回空字符串。 – Matthias