r/learnpython • • Oct 27 '19

mind blown using help() in python

I've been programming in python for about a year now. And I've never encountered this module before, and it's soooooooo incredibly useful. Like I'll probably never even google anything ever again ( ok thats total bullshit). But really my point here is if you're learning python you should be aware of and know how to use the help module IMHO. across the thousands of webpages I've been to and resources I've used to teach myself I can't believe I didn't run into it sooner. Anyways I just thought sunday was a good day for ranting and sharing. I hadn't initially planned on asking a question here but maybe we could get something along the lines of things you found out too late and or things everyone learning python IYHO should know. :)

edit:

help is a function in python which describes the object you pass to it. The description it outputs is it's docstring, as pointed out by DataDecay more information on docstrings can be found in PEP-257

so if you want more information about an object you can pass it as an argument to help.

Say for instance you were confused as I currently am about how asyncio works.

You could type help(asyncio) and it would give you information about that package (technically object).

YAYYYYYYY and rkarl7777 both mentioned another very useful utility named dir, which will list the methods available to the object passed to it.

So after gaining a general understanding of the base package you can then look through all of its methods.

dir(asyncio)

then if you have questions about any of the methods in that list you can query those with help.

help(asyncio.StreamWriter)

Now hang on just a second while I try and find somebody who is better at explaining things than I am.

I went through a couple of articles, this one seems to be the best.

https://www.linuxnix.com/python-builtin-helpdir-help-type-and-___doc_-functions/

448 Upvotes

62 comments sorted by

View all comments

8

u/dashidasher Oct 28 '19 edited Oct 28 '19

One of the things I use almost every day is the Python Debugger https://docs.python.org/3/library/pdb.html. If you put pdb.set_trace() anywhere in your code it will stop executing the script at that point and let you play around untill you use the continue command (you can also do next, step, untill...). I've only found out about it 2 months into my job working with python. Been using python for like 3 years before that too. All that time I've only used prints to debug xD

3

u/congnarjames Oct 28 '19

I'll check that out for sure!

1

u/[deleted] Oct 29 '19

Make things easier on yourself.

New in version 3.7: The built-in

breakpoint()

, when called with defaults, can be used instead of

import pdb; pdb.set_trace()

.

1

u/Brilliant_Ice4349 Dec 14 '25

Omg you're a lifesaver, whenever I'm defining a function for a piece of code later one, which I know won't work until I finish defining all the functions required for it, I had to copy paste each defining function + global variables required for it to work on another notebook 😭

1

u/dashidasher Dec 14 '25

Glad to hear. This comment is a bit outdated so make sure to use breakpoint() instead of pdb.set_trace() as one of the replies mentions :D

1

u/Brilliant_Ice4349 Dec 14 '25

Thanks :)
cookie += 1
Print(f"Here you have {cookie} cookie :)")