0

I am trying to import and use a module called "wikipedia" found here...

https://github.com/goldsmith/Wikipedia

I can check all the attributes using dir function.

>>> dir(wikipedia)
['BeautifulSoup', 'DisambiguationError', 'PageError', 'RedirectError', 'WikipediaPage', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'cache', 'donate', 'exceptions', 'page', 'random', 'requests', 'search', 'suggest', 'summary', 'util', 'wikipedia']

But wikipedia.page does not return all it's sub-attributes(!?)

>>> dir(wikipedia.page)
['__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__doc__', '__format__', '__get__', '__getattribute__', '__globals__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name']

I expected to see the attributes like title, content here in this list. How do I know what are the attributes hidden within "page"?

shantanuo
  • 31,689
  • 78
  • 245
  • 403
  • I found this, it might help you. It's a similar question. http://stackoverflow.com/questions/191010/how-to-get-a-complete-list-of-objects-methods-and-attributes – Shashank Sep 03 '13 at 04:54

2 Answers2

5

Because wikipedia.page is a function. I think what you want is the attributes of WikipediaPage object.

>>> import wikipedia
>>> ny = wikipedia.page('New York')
>>> dir(ny)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'content', 'html', 'images', 'links', 'load', 'original_title', 'pageid', 'references', 'summary', 'title', 'url']

The types of these two are different.

>>> type(ny)
<class 'wikipedia.wikipedia.WikipediaPage'>
>>> type(wikipedia.page)
<type 'function'>
CyLiu
  • 401
  • 3
  • 5
0

you may want to also check out __dict__ its a nice lil dunder

>>> class foo(object):
...     def __init__(self,thing):
...         self.thing= thing
...
>>> a = foo('pi')
>>> a.__dict__
{'thing': 'pi'}

or vars which does the same thing:

>>> vars(a)
{'thing': 'pi'}
TehTris
  • 3,139
  • 1
  • 21
  • 33