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
Solved

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

Posted on 2010-11-28
2
393 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
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

"The time has come," the Walrus said, "To talk of many things: Of sets--and lists--and dictionaries-- Of variable kinks-- And why you see it changing not-- And why so strange are strings." This part describes how variables and references (see …
Sequence is something that used to store data in it in very simple words. Let us just create a list first. To create a list first of all we need to give a name to our list which I have taken as “COURSE” followed by equals sign and finally enclosed …
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 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…

792 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