I'm new user of stackoverflow, besides I'm not an English guy, so I'm sorry for my english.
I was programming in python 'til I got a mistake tho I'm not able to figure out what's wrong...
#!/usr/bin/env python2.7 from random import choice import sys def help(): print ("Please, you need to introduce a Int in this way: PWrand 10") def PWrand(insert_by_user): chars = 'ABCDEFGHIJKLMNOPQRSTUWXYZabcdefghijklmnopqrstuwxyz0123456789!-_:.,;&)(' for password in range(insert_by_user): sys.stdout.write(choice(chars)) #Command Line if __name__ == '__main__': if len(sys.argv) < 2 or len(sys.argv) > 2: help() elif (type(sys.argv[2]) != int): print("It need to be an Int!") else: insert_by_user = (sys.argv[2]) print(PWrand(insert_by_user)) So, this is what I take.
Traceback (most recent call last): File "./passwordrandom.py", line 24, in <module> elif (type(sys.argv[2]) != int): IndexError: list index out of range Thank you all!
insert_by_user = int(sys.argv[1])and of course, if it is not the string representation of an int, like "b", be ready to catch that ValueError exception.len(sys.arg)which in your testing will return 2, and an index on the sequence likesys.argv[2]which will give you the #3 item. There's some good reasons for zero-based indexing but mostly it causes confusion. Also, in your question you should show how you are calling the python script with your args to make it clear that you test with 2 args.