Python Forum
Python simple store inventory system.
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)
Reply
#2
cato is a string, you have used the wrong variable.
I guess you want to append to food.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#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
Reply
#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'})
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Advice for Inventory System Extra 0 1,280 Feb-18-2022, 09:25 PM
Last Post: Extra
  Difference between os.system("clear") and os.system("cls") chmsrohit 7 16,492 Jan-11-2021, 06:30 PM
Last Post: ykumar34
  How does a set in python store the elements? idknuttin 5 2,700 Jul-10-2020, 10:46 PM
Last Post: Gribouillis
  Communicating Roblox's Inventory API with python? 4TH4RV 1 2,028 Jun-22-2020, 10:30 AM
Last Post: snippsat
Question Difference between Python's os.system and Perl's system command Agile741 13 6,650 Dec-02-2019, 04:41 PM
Last Post: Agile741
  Reading blob data from database by python and store it in .zip format Adityasi 2 6,442 Nov-18-2019, 05:22 PM
Last Post: ibreeden
  How do I install apps from google play store? using python + selenium.. mongo 0 2,243 Aug-05-2019, 12:41 AM
Last Post: mongo
  Store a product/item in a inventory program viktoria_linn 1 4,024 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 3,008 Jun-20-2019, 07:54 AM
Last Post: buran
  What area unit the opposite ways in which to understand if an inventory in Python is Smhbugra 2 2,429 May-27-2019, 07:55 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020