Kaworu
Active Coder
Hi.
I created a simple script to generate safe passwords. When I tried to rewrite it as OO code, I suddenly have an error.
My code is this:
The error is in the first line after
Its kinda hard to say what's wrong. Indexation? Seems alright, Something else?
I would appreciate any help ;-)
I created a simple script to generate safe passwords. When I tried to rewrite it as OO code, I suddenly have an error.
My code is this:
Python:
import string
import random
class RandomPassword:
def __init__(self):
self.lc = string.ascii_lowercase
self.uc = string.ascii_uppercase
self.nr = string.digits
self.special = string.punctuation
def random_lowercase(self):
random_lc = random.choice(self.lc)
return random_lc
def random_uppercase(self):
random_uc = random.choice(self.uc)
return random_uc
def random_nr(self):
random_nr = random.choice(self.nr)
return random_nr
def random_special(self):
random_special = random.choice(self.special)
return random_special
def generate_safe_password(self, size = 20):
random_list = list()
while size != 0:
random_step = random.randint(1,4)
if random_step == 1:
x = random_lowercase()
random_list.append(x)
elif random_step == 2:
x = random_uppercase()
random_list.append(x)
elif random_step == 3:
x = random_nr()
random_list.append(x)
elif random_step == 4:
x = random_special()
random_list.append(x)
size = size - 1
return random_list
def string_from_list(self, my_list):
my_string = "".join(my_list)
return my_string
def final_result(self):
a = RandomPassword.generate_safe_password()
b = RandomPassword.string_from_list(a)
return b
############################
# PROGRAM
############################
if __name__ == "__main__":
pass = RandomPassword()
a = pass.final_result()
print("Your new safe password is: ", a)
The error is in the first line after
if __name__ == "__main__".
Exactly in the place when there is an equality sign. SyntaxError: invalid syntax
Its kinda hard to say what's wrong. Indexation? Seems alright, Something else?
I would appreciate any help ;-)