0

i am trying to import a function from another file

a/b/c.py
a/1/2.py

i wanted to import a funciton from c.py in 2.py

sys.path.insert(1, '/path/to/c/py/a/b/c')
from c import function1, function2

i got this error:

Traceback (most recent call last):
  File "path\to\2\py\a\1\2.py", line 5, in <module>
    from c import function1, function2

ModuleNotFoundError: No module named 'c'
New contributor
Erdem Sarikaya is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
2
  • This might help, How to write a Python module/package?
    – Nesi
    Commented 28 mins ago
  • The sys.path should contain the directories (and maybe ZIP files) that contain the top-level modules or packages. As c is actually a module file c.py it must not be part of a sys.path path. Commented 6 mins ago

0

Your Answer

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

Browse other questions tagged or ask your own question.