The doc says
Some Python modules are also useful as scripts. These can be invoked using python -m module [arg] ..., which executes the source file for module as if you had spelled out its full name on the command line
I wrote this code to help myself understand the -m
def print_hi(n=1):
print('hi'*n)
if __name__ == "__main__":
print_hi(9)
I saved this as a file aname.py
.
And then I ran this command, and get the expected result.
$ python aname.py
hihihihihihihihihi
question
When I execute the file as a module, this error shows up
$ python -m aname.py
/usr/bin/python: Error while finding module specification for 'aname.py' (AttributeError: module 'aname' has no attribute '__path__')
What causes this error? How to fix it?