python用terminal輸入參數
1
2
3
4
|
import argparse if __name__ = = '__main__' : parser = argparse.ArgumentParser() parser.add_argument( '--rate' , type = float ,default = 0.05 , help = 'the rate of the label' ) |
設置類型為浮點數,默認值為0.05,當輸入的參數不滿足要求
python ××.py help能夠提示
1
|
parser.add_argument( '--dataset' , required = True , help = 'cifar10 | lsun | imagenet | folder | lfw ' ) |
1
2
|
opt = parser.parse_args() opt.rate |
補充:使用Python打開新的終端(terminal)并執行語句
環境:CentOS 7
Python版本:3.6
在寫Python程序的時候遇到需要打開一個新的終端(terminal)或者說命令行窗口進行監視的情況,多方查詢無果,終于在Stack Overflow上找到了。
1
2
|
import os os.system( "gnome-terminal -e 'ls'" ) |
其中 'ls' 部分即為所需執行的內容。
這樣打開的窗口會在執行完成后關閉,不希望關閉則可以寫:
1
|
os.system( "gnome-terminal -e 'bash -c \"ls; exec bash\"'" ) |
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持服務器之家。
原文鏈接:https://www.cnblogs.com/kangronghu/p/6682750.html