Solved

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

Posted on 2010-11-28
2
379 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
2 Comments
 
LVL 3

Accepted Solution

by:
Mytix earned 500 total points
Comment Utility
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
Comment Utility
perfect thanks
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now