是否可以创建一个变量来存储产品列表,而不是使用“行”变量。当创建一个文本文件在Python中创建文本文件
#creating a textfile
text_file= open("productlist.txt", "w")
lines = ("Bed","\n","Couch","\n","Mirror","\n","Television","\n"
"Tables","\n","Radio")
text_file.writelines(lines)
text_file.close()
text_file = open("productlist.txt")
print(text_file.read())
text_file.close()
你的意思是'lines = text_file.readlines()'也许? –
@ Jean-FrançoisFabre不,我想知道是否可以在创建此列表时使用其他变量 lines =(“Bed”,“\ n”,“Couch”,“\ n”,“Mirror”, “\ n”,“电视”,“\ n”“表格”,“\ n”,“收音机”) – Charisma
我真的不知道你的意思。您可以根据需要创建尽可能多的变量。 –