Is it generally a good idea to put a console client into module's if __name__ == "__main__":
section? E.g. code to setup argparser and preprocess user input.
Asked
Active
Viewed 71 times
-1

Kartner
- 11
- 2
-
1Basically it comes down to what the program needs to do. For testing purposes it may be better to move things to a `def main()` function. – Simeon Visser Nov 11 '14 at 22:46
1 Answers
0
With this, a program will effectively double as a module and a script. There's nothing wrong with this per se. The pdb
standard module is an example and e.g. programs that run as Windows services using win32serviceutil.ServiceFramework
are usually done this way.
Your only concern here is if you have several scripts and/or modules, you can still tell which is which. See Is a Scripts directory an anti-pattern in Python? If so, what's the right way to import? for a related discussion.

Community
- 1
- 1

ivan_pozdeev
- 33,874
- 19
- 107
- 152