0

I am very new at Python. I have an existing example project that has the scripts YYY in path XXX/YYY, and a script A.py that call these one by one.

I only want to add a script ZZZ.py to the YYY scripts so that call after them. I add this script in the same path (XXX/ZZZ.py) and try to import it in the A.py and call it.

But I got this error:

python import error no module named XXX/ZZZ.py

I wonder: What is the difference? Why can Python import XXX/YYY py files but return this error for ZZZ.py?

2
  • 4
    what are the actual import lines that work and the one that does not Commented Jul 8, 2010 at 8:45
  • The typical import in file A.py is : import XXX.YYY as Y Y.doSomething() import XXX.ZZZ as Z Z.doSomethingElse() Python can run Y.doSomething() but fails to import XXX.ZZZ!! Commented Jul 8, 2010 at 9:03

2 Answers 2

2

If your modules are structured like this:

/XXX

    __init__.py
    ZZZ.py
    /YYY

        __init__.py

        *more scripts here*

And if the directory containing XXX is in your PYTHONPATH, then

import XXX.ZZZ as Z

should work.

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

Comments

0

If you want to import ZZZ, do import XXX.YYY.ZZZ as Z. This assumes that YYY is a directory, and also assumes you actually put that ZZZ.py inside of YYY.

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.