On Apr 4, 3:42 am, "catalinf...@gmail.com" <catalinf...@gmail.com>
wrote:
> Hi everyone .
> My questions is "why vars().has_key('b') is False ?'
> I expecting to see "True" because is a variable ...
> Thanks

Yes, 'b' is a var, but only within the scope of something().  See how
this is different:

>>> def sth():
...   b = 25
...   print 'b' in vars()
...
>>> sth()
True

(Also, has_key() is the old-style way to test for key existence in a
dict, and is kept around for compatibility with old code, but the
preferred method now is to use 'in'.)

-- Paul
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to