I am making a password generator that turns the generated password into an md5 hash, but it will not allow me to import a function from one file to another.
Here is my code.
password.py
import random
import string
def main():
y = int(input("Enter desired length for password: "))
def random_char(y):
return ''.join(random.choice(string.ascii_letters + string.digits + string.punctuation) for x in range(y))
genpass = random_char(y)
print(genpass)
def getGenpass():
return genpass
main()
hash.py
import hashlib
import password
from password import getGenpass
mystring = password.getGenpass()
def main():
hash_object = hashlib.md5(mystring.encode())
print("Here is your md5 hash: " + hash_object.hexdigest())
main()
If I remove the imports from password.py the script does work.
disclaimer. I am new to python.