I'm just trying to run a basic python script by importing the script to a second python module. But when I try to run it keep getting an error that says:
"exceptions.ImportError: No module name AUTO"
Here is my code on the second module:
import AUTO
def main():
pass
if __name__ == '__main__':
main()
AUTO.printDate()
AUTO is another module that has one function printDate() which just prints today's date. It just keeps error-ing out.
1 Answer 1
to import another module, it shall:
- be a file that ends with
.py - be in python import's path:
- anywhere in your
sys.pathor - in current directory or
- in any directory below your current directory that has a
__init__.py(but then you have to import it usingimport thatdirectory.mymodule)
- anywhere in your
if you don't respect those rules, your file will not be seen by python's import system.
let's suppose the code you have in your question is foo.py, you want to have foo.py and AUTO.py together in the same directory, wherever they are.
2 Comments
AUTO.py. So it must be a directory problem then? I just need to figure out a way to find out what directory to save it in...
sys.path?