zoukankan      html  css  js  c++  java
  • python -c 执行单行命令/脚本,有点意思

    python -c参数,支持执行单行命令/脚本。
    例:

    > python -c "import os;print('hello'),print('world')"
    > python -c "import os;print('hello');print('world')"

    注意:要用双引号将命令包起来,import要以**;结尾,命令用[]括起来,多行命令用多个[]**

    > python -c "import os,time;[print(i) for i in os.listdir()];[print(time.time())]"
    > python -c "import os,time;[print(i) for i in os.listdir()],[print(time.time())]"

    复杂的命令必须要用**[]**括起来,否则会报错。

    格式上还可以多尝试一下:

    > python -c "print('hello');print('world')"
    > python -c "print('hello'),print('world')"
    > python -c "[print('hello'),print('world')]"
    > python -c "[print('hello')],[print('world')]"

    这几条的输出是一样的。
    以上。
    ————————————————
    版权声明:本文为CSDN博主「phoenix339」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/phoenix339/article/details/90405610

  • 相关阅读:
    HDU 1261 字串数(排列组合)
    Codeforces 488C Fight the Monster
    HDU 1237 简单计算器
    POJ 2240 Arbitrage
    POJ 3660 Cow Contest
    POJ 1052 MPI Maelstrom
    POJ 3259 Wormholes
    POJ 3268 Silver Cow Party
    Codesforces 485D Maximum Value
    POJ 2253 Frogger(最短路)
  • 原文地址:https://www.cnblogs.com/sggggr/p/12187616.html
Copyright © 2011-2022 走看看