Hi All
I'm learning Python.
I have created a typical sample module online (specifically on repl.it):
[CODE lang="python" title="module example"]# Python Module example
def add(a, b):
"""
This program adds two
numbers and returns the result.
"""
return a + b
[/CODE]
Here, the module file name is
I have no problem accessing this sample function from file
[CODE title="import example module - same program"]
import example
print("example.add(2, 12) = ",
example.add(2, 12))
[/CODE]
However, when I try to access module example from another program, it is not possible, since the Python interpreter can't locate example module (screenshot attached).
How can I do this (assuming the Python program accessing example module will be distinct from the program containing function
I am asking this particularly in the context of online websites (such as repl.it) where I can create such programs entirely online.
I'm learning Python.
I have created a typical sample module online (specifically on repl.it):
[CODE lang="python" title="module example"]# Python Module example
def add(a, b):
"""
This program adds two
numbers and returns the result.
"""
return a + b
[/CODE]
Here, the module file name is
example.py, the module is named example and it contains a sample function add(a, b) which returns the sum of the parameters.I have no problem accessing this sample function from file
main.py in the same program. It works perfectly, once the import is done:[CODE title="import example module - same program"]
import example
print("example.add(2, 12) = ",
example.add(2, 12))
[/CODE]
However, when I try to access module example from another program, it is not possible, since the Python interpreter can't locate example module (screenshot attached).
How can I do this (assuming the Python program accessing example module will be distinct from the program containing function
add()? I am asking this particularly in the context of online websites (such as repl.it) where I can create such programs entirely online.