InetVMart Indonesia
InetVMart Indonesia

Reputation: 63

Including other Python file in current project

I have the following file. It contains several functions that I would use frequently. Instead of writing the same function over and over in every project, I think it would be more efficient if we are able to include the files in each project.

I want to include functions inside this file:

enter image description here

However, I don't know what technique is called and I am not sure if it is possible to make it work.

tools is not found:

enter image description here

Here's the folder that I want to include:

enter image description here

I have created __init__.py as explained in https://stackoverflow.com/a/4116384/17869806

Upvotes: 1

Views: 114

Answers (2)

mapsa
mapsa

Reputation: 474

If you are using a Jupyter notebook, create a new one in the folder ivm_github_python with this content:

from tools import ivm_string_print
ivm_string_print.myfunction()

in this case myfunction is defined in ivm_string_print.py

Upvotes: 1

Superstricker09
Superstricker09

Reputation: 83

So in the file which is the main file for each project you can do import filename and import it as a module in the start of the project.

Note: the file which you want to import should be in the same folder as your main file. and suppose the file name you want to import is "functions.py" when you import it write import functions and not import functions.py

pls upvote if helps :)

Upvotes: 1

Related Questions