On Tue, Jul 3, 2012 at 9:35 AM, Daniel Gonzalez <gonva...@gmail.com> wrote:
> Hi,
>
> I have a function which can receive a dict or a list, and do different
> actions depending on the type. I have tried to:
>
> import types
>
> But I am getting an error when my application starts up:
>
> "Activity AttributeError: 'undefined' has no attribute 'CodeType'"
>
> How can I solve this problem? How can I do introspection in pyjs?

i would embrace duck-typing and just use whatever the incoming value
"feels like":

try:
  for k, v in incoming.iteritems():
    print 'i'm mapping-like!'
except AttributeError:
  for v in incoming:
    print 'i'm list-like!'

... or:

if hasattr(incoming, 'items'):
  for k, v in incoming.iteritems():
    print "i'm mapping-like!"
elif hasattr(incoming, 'append'):
  for v in incoming:
    print "i'm list-like!"
else:
  print "i'm something else!"

... don't detect/compare types, please :-).  i have to correct my
colleagues code all the time because i send dict or list-like objects
into their code and then they do something pointless like
`isinstance(object, dict)`, and then i get rejected.

-- 

C Anthony

Reply via email to