How can I make my python file a module that can be imported from any where without specifying that path when not in the CD.
@gururajankappa Hello, do you have an example of your code so we can see what the issue is?
def multiply(a, b): return a * b def add(a, b): return a + b
from utility.mathFunction import add add(a, b)
Instead of having to import mathFunctions.py like I did.
I want to import it like I import normal modules
Like import tkinter
Just from mathFunction import add
How can I do that.
You will not be able to import from anywhere. Make sure that you make a separate folder to store each project and you can import like this.
myproject/ myproject/main.py myproject/math_functions.py
from math_functions import add_two_numbers add_two_numbers(10, 20)
Or you can create a Python package.
myproject/ myproject/main.py myproject/math_functions/__init__.py myproject/math_functions/addition.py
from math_function.addition import add_two_numbers add_two_numbers(11, 22)
Here is for info on how to import modules.
some more characters