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