Executable directories and compressed executable directories in python
Executable directories is main entry point when the package is executed. This can be used to distribute a huge python program to wider user to execute package.
Example:
~/py$ ls -ld directory0
drwxr-xr-x 3 nansari nansari 4096 Jan 1 09:32 directory0
~/py$ python directory0
/home/nansari/anaconda3/bin/python: can't find '__main__' module in 'directory0'
~/py$
~/py$ touch directory0/__main__.py
~/py$ python directory0
~/py$
~/py$ cat >>directory0/__main__.py
print('__main__ from directory0 is being executed now')
~/py$ python directory0
__main__ from directory0 is being executed now
~/py$
Compressed Excitable Directory
~/py$ cd directory0
~/py/directory0$ zip -r ../directory0.zip *
adding: __main__.py (stored 0%)
adding: __pycache__/ (stored 0%)
adding: __pycache__/__main__.cpython-37.pyc (deflated 22%)
~/py/directory0$ cd ..
~/py$ python directory0.zip
__main__ from directory0 is being executed now
~/py$
Even .zip extension can be removed, still __main__.pty executed when directory executes!
~/py$ cp -a directory0.zip my_package
~/py$ python my_package
__main__ from directory0 is being executed now
~/py$ file my_package
my_package: Zip archive data, at least v1.0 to extract
~/py$
Example:
~/py$ ls -ld directory0
drwxr-xr-x 3 nansari nansari 4096 Jan 1 09:32 directory0
~/py$ python directory0
/home/nansari/anaconda3/bin/python: can't find '__main__' module in 'directory0'
~/py$
~/py$ touch directory0/__main__.py
~/py$ python directory0
~/py$
~/py$ cat >>directory0/__main__.py
print('__main__ from directory0 is being executed now')
~/py$ python directory0
__main__ from directory0 is being executed now
~/py$
Compressed Excitable Directory
~/py$ cd directory0
~/py/directory0$ zip -r ../directory0.zip *
adding: __main__.py (stored 0%)
adding: __pycache__/ (stored 0%)
adding: __pycache__/__main__.cpython-37.pyc (deflated 22%)
~/py/directory0$ cd ..
~/py$ python directory0.zip
__main__ from directory0 is being executed now
~/py$
Even .zip extension can be removed, still __main__.pty executed when directory executes!
~/py$ cp -a directory0.zip my_package
~/py$ python my_package
__main__ from directory0 is being executed now
~/py$ file my_package
my_package: Zip archive data, at least v1.0 to extract
~/py$
Comments
Post a Comment