爲positionals無效參數我想實現導入功能與必需和可選參數,以這種方式運行此:「需要」在Python命令
python manage.py import --mode archive
在需要--mode
和archive
也。
我正在使用argparse庫。
class Command(BaseCommand):
help = 'Import'
def add_arguments(self, parser):
parser.add_argument('--mode',
required=True,
)
parser.add_argument('archive',
required=True,
default=False,
help='Make import archive events'
)
但我recived錯誤:
TypeError: 'required' is an invalid argument for positionals
'archive'已被**需要,因爲它是一個位置參數。 –