?
Solved

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

Posted on 2010-11-28
2
Medium Priority
?
424 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 2000 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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
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…
Suggested Courses

864 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