On Sat, Apr 25, 2015 at 11:13 AM, Juanald Reagan <jon.en...@gmail.com> wrote:
> Okay, so it doesn't look like that worked...here is the traceback. I don't
> understand the second part of your request.
>
> Jons-desktop:whois-0.7 2 jon$ python pythonwhois.py
>
> 8.8.8.8
>
> Traceback (most recent call last):
>
>   File "pythonwhois.py", line 14, in <module>
>
>     print results.asn_registry
>
> AttributeError: 'dict' object has no attribute 'asn_registry'


Because of the lack of subject-line context, I'm having a hard time
following this thread.  I've changed the subject to "Looking up
attributes in a dictionary."  Trying to trace the context by looking
through the archive... ok, I see:

    https://mail.python.org/pipermail/tutor/2015-April/105122.html
    https://mail.python.org/pipermail/tutor/2015-April/105123.html

... got it....


Ok, so you're replying back to Stephen, about the code snippet he
proposed, and you're running into an error.  I think I understand
better now.


Please try changing:

    print results.asn_registry

to the two statements:

    print results.keys()
    print results['asn_registry']


The first statement shows what keys are in the results dictionary.
The second statement tries to print the value associated with
'asn_registry'.

The reason that the original suggestion didn't work here is because,
in Python, object attribute lookup is different from dictionary
lookup.  We guessed that 'results' was an object, and that you wanted
to look up the 'asn_registry' attribute of that object.

But from the error message, we see that 'results' is a dictionary.
Easy to correct.  You want to use a dictionary lookup instead.

The first print statement is there just to validate that there is such
a key 'asn_registry' within the 'results'.  It's possible that the key
is different, so the first print is there just as a double-check for
us.
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to