Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Python simple store inventory system.
#1
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.

Error:
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.append(item)
print(food)
Quote
#2
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: https://sourceserver.info
All humans together. We don't need politicians!
Quote
#3
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 - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#4
(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'})
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How do I install apps from google play store? using python + selenium.. mongo 0 150 Aug-05-2019, 12:41 AM
Last Post: mongo
  Store a product/item in a inventory program viktoria_linn 1 214 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 454 Jun-20-2019, 07:54 AM
Last Post: buran
  Difference between os.system("clear") and os.system("cls") chmsrohit 6 694 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 289 May-27-2019, 07:55 PM
Last Post: Larz60+
  Receive Serial Data and store in different Variables in Python jenkins43 5 789 Dec-28-2018, 01:33 PM
Last Post: snippsat
  Easy equipment system for simple game and problems with it naisyrk 3 573 Sep-01-2018, 10:05 AM
Last Post: Gribouillis
  Python inventory system with dicts. 2skywalkers 7 643 Aug-23-2018, 05:06 PM
Last Post: ichabod801
  Recommended way to store users,db credentials in a Python project? PrateekG 2 744 May-31-2018, 12:22 PM
Last Post: DeaD_EyE
  search and store a value from linux command output in to variable python prazy29 1 744 Apr-06-2018, 01:56 PM
Last Post: wavic

Forum Jump:


Users browsing this thread: 1 Guest(s)