Home > Software engineering >  Making a simple easy to update list.py file, saving from python shell or appending actual .py file
Making a simple easy to update list.py file, saving from python shell or appending actual .py file

Time:02-10

I am brand new to learning python and want to not only output an updated list from input() but also save that to the file for future storage, this is what I have so far:

things_to_buy = ["plants for house", "new running shoes", "fishing gear", "Nighthawks portrait", "workout earbuds"]

print(things_to_buy, "\n\n")

new_item = input("Add or edit inventory, Captain: \n")

things_to_buy.append(new_item)

print("\n", things_to_buy)

I can get the input added to the list but of course I'm only printing.

How can I append to the actual .py file as have it stored for next time I run it?

Tried getting some help and all I got was vague notions about storing it in a .json which seems bizarre(though json can accept python objects)

Running linux, am comfortable with bash but still quite new to python!

CodePudding user response:

  •  Tags:  
  • Related