Solved

Error using ...GetSelections return values into a list=[] what is wrong?

Posted on 2010-11-28
2
406 Views
Last Modified: 2012-05-10
ok Im choosing from the list box supplies used.... gotta have the ability to choose multiple selections... I want to put them in a list, but I keep getting and error... its important to put this in a list because when I'm done I need to clear the list for the next entry.... you can see in the code that ive tried to get it in a list ... but I cant get it to work... then once its in the list i set up if/ elseif statements.... if the value retured = '1' then.... but the program wont recognize  the number... why not and what should I do to fix this... last question is the way I am doing this the best way to go about this ?


self.sampleList =['gauze pads', '2" medical tape','1" medical tape','cravats'   
        self.listbox = wx.ListBox(panel,-1,(700,30), choices=self.sampleList,
                style=wx.LB_EXTENDED)
        self.listbox.Bind(wx.EVT_LISTBOX, self.listboxClick)
    def listboxClick(self,event):
    # for multiple and single item select use this ...
        supplies = self.listbox.GetSelections()
        selected_list = []
        print supplies
        
        
        for sup in supplies
            selected_list.append(self.selected_list[pos])
        s = str(self.selected_list)
        print s
        #self.text_out.ChangeValue(s)
        
        if supplies =='1':
                print 'Medical Tape -1'
                self.new_supply = -1
        else:
                pass
        
        
   def getinventory(self,event):
        con = lite.connect('supplies.sqlite')
        cur = con.cursor()
        cur.execute("select * from  inventory())
        rows = cur.fetchone()
        self.standing_inv = rows[0]
        self.ln = rows[1]
        self.fn = rows[2]
        cur.close()               
        con.close()
    
    def updateinventory(self,event): 
        con = lite.connect('supplies.sqlite')
        cur = con.cursor(
        new_inventory = self.standing_inv - self.new_supply
        medical_tape = self.new_inventory
            
            cur.execute('update inventory set medical_tape=? , gauze=?,
                        ( medica;_tape, gauze))
                         
            con.commit()
            cur.close()
            con.close()

Open in new window

0
Comment
Question by:dolamitejenkins
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
Mytix earned 500 total points
ID: 34227985
Its rather dangerous converting list to string using str(). Maybe instead of doing this:
        supplies = self.listbox.GetSelections()
        selected_list = []
        print supplies
        
        
        for sup in supplies
            selected_list.append(self.selected_list[pos])
        s = str(self.selected_list)
        print s
        #self.text_out.ChangeValue(s)
        
        if supplies =='1':
                print 'Medical Tape -1'
                self.new_supply = -1
        else:
                pass

Open in new window

Do this:
        supplies = self.listbox.GetSelections()
        for sup in supplies:
            if str(sup) == '1':
                print 'Medical Tape -1'
                self.new_supply = -1
            else:
                pass

Open in new window

The reason is that when you do a str() on a list, the [] and the spaces and commas are retained and you have to check for them too (which isn't a good idea)
Let me know if that works
0
 

Author Closing Comment

by:dolamitejenkins
ID: 34228042
perfect thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question