开发者

Python: Module Not Found

I have a program 'a.py' which start with:

import XXX

The import works perfectly and a.py runs fine.

Then I wrote a program 'b.py' which calls 'a.py' to run continuously. It looks like this:

import os
开发者_StackOverflow社区def main():
    return os.system("a.py") 
c=main()
while(c):
    c=main()

The I got the error says that 'Import error: no module named XXX'

Can anyone please tell me what's wrong?

Both a.py and b.py are in the same folder.


Instead of using os.system, why don't you do an

import a

in b.py, and then call the function you want to run from a.py directly?


Use OOP concept, make a class, put your code inside a function and call this function from constructor. and in b.py just call make an object of the class. and you are done.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜