python module and command line program
Question: I have a code which I'd like people to be able to use as a stand alone python
program, or to import as a module for their own codes. Is there a way to
package a module which can also include a program that can be run from the
command line?

I.e. from the command-line:

    
    
    > ZHermesCode
    

or within ipython or a python script:

    
    
    import ZHermesCode
    


Answer: Look up [Setuptools automatic script
creation](https://pythonhosted.org/setuptools/setuptools.html#automatic-
script-creation). For example, [`python-scss`](https://github.com/klen/python-
scss) uses this technique to make `scss` an executable shell command.

In [`setup.py`](https://github.com/klen/python-scss/blob/master/setup.py):

    
    
    setup(
        # ...
        entry_points={
            'console_scripts': [
                'scss = scss.tool:main',
            ]
        },
    )
    

Then defining a function `main` in
[`scss/tool.py`](https://github.com/klen/python-
scss/blob/master/scss/tool.py). It also uses the technique mentioned by Loocid
to make the `tool.py` file itself directly executable (as opposed to the
wrapper script that is publicly installed by setuptools according to the
recipe above):

    
    
    if __name__ == '__main__':
        main()
    

