Syntax error with Python one-liner

前端 未结 2 1995
执念已碎
执念已碎 2020-12-10 15:43
python -c \'import sys; print \"a\"\'

works, and

python -c \'for a in [1, 2, 3]: print a\'

works, but

<         


        
2条回答
  •  眼角桃花
    2020-12-10 16:03

    Not an answer to your exact question, but still may help someone. You can actually split the command line in shell.

    sh/bash/etc:

    python -c 'import sys
    for a in [1, 2, 3]: print a'
    

    Windows cmd (C:\> and 'More?' are cmd prompts, don't enter those):

    C:\>python -c import sys^
    More?
    More? for a in [1, 2, 3]: print a
    

提交回复
热议问题