Hi again! I’m writing this article the night before my mock IT matura exam, so it’s probably not the wisest choice but history will judge me later. I discovered a few things to help you during the exam when you get stuck and I want to share them with you.
I know that probably python is not the thing most of you use everyday, and even if you use it everyday or occasionally (like me) you still google lots of things. We’re practically always connected to the Internet so it’s not a problem - just type “parsing date python” and it’s there (fyi pros also do that). But what if we got disconnected, don’t remember a thing, and we REALLY want to know which function to use in order to parse dates?
It turns out that’s not only the case when you are on vacation in small village far far away but you need to prepare hot fix on the spot. It might also happen that you one day wake up as high school student who need to take the IT matura exam.
But the reason for your desperate need to find information about python functions and modules offline is irrelevant. The only thing that matters is that I have found a few solutions for you. Check them out!
Looking for info about python functions and modules OFFLINE
Let me present you 3 ways of searching info about python functions.
Using docs app
Important: I didn’t test that
If you use linux and you have one installed (
apt install python-doc), you are good to go, but if you don’t (which might be the case), see below.
(Possibly not working) Looking into
Important: I didn’t test that
AHuman user posted this on StackOverflow in 2014 (possibly outdated?). He suggests browsing
Doc dir in python installation directory.
Look in the python folder in the folder: Doc. This folder has the entire downloaded documentation of the python docs from python.org. I know this is a VERY late answer, but it brings up an easy solution.
Unfortunately, there’s great chance that your Windows Python installation lacks
Doc dir, especially if Python was installed through Microsoft Store.
Let see other solutions then!
Browsing modules & functions docs
The fact that docs may not be included as files doesn’t mean they aren’t present on your device.
When you start interactive python interpreter (type
python3 and press Enter), you can use
help function to get information about modules or functions.
As argument you may pass function or module name. If the the page is long, you can navigate by using
k keys (not sure if arrows work), and exit using
But in my opinion reading from console and navigating inside it is not something many people want to do during MATURA exam. They find it often cumbersome. Since I use Windows on my MATURA exam, but on a daily basis use Ubuntu I find it cumbersome too (I was trying to grep help on Windows hah).
Luckily there’s a way for us.
Python ships with built-in module
help function uses internally to show you docs. But
pydoc module can do a lot more, it can show you docs as website with search box to help you filter needed info. That’s something we want, isn’t it?
pydoc is not added to PATH so you cannot use it from Command Line/Terminal directly.
(Not relevant info: You can still use it if you use virtual env, which I don’t suspect you’ll be using during matura).
How should we use it then?
With simple oneliner you type into Command Line/Terminal:
python3 -c "import pydoc;pydoc.browse(1234)"
It opens your browser with the offline site I described above. Pretty neat!
If you know what are CLI flags and you are worried that I use linux-style flag
-c not windows-style
/c, don’t be. Python on Windows just accepts linux-style flags.
Explain that oneliner to me
- We run python normally but
-cflag allows us to put our python code directly into the command.
- In quotes we put python code
- First, we import pydoc module and in next line (when using python CLI, newline can be indicated by semicolon) we run
1234argument, which is port number we want to run our site on.
Tips for using pydoc browser
I highly recommend that you use “Get” box which prints docs right away than “Search” box which prints module names.
Remember: You need to know function/module name in order to use pydoc browser.
What if I don’t know the function name?
There’s cute little code I found here on Stack
import __builtin__ import inspect builtin_functions = [name for name, function in sorted(vars(__builtin__).items()) if inspect.isbuiltin(function) or inspect.isfunction(function)] print(builtin_functions)
I would love to explain it to you how that code works but I gotta go and sleep a few hours. Some clue on what’s going on with that snippet you can find in my previous article.
But if you got function names, you can more less deduct their purpose and then search pydoc for further questions.
If you going to take IT matura exam like me, best of luck to you my friend!
If you know any better solutions for browsing python docs offline, please let me know in the comments!