On Thu, Jan 14, 2016 at 3:21 AM, Alan Evangelista <ala...@linux.vnet.ibm.com> wrote: > On 01/13/2016 02:15 PM, John Whitlock wrote: > > I've found that experienced Python developers are unaware that some standard > modules can be run as scripts (...) I find these useful every few months, > but they are also hard to discover. > > > What is the usefulness of running a standard Python module as a script? >
It depends on the module. Some are designed to be equally easily imported or run with "python -m modulename", and that's a Good Thing. Example: rosuav@sikorsky:~$ python3 -m timeit -s "def foo(): return sum(i+i for i in range(1000))" "foo()" 10000 loops, best of 3: 72.6 usec per loop rosuav@sikorsky:~$ python3 -m timeit -s "def foo(): return sum(i*2 for i in range(1000))" "foo()" 10000 loops, best of 3: 73.3 usec per loop rosuav@sikorsky:~$ python3 Python 3.6.0a0 (default:1118dfcbcc35, Jan 6 2016, 15:05:01) [GCC 4.9.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import timeit >>> timeit.repeat(setup="def foo(): return sum(i*2 for i in >>> range(1000))",stmt="foo()",number=10000) [0.809292299032677, 0.7410961069981568, 0.7404299289919436] >>> It's a way for a tool to have multiple interfaces - module or command-line tool. ChrisA _______________________________________________ pydotorg-www mailing list pydotorg-www@python.org https://mail.python.org/mailman/listinfo/pydotorg-www