Answer the question
In order to leave comments, you need to log in
How to get password via argparse?
I try to get the password in this way , but even nothing comes out, I do it like this
class Password(argparse.Action):
def __call__(self, parser, namespace, values, option_string):
if values is None:
values = getpass.getpass()
setattr(namespace, self.dest, values)
parser = argparse.ArgumentParser('bla bla bla')
parser.add_argument('user', help='User name to use for authentication', type=str)
parser.add_argument('-p', action=Password, nargs='?', dest='password', helс p='Enter your password')
print(parser.parse_args())
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question