Reputation: 21
How can I properly pass a Command Line Argument to assign a number to a variable. Below is a simple password generator that I created but cant get the arguments to work when passing them through the terminal:
#!/usr/bin/env python3
# This script creates a secure password using all available key combinations.
# System arguments aka command line arguments
import secrets , string, os, sys
from sys import argv
chars = string.ascii_letters+string.punctuation+string.digits
argv = one, two
print()
#pwd_length = int(input('Enter the length of the desired password: '))
pwd_length = two
print()
print('[+] ' + 'Your secure password is:')
print()
for n in range(1):
output = ""
for i in range(pwd_length):
next_index = secrets.SystemRandom().randrange(len(chars))
output = output + chars[next_index]
print(output)
print()
Upvotes: 1
Views: 503
Reputation: 21
In case anyone is wondering how to make a command line arguement, it ended up being simple, here is the solution:
#!/usr/bin/env python3
# This script creates a secure password using all available key combinations.
import secrets , string, os, sys
chars = string.ascii_letters+string.punctuation+string.digits
pwd_length = int(sys.argv[1])
print("\n",'[+] ' + 'Your secure password is:',"\n")
for n in range(1):
output = ""
for i in range(pwd_length):
next_index = secrets.SystemRandom().randrange(len(chars))
output = output + chars[next_index]
print(output,"\n")
Upvotes: 1