?
Solved

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

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
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 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 …
Suggested Courses

777 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