[Python-ideas] Syntax to import modules before running command from the command line

Wes Turner wes.turner at gmail.com
Fri Jan 5 02:31:28 EST 2018

Could it just check if -c and -m are both set?
That way there'd be no need for -p or -M.

(I have an -m <module> switch in pyline which does exactly this. It makes
copying and pasting less convenient; but does save having to type 'import
module;’ for one liners)

On Friday, January 5, 2018, Steve Barnes <gadgetsteve at live.co.uk> wrote:

> Currently invoking `python -c "some;separated;set of commands;"` will,
> if you need to use any library functions, require one or more import
> somelib; sections in the execution string. This results in rather
> complex "one liners".
> On the other hand `python -m somelib` will load somelib and attempt to
> execute its `__main__()` or give an error if there isn't one.
> What I would like to suggest is a mechanism to pre-load libraries before
> evaluating the -c option as this would allow the use of code from
> libraries that don't have a `__main__` function, or those that do but it
> doesn't do what you want.
> Since -m for module is already taken I would suggest one of:
>     -p for pre-load module
>     -M for load module without attempting to execute `module.__main__()`
> and without defining "__main__" in the load context or
>     -l for library
> with the last two having the advantage of appearing next to -m in the
> --help output.
> This would change, (for a trivial example):
>     `python -c"import numpy;print(numpy.pi);"`
> to:
>     `python -M numpy -c"print(numpy.pi);"`
> --
> Steve (Gadget) Barnes
> Any opinions in this message are my personal opinions and do not reflect
> those of my employer.
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180105/80563530/attachment.html>

More information about the Python-ideas mailing list