Yes, it's so. I should be more careful with variable names :)

On 27 фев, 00:54, Jonathan Lundell <[email protected]> wrote:
> On Feb 26, 2011, at 11:50 AM, LightOfMooN wrote:
>
>
>
> > function is too big (150+strings)
> > but I find some peace of code in it:
>
> > props = get_props_by_section_id_list([section_id,])
> >    gsp_ids = {}
> >    for type in props.keys():
> >        gsp_ids[type] = {}
> >        for prop in props[type]:
> >            gsp_ids[type]
> > [prop.id]=db((prop.id==db.sections_properties.prop_id)&(db.sections_propert 
> > ies.type==type)).select(db.sections_properties.id).first().id
>
> > maybe because of that?
>
> Yes. That creates a local binding of type that obscures the built-in 
> function. Change 'type' here to another name and you should be OK.
>
>
>
>
>
>
>
>
>
> > On 27 фев, 00:11, Jonathan Lundell <[email protected]> wrote:
> >> On Feb 26, 2011, at 10:53 AM, LightOfMooN wrote:
>
> >>> if type('asd') == str:
> >>>    pass
>
> >> Could you post the whole function? It sounds like you might be rebinding 
> >> type.
>
> >>> Traceback (most recent call last):
> >>>  File "/home/www-data/web2py/gluon/restricted.py", line 188, in
> >>> restricted
> >>>    exec ccode in environment
> >>>  File "/home/www-data/web2py/applications/rushops/controllers/
> >>> shop.py", line 376, in <module>
> >>>  File "/home/www-data/web2py/gluon/globals.py", line 95, in <lambda>
> >>>    self._caller = lambda f: f()
> >>>  File "/home/www-data/web2py/gluon/tools.py", line 2314, in f
> >>>    return action(*a, **b)
> >>>  File "/home/www-data/web2py/applications/rushops/controllers/
> >>> shop.py", line 203, in structure
> >>>    if type('asd') == str:
> >>> UnboundLocalError: local variable 'type' referenced before assignment
>
> >>> but in the other function:
>
> >>> ids = request.vars.filetodelete
> >>>                if type(ids) != list and ids:
> >>>                    ids = [ids]
>
> >>> works fine

Reply via email to