python 如何用terminal輸入?yún)?shù)
python用terminal輸入?yún)?shù)
import argparse if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--rate',type=float,default=0.05, help='the rate of the label')
設(shè)置類型為浮點(diǎn)數(shù),默認(rèn)值為0.05,當(dāng)輸入的參數(shù)不滿足要求
python ××.py help能夠提示
parser.add_argument('--dataset', required=True, help='cifar10 | lsun | imagenet | folder | lfw ')
opt = parser.parse_args() opt.rate
補(bǔ)充:使用Python打開新的終端(terminal)并執(zhí)行語句
環(huán)境:CentOS 7
Python版本:3.6
在寫Python程序的時(shí)候遇到需要打開一個新的終端(terminal)或者說命令行窗口進(jìn)行監(jiān)視的情況,多方查詢無果,終于在Stack Overflow上找到了。
import os os.system("gnome-terminal -e 'ls'")
其中 'ls' 部分即為所需執(zhí)行的內(nèi)容。
這樣打開的窗口會在執(zhí)行完成后關(guān)閉,不希望關(guān)閉則可以寫:
os.system("gnome-terminal -e 'bash -c \"ls; exec bash\"'")
以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
pytorch和numpy默認(rèn)浮點(diǎn)類型位數(shù)詳解
這篇文章主要介紹了pytorch和numpy默認(rèn)浮點(diǎn)類型位數(shù),具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-02-02使用Python實(shí)現(xiàn)保存剪貼板中的圖像
這篇文章主要為大家詳細(xì)介紹了如何使用Python創(chuàng)建一個簡單的GUI應(yīng)用程序,實(shí)現(xiàn)保存剪貼板中的圖像功能,文中的示例代碼講解詳細(xì),需要的可以參考下2023-09-09