It does not work in a function that later defines type as a local variable, that overrides the type() function.
On Feb 26, 1:02 pm, LightOfMooN <[email protected]> wrote: > So I make little function, that's work > > def makelist(items): > if type(items) != list: > items = [items] > return items > > but don't understand, why previous not working > > On 26 фев, 23:53, LightOfMooN <[email protected]> wrote: > > > > > > > > > if type('asd') == str: > > pass > > > 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

