6 Replies - 2289 Views - Last Post: 16 August 2012 - 06:57 PM Rate Topic: -----

#1 grimofdoom  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 22
  • Joined: 14-August 12

List save/manipulate

Posted 14 August 2012 - 04:54 PM

I am new at python.For my first big project,i am making a program that would keep track of inventory, stuff sold(day to day),add inventory or items to inventory...ect .But right now I am only at the getting the inventory. I have tried importing with append but it would show the inventory items(ignored the "inventory" list variable).I need (if possible)I need a simple script that creates a file(if not found) and adds a list that the user can choose the name(variable name for the "list=[]) and be able to save the file of list/s whenever the list is menipulated. I would only like the create if not there and be able to import the list while save whenever menipulated. I can problabley get the rest by myself. Thanks in advanced.

Is This A Good Question/Topic? 0
  • +

Replies To: List save/manipulate

#2 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7999
  • View blog
  • Posts: 13,701
  • Joined: 19-March 11

Re: List save/manipulate

Posted 14 August 2012 - 05:22 PM

I think you probably need to back up a little. You need to define what you're trying to do.

What is it that you're keeping an inventory of? What do you need to know about those things, and how do you intend to keep track of it? Do you want to do this with an object-oriented approach, or is a simple procedural approach sufficient? Do you want to be able to write this to a file and read it back in?

What is it that you need to do? If you can't specify the problem in the first place, you're going to have a hard time solving it.

This post has been edited by jon.kiparsky: 14 August 2012 - 05:22 PM

Was This Post Helpful? 0
  • +
  • -

#3 grimofdoom  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 22
  • Joined: 14-August 12

Re: List save/manipulate

Posted 14 August 2012 - 05:41 PM

the "inventory" is just a variable that the user chooses to name the list that will hold that category of items. The list will hold "item=itemname","price=itemprice","measure=itemmes","barcode=itembar". I am looking for to have the user input a name for the category then creates a list into a file(.txt or .py). Then once it is created(the program will go to main menu and chooses add item), the user can add the item name,price,measure and barcode and then it saves(or edit an item/ delete). Then (i should be able to get this and on) I want the user to be able to delete or add an inventory. That is the basic run down.(i want another file, not sure what the object oriented/simple procedure is. And it is write/read file.)
Was This Post Helpful? 0
  • +
  • -

#4 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7999
  • View blog
  • Posts: 13,701
  • Joined: 19-March 11

Re: List save/manipulate

Posted 16 August 2012 - 09:25 AM

What about using a dictionary to store each item?

item = {}
item["item_name"]="Widget"
item["measure"] = "Unit"
item["price"] = 10
etc...
inventory.add(item)




It's not really ideal, but it's a little neater than parsing a list in the format you describe.

To get the items called "Widget" you could do something like
widgets = filter(lambda x: "Widget" in x["item_name"], inventory)


or a similar list comprehension if you prefer that.

(be warned, I wrote that filter before my coffee, and I don't have python installed on this machine to test it... if it doesn't work, something like it will)
Was This Post Helpful? 0
  • +
  • -

#5 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: List save/manipulate

Posted 16 August 2012 - 11:15 AM

If you want to make your project a little more real, you might want to consider using a database. Sqlite3 is easy to use and already has a library included in your python install by default. There are even some great tutorials on SQLite 3 here at DreamInCode!

EDIT:
I was a little gun-shy about using a database at first, but it's really not as complex as you might think.

This post has been edited by atraub: 16 August 2012 - 11:16 AM

Was This Post Helpful? 0
  • +
  • -

#6 grimofdoom  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 22
  • Joined: 14-August 12

Re: List save/manipulate

Posted 16 August 2012 - 11:34 AM

Is it possible to use an offline database without needing another program to use( when user uses it once it is standalone(I think that is what I mean,where other people can use it without needing python downloaded)).
Was This Post Helpful? 0
  • +
  • -

#7 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: List save/manipulate

Posted 16 August 2012 - 06:57 PM

to keep it simple, sqlite3 is a great choice. Windows doesn't natively work with any databases, so you'll need some kind of software to work with them. There are simple sqlite3 database viewers out there that are small downloads and freely available.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1