Hacker News new | ask | show | jobs
by legends2k 2687 days ago
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!

2 comments

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.