tags:

views:

78

answers:

3

Dear All, Hello, I am very new at python. I have an existing example project that have some scripts YYY,in path XXX/YYY and an script A.py that call these one by one, I only want to add an script ZZZ.py to the YYY scripts so that call after them. I add this scrit 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 wounder what is the difference? Why python can import XXX/YYY py files but returns this error for ZZZ.py? Anybody could help me? Thanks in advance

A: 

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.

Tshepang
A: 

but YYY is not directory!!! I think that maybe previous explanation of my problem is not accurate enough. So I try to explain it more by the following paragraphs. YYY is colection of py files {Y1,Y2,....}, that are imported to A.py. I mean that in A.py file we have this:

import XXX.y1 as Y1 Y1.doSomething1() import XXX.y2 as Y2 Y2.doSomething2()

... and so,

All Y1,Y2,... files in XXX directory are called in the same way, but when I add new python file in XXX directory, named it to ZZZ and change A.py to this:

import XXX.y1 as Y1 Y1.doSomething1() import XXX.y2 as Y2 Y2.doSomething2() import XXX.ZZZ as Z Z.doSomething()

Python can not import ZZZ. and returns "python import error no module named XXX/ZZZ.py" I wounder what is the difference between ZZZ and Y1 or Y2,....

razieh eskandari
A: 

OOOOOOOh! what a big mistake! I found it, Python import files from other directory! my example project install itself in the other path and i forgot about it!!

razieh eskandari