I am trying to get my program to print one item from each array to a text file and then once all the first items were written,write the second item of the array on the second line and so on.
The code I have now only prints the info on one line of text.
def write():
outFile=open("Inventory.txt","w")
for i in range(0,len(clothesItem)):
outFile.write(format(clothesItem[i],ITEM_FORMAT)+format(clothesColor[i],COLOR_FORMAT)+format(clothesAmount[i],AMOUNT_FORMAT))
outFile.close()
Change this line:
outFile.write(format(clothesItem[i],ITEM_FORMAT)+format(clothesColor[i],COLOR_FORMAT)+format(clothesAmount[i],AMOUNT_FORMAT))
To the following:
outFile.write(format(clothesItem[i], ITEM_FORMAT) + format(clothesColor[i],COLOR_FORMAT) + format(clothesAmount[i], AMOUNT_FORMAT) + "\n")
^^^^
Note the + "\\n"
added onto the end.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.