Advanced ways to get object information from within python

Alan Gauld learn2program at gmail.com
Thu Dec 23 16:24:59 EST 2021


On 23/12/2021 11:01, Julius Hamilton wrote:
> Lastly, the "help" function.
> 
> I find "help" to similarly be a situation of information overload. 

I assume you know that you can target help() to the specific
attribute or function you need not just the top level classes?

So combined with dir() you can call help on each of the names
that dir() reveals.

That usually produces a much more focused form of documentation.

So in your example:

> dir(scrapy) shows this:

>['Field', 'FormRequest', 'Item', 'Request', 'Selector', 'Spider',
'__all__', '__builtins__', '__cached__', '__doc__', '__file__',
'__loader__', '__name__', '__package__', '__path__', '__spec__',
'__version__', '_txv', 'exceptions', 'http', 'item', 'link',
'linkextractors', 'selector', 'signals', 'spiders', 'twisted_version',
'utils', 'version_info']

> I wish there was a convenient way for me to know what
> all of these are.

help(scrapy.http)
help(scrapy.spiders)
etc...

And if it turns out they are not functions or classes
you can use [p]print to get the values. You can also
use type() to clarify what kind of thing an attribute is.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



More information about the Python-list mailing list