0

(sorry for my english)

Guys, my class in Python runs once

import csv, random class myPassword: azlower = "abcdefghijklmnopqrstuvwxyz" azupper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" vowel = "aeiouAEIOU" simbol = "!@#$%*" passw = random.sample(range(9), 2) passw = ''.join(map(str, passw)) passw += random.choice(simbol) passw += random.choice(azupper) passw += random.choice(vowel) passw += random.choice(azlower) passw += random.choice(simbol) passr = random.sample(range(9), 3) passw += ''.join(map(str, passr)) for i in range (0,2): print (myPassword.passw) 

This code runs the same password in every for. How to run the class again? Tkx!

3
  • 3
    don't use a class? Use a function... return passw in your function. Commented Apr 12, 2018 at 20:32
  • 1
    That code should not be in a class. Commented Apr 12, 2018 at 20:38
  • 1
    The code in the first indentation only runs once. This part is used to define the structure of a class so it should only run once. myPassword.passw is just a static class variable. You may want to def a method or just simply use a function. Commented Apr 12, 2018 at 20:39

1 Answer 1

3

Using a class here is not the thing to do. You want to use a method:

def myPassword(): azlower = "abcdefghijklmnopqrstuvwxyz" azupper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" vowel = "aeiouAEIOU" simbol = "!@#$%*" passw = random.sample(range(9), 2) passw = ''.join(map(str, passw)) passw += random.choice(simbol) passw += random.choice(azupper) passw += random.choice(vowel) passw += random.choice(azlower) passw += random.choice(simbol) passr = random.sample(range(9), 3) passw += ''.join(map(str, passr)) return passw for i in range (2): print (myPassword()) 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks!! Working as well

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.