I am a self taught python developer and I trying to write clean code as mush as possible. Since I do not have any environment that can give me constructive criticism, I would like to hear your opinions, so, here it is a python password generator, I know that something like that can be made with single function, but this is just "project as a placeholder" if that make sense..
So does this consider "good practice"? -andAnd what can I do better?
import sys
import yaml
import string
import random
from typing import Union
class GeneratePassword:
"""
Object that generate password. Password size is taken from yaml config file,
it can be week(64), medium(128) or strong(256). Need to pass that as
string argument to cls.generate_password function.
"""
@classmethod
def generate_password(cls, password_level: str):
conf = cls.check_config_file()
if conf is not None:
security_level = conf.get(password_level)
new_password = cls.generate_gibberish(security_level)
return new_password
@staticmethod
def check_config_file() -> Union[dict, None]:
try:
with open('./config/security_level_conf.yml') as pass_conf:
current_data = yaml.safe_load(pass_conf)
return current_data
except FileNotFoundError:
sys.exit('Config file not found.')
@staticmethod
def generate_gibberish(security_level: int) -> str:
choices = string.punctuation + string.ascii_letters + string.digits
password = []
for i in range(security_level):
character = random.choice(choices)
password.append(character)
return "".join(password)
if __name__ == '__main__':
print(GeneratePassword.generate_password('week'))