Jan-11-2021, 09:45 AM
(This post was last modified: Jan-11-2021, 09:46 AM by Pedroski55.)
I just read the word "table". You want a table? Spreadsheet or html?
Obviously, Larz60+ knows json and you can import the json module and use json.dumps() to convert his dictionary to a string, then write the string to a file.
Like you, I am really just a beginner and only know simple stuff.
Save your data as text with csv format (basically, a comma separates column values) and you can open it in any spreadsheet program.
So, beginner stuff, easy to understand what's happening:
Obviously, Larz60+ knows json and you can import the json module and use json.dumps() to convert his dictionary to a string, then write the string to a file.
Like you, I am really just a beginner and only know simple stuff.
Save your data as text with csv format (basically, a comma separates column values) and you can open it in any spreadsheet program.
So, beginner stuff, easy to understand what's happening:
path = '/home/pedro/winter2020/20PY/dumpFiles/' item = 'X' goods = [] headers = ('Item', 'Buy', 'Sell') goods.append(headers) while True: print('Enter nothing to quit.') item = input('What goods are we talking about? ') if item == '': break buy_price = input('Enter the purchase price. ') sell_price = input('Enter the sales price. ') tup = (item, buy_price, sell_price) goods.append(tup) output = '' for tup in goods: string = tup[0] + ',' + tup[1] + ',' + tup[2] + '\n' output = output + string savefilename = path + 'prices.csv' # you can open this in any spreadsheet program file = open(savefilename, 'w') file.write(output) file.close()