How to use NNN.py libraries, in Python programs, after download to the local computer?

63 Views Asked by At

In putting together a convolutional model in my computer, I want to use the convert_to_one_hot(.. utility written by Coursera/Ng. I can download their module test_utils.py, where I expect the one_hot converter to be. How do I incorporate test_utils.py to my tools? with Import? Install? where do I put the test_utils.py, or similar collections?

1

There are 1 best solutions below

2
On

Im guessing you are referring to some built in code that Andrew Ng gave, in that case if you know its a single file you can just put it wherever you want in your project and make sure that you reference to the nearest _init_.py inside your project, so for example, imagine your project looks something like this:

YourProject
    app.py
    my_module
        __init__.py
        test_utils.py
    config.py

If you were working on the app.py file and wanted to use the test_utils.py function called one_hot_encoder(), you could simply do

from my_module.test_utils import one_hot_encoder

And thats because there is a _init_.py file inside the my_module folder, which the python interpreter take that folder as a "library" name and searchs for the root you are specifying (test_utils) and returns whatever import you choose, could be either a class or a function or even a variable like a list.

NOTE: Make sure that you add other necessary scripts to your module or to pip install the libraries used in the script, for it to work.