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

Paul Moore p.f.moore at gmail.com
Fri Jan 5 06:06:25 EST 2018


On 5 January 2018 at 08:12, Nick Coghlan <ncoghlan at gmail.com> wrote:
> However, the issue then is that "python -M numpy" would just be a less
> flexible alternative to a command like "python -C 'import numpy as
> np'".

For quick one-liners don't underestimate the value of avoiding punctuation:

    # No punctuation at all
    python -M numpy
    # Needs quotes - if quoted itself, needs nested quotes
    python -C "import numpy"
    # Needs quotes and semicolon
    python -c "import numpy; ..."

This may not be a big deal on Unix shells (IMO, it's still an issue
there, just less critical) but on less-capable shells like Windows'
CMD, avoiding unnecessary punctuation can be a big improvement.

Paul


More information about the Python-ideas mailing list