不太確定該如何表達(dá),但是我正在將bash腳本轉(zhuǎn)換為python,并且試圖在python庫(kù)中調(diào)用方法,該方法通常是通過(guò)CLI調(diào)用的。該方法使用argparse并在調(diào)用時(shí)需要2個(gè)參數(shù)。我不確定如何從單獨(dú)的python腳本調(diào)用此方法并提供兩個(gè)參數(shù)。我嘗試過(guò)的>> from somelibrary import mymethod as method>> method.main('foo', 'bar')Traceback (most recent call last): File "<stdin>", line 1, in <module>TypeError: main() takes 0 positional arguments but 2 were given>>> method.main()usage: [-h] foo bar: error: the following arguments are required: foo, bar任何幫助是極大的贊賞!
如何調(diào)用需要CLI參數(shù)的python方法?
慕的地6264312
2021-04-28 14:11:48