pythonpython-2.7control-flowpassword-generator

Python 2.7 Control Flow


I'm currently have a little problem: I'm making a "command" for my bot, a little password generator, currently, I already have the command itself, it'll go like this

if Command.lower() == '!pwgen' #First message, the user calls the command
length = Argument[0] #The length he wants, Argument[0] == the length
import os, random, string 
length = 13
chars = string.ascii_letters + string.digits + '!@#$%^&*()'
random.seed = (os.urandom(1024))
password = ''.join(random.choice(chars) for i in range(length))
messages.Main(password,xSock,BotID)

There's my problem, I wanna make sure that, if the argument is empty, I want the password generator to use a default digit, e.g. 12 so the length will be 12 if there's no length given by the user. Thanks.


Solution

  • Based on what you have, try:

    length = Argument[0] if len(Argument)>0 and Argument[0] is not None else 12