Hacker News new | ask | show | jobs
by avip 2687 days ago
Very good page. But the best python cheat sheet is help(the_thing). python has the second best ever help and discoverability (after Matlab of course!)
5 comments

But. to do `help(thing)` you need to know what the _thing_ is.

With Python, many times I vaguely know something but dunno what it is exactly. This cheatsheet solves that!

Is there some way to list all modules available for importing? Some times you don't know which modules are available to ask the help for it.
>>> help('modules')
Related post on my blog:

Get names and types of a Python module's attributes:

https://jugad2.blogspot.com/2016/10/get-names-and-types-of-p...

and the same recipe on ActiveState Code (from where you can download the Python code for the recipe):

https://code.activestate.com/recipes/580705-get-names-and-ty...

You can call help on anything. Here I am asking for help on something I have no clue about:

  >>> from server.db import db
  >>> help(db)
  help on Client in module google.cloud.firestore_v1beta1.client object:
class Client(google.cloud.client.ClientWithProject) | Client(project=None, credentials=None, database='(default)') | | Client for interacting with Google Cloud Firestore API. | | .. note:: | | Since the Cloud Firestore API requires the gRPC transport, no | ``_http`` argument is accepted by this class. ...
I think legends 2k means you may not know the name of a function you need to use in something you are trying to implement.

Example: Suppose you didn't know that re was what you needed for regular expression, or suppose you forgot how iterators work etc.

Sure, that's why it's #2 on "2 Hard things in CS". Should probably be #1.
Yes! And implementing this help text for your library is free. It just assembles the docstrings found in your code. And then your favourite text editor can use this for autocomplete and such as well.

Treating docstrings as an actual reflectable part of a class/function and not just "comments to be ignored by a parser" is brilliant.

I would put it after R help function and, even better, F1 key to get the full documentation of any thing in Rstudio.
I'm amazed you think the R documentation is anything but terrible.

Compare the R vector page: https://stat.ethz.ch/R-manual/R-devel/library/base/html/vect...

To the equivalent python documentation: https://docs.python.org/3/tutorial/datastructures.html

The documentation could clearly be prettier but its strength lies in its standardization : I can get method arguments and examples for all functions of all packages in the same format and with a single keystroke.
I could not help but comment to add Elixir to the list of languages with amazing discoverability. For things in the standard library, you essentially get a condensed version of Python web documentation, with examples!
What to do `help(thing)` you need to know what the _thing_ is.

With Python, many times I vaguely know something but dunno what it is exactly. This cheatsheet solves that!