This is not in any way meant to be negative, I am open to learn how it’s done in Python. However I am having a hard time coming from Java development to Python.
In Java we have the Java Docs where for each class all functions/methods are listed with their parameter syntax and a quick description what each parameter does.
In this specific case, I have found a code snipped that uses:
with utils.elapsed_timer('predict', batch_size) as timer:
Now in Java my usual way to understand what this does is, to open the language documentation for the utils module, find the elapsed_timer object, and look up in the constructors section what these parameters do.
Even using a search machine, I haven’t found such a documentation for this object in question. So right now, I am stuck.
Thanks for help in advance!
elapsed_timer is not a function provided from Python, nor does it have a module called
utils. It really depends on where the person who provided that snippet got that function from, they may have written it themselves.
To answer your question more generally, the place to start for functionalty provided by Python is docs.python.org Go to the “Library Reference” and there you will find a full list of all the standard Python modules. I cover this a little in my course notes at Using functions - Intermediate Python.
For docs on any third-party modules, you will have to look on their websites.
Thanks! That explains why I haven’t found the utils module in the documentation. I’ve now checked other modules and they provide what I am looking for, a list of functions with their parameters.
Probably I just guessed that utils must be a standard Python library, since many languages have a standard “utils” library. That explains it, of course third-party documentation is always a hit-or-miss depending on how their creators prioritized it.
I’ll now try to find the source of the library in the code example, that will get me further. Please excuse my obvious mistake.
I expect the reason you’re not finding official Python documentation
is that there is no “utils” module in the standard library:
>>> import utils
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'utils'
If you would say where you found this example, it might allow others
to help you figure out where the suggested module can be obtained
(and that should hopefully lead to documentation provided by its
And just one more note… you can use the interpreter to introspect a bit if the author provided documentation in the form of docstrings. That is, you might get some joy by doing:
Python 3.10.4 (main, Mar 25 2022, 00:00:00) [GCC 11.2.1 20220127 (Red Hat 11.2.1-9)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import utils
A good IDE can show you that information while coding, without the need to open a separate session.
I have found it by now. Actually I was pretty dumb, because I haven’t read the whole example, and the utils module is just there, as another file with the example. So I could even read what it does exactly.
Of course I can provide the source of the example. It’s the IBM HElayers demo experience, as shown in this video: IBM Homomorphic Encryption: Getting Started with HElayers in Python - YouTube
Thanks for your help!