0

I have a script named main.py that imports script1.py from a dir named folder.

This script1.py imports another script named script2.py that resides in the same folder directory.

Here is the code:

main.py

import folder.script1 as s1

s1.func()

folder/script1.py

import script2 as s2

def func():
    s2.func()

folder/script2.py

def func():
    print('Ciao')

When I run main.py I get the error:

Traceback (most recent call last):
  File "C:\try.py", line 1, in <module>
    import folder.script1 as s1
  File "C:\folder\script1.py", line 1, in <module>
    import script2 as s2
ModuleNotFoundError: No module named 'script2'

Is there a nice way to make this work or should I change approach?

1 Answer 1

2

Try to import script2 like that in script1 :

import folder.script2 as s2

Same as you import it in script2, then in works fine.

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

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.