How to change a Python module name?
Question: Is it only possible if I rename the file? Or is there a `__module__` variable
to the file to define what's its name?


Answer: If you really want to import the file 'oldname.py' with the statement 'import
newname', there is a trick that makes it possible: Import the module
_somewhere_ with the old name, then inject it into `sys.modules` with the new
name. Subsequent import statements will also find it under the new name. Code
sample:

    
    
    # this is in file 'oldname.py'
    ...module code...
    

Usage:

    
    
    # inject the 'oldname' module with a new name
    import oldname
    import sys
    sys.modules['newname'] = oldname
    

Now you can everywhere your module with `import newname`.

