Weird errors when trying to access a dictionary key

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Thu Jul 19 06:43:04 CEST 2007


robinsiebler at gmail.com a écrit :
> I have a data structure that looks like this:
> 
(snip)
> 
> I get the following error:
(snip)
> AttributeError: 'list' object has no attribute 'keys'

Already answered.

> Here is where it gets weird:
> 
> type(song)
(snip)
> TypeError: 'str' object is not callable

You code snippet started with:
    if type == 'artist':

which implies you bound the name 'type' to a string. Then you try to use 
  the object bound to name 'type' as a callable. Python's bindings are 
just name=>object mappings, and nothing prevents you to rebind a builtin 
name. IOW, avoid using builtins types and functions as identifiers.

HTH




More information about the Python-list mailing list