1

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()

1 Answer 1

1

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")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.