Just magic ...

Armin Steinhoff a-steinhoff at web.de
Fri Apr 2 14:54:34 EST 2004


root wrote:
> Jeff Epler wrote:
> 
>> I don't know, and since the code you posted doesn't run I can't find
>> out.
> 
> 
> #it's only a subset of the code ...
> 
> class SlaveParSet(QDialog):
>     def __init__(self,parent = None, name=None, modal = 0, fl = 0,
>                  Conf='PROFIBUS', saddr= 0):
> 
>         if name == None:
>             self.setName('SlaveParSet')
> 
>         self.config_name=conf
>         self.slave_addr = saddr
> 
>         self.gsd_connect = sqlite.connect("gsd_db")
>         self.gsd_curs    = self.gsd_connect.cursor()
> 
>         # open project data base
>         self.prj_connect = sqlite.connect("proj_db")
>         self.prj_curs    = self.prj_connect.cursor()
> 
>         self.ID = ''
>         self.IMpos = 0
> 
> 
>     # insert selected module into installed modules
>     def ModuleSelectionval(self, nr):
>         module = str(self.ModuleSelection.text(nr))
> 
>         #rebuild pos/module relationship
>         Sel = str("""select mod_pos, mod_name, proj, saddr,
>                      mod_config_data, mod_prm_data
>                      from INSTMODULE where proj= %s and saddr = %s""")
>         Key = (self.config_name, self.slave_addr)
>         self.prj_curs.execute(Sel, Key)
>         ins_list = self.prj_curs.fetchall()
> 
> #ins_list is a list and contains now one tuple
> 
>         if len(ins_list):
>            self.IMpos +=1
>            InsPos = self.IMpos
> 
>            Ins = str("""insert into INSTMODULE(mod_pos, mod_name, proj,
>                         saddr, mod_config_data, mod_prm_data)
>                         values (%s, %s, %s, %s, %s, %s)""")
> 
>            self.IMpos =0
>            for set in ins_list:
>               setdata = (self.IMpos,) +  set[1:]
> 
> # set should reference a tuple but it refers to class instance .. WHY??


However ... my work around looks like:

            for set in ins_list:
               lset = ()
               for i,val in enumerate(set):
                   lset = lset+ (val,)

               self.setdata = (self.IMpos,) +  lset[1:]
               self.prj_curs.execute(Ins, self.setdata)
               self.InstModules.insertItem(lset[1], self.IMpos)

Is there a better solution ??

Armin

> 
>               self.prj_curs.execute(Ins, setdata)
>               self.InstModules.insertItem(set[1], self.IMpos)
>               self.IMpos +=1
>               if InsPos == self.IMpos:
>                  self.InstModules.insertItem(new_item[1], self.IMpos)
>                  self.prj_curs.execute(self.Ins, new_item)
>                  self.IMpos +=1
>            if self.IMpos > 0:
>               self.IMpos -= 1
> 
>            self.InstModules.setCurrentItem(self.IMpos)
>            self.prj_connect.commit()
>         else:
>            self.IMpos = 0
>            self.InstModules.clear()
>            self.InstModules.insertItem(module, self.IMpos)
>            self.InstModules.setCurrentItem(self.IMpos)
> 
> 
> 
>>
>>
>>>>> self.IMpos =0
>>
>>
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in ?
>> NameError: name 'self' is not defined
>>
>> Jeff
>>



More information about the Python-list mailing list