Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Python simple store inventory system.
What I am trying to do is make a SIMPLE python inventory system but I am having trouble. Just so you know its not done yet. In the "if" statement part I want the user to choose which list to add a item to, but I don't want to do a "if" statement for each list, so I'm trying to find a way to where it just adds to the list that you type in to make it easier but I get a error message. I get a error though.

Line 14: AttributeError: 'str' object has no attribute 'append'
print("Welcome to Inventory Managment, type 'help' if you need help"

food = []
tools = []
electronics = []
books = []
furniture = []

command = input("What would you like to do?: ")
if command == "add":
	cato = input("Where would you like to add?: ")
	item = input("What item would you like to add?: ")
cato is a string, you have used the wrong variable.
I guess you want to append to food.
My code examples are always for Python >=3.6.0
Almost dead, but too lazy to die:
All humans together. We don't need politicians!
The way to do it is with a dictionary: inventory = {'food': [], 'tools': [], ...}. By using strings for the keys, this allows you to use the user's input as a key: inventory[cato].append(item).

You may want to look at the collections module, specifically defaultdict. It provides an easy way to do this.
Craig "Ichabod" O'Brien -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

(Aug-19-2018, 04:51 PM)2skywalkers Wrote: What I am trying to do is make a SIMPLE python inventory system
You will soon need to store persistent data on disk. I suggest using module tinydb for this. You can write simple things such as
db.insert({'item': 'Wuthering Heights', 'shelf': 'books'})

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
Question Difference between Python's os.system and Perl's system command Agile741 13 795 Dec-02-2019, 04:41 PM
Last Post: Agile741
  Reading blob data from database by python and store it in .zip format Adityasi 2 526 Nov-18-2019, 05:22 PM
Last Post: ibreeden
  How do I install apps from google play store? using python + selenium.. mongo 0 438 Aug-05-2019, 12:41 AM
Last Post: mongo
  Store a product/item in a inventory program viktoria_linn 1 615 Jul-02-2019, 09:26 PM
Last Post: DeaD_EyE
  Store a python list of lists in a database to use for searches later on klllmmm 3 666 Jun-20-2019, 07:54 AM
Last Post: buran
  Difference between os.system("clear") and os.system("cls") chmsrohit 6 2,716 Jun-16-2019, 11:38 AM
Last Post: DeaD_EyE
  What area unit the opposite ways in which to understand if an inventory in Python is Smhbugra 2 475 May-27-2019, 07:55 PM
Last Post: Larz60+
  Receive Serial Data and store in different Variables in Python jenkins43 5 1,284 Dec-28-2018, 01:33 PM
Last Post: snippsat
  Easy equipment system for simple game and problems with it naisyrk 3 772 Sep-01-2018, 10:05 AM
Last Post: Gribouillis
  Python inventory system with dicts. 2skywalkers 7 951 Aug-23-2018, 05:06 PM
Last Post: ichabod801

Forum Jump:

Users browsing this thread: 1 Guest(s)