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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM