1

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

1

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

it is working after i add sys.path.append('/Users/inetvmart/Documents/GitHub/ivm_github_python/tools/')
1

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 :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.