[Tutor] if __name__=='main' vs entry points: What to teach new comers?

Chris Warrick kwpolska at gmail.com
Tue Aug 1 14:32:01 EDT 2017


On 1 August 2017 at 16:54, Thomas Güttler <guettliml at thomas-guettler.de> wrote:
> I have a friend who is a talented shell script writer. He is a linux guru
> since
> several years.
>
> He asked me if "if __name__=='main':" is state of the art if you want
> to translate a shell script to python.
>
> I started to stutter and did not know how to reply.
>
> I use Python since several years and I use console_script in entry_points of
> setup.py.
>
> I am very unsure if this is the right way if you want to teach a new comers
> the joy of python.
>
> In the current context we want to translate a bunch of shell scripts to
> python scripts.
>
> What do you think?
>
> Regards,
>   Thomas Güttler
>
>
> --
> Thomas Guettler http://www.thomas-guettler.de/
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

Do both. If you’re making a package, create a __main__.py file as well
so your package is usable with `python -m somepackage`. On the other
hand, if you’re making things more akin to shell scripts, using just
entry_points makes stuff harder, because you need to install the code
(and write a setup.py), as opposed to just putting the script
somewhere in $PATH.

-- 
Chris Warrick <https://chriswarrick.com/>
PGP: 5EAAEA16


More information about the Tutor mailing list