attribute error when using the write function in python

Viewed 19
# PassGen ~ Password Generator
# by Adulmalik Abougarboa

# This code is owned by the person listed above

# Allows user to choose length of the password
class Scale():
    def s(self):
        if scale == 5:
            i = secrets.token_hex(3)
        elif scale == 6:
            i = secrets.token_hex(3.5)
        elif scale == 7:
            i = secrets.token_hex(4)
        elif scale == 8:
            i = secrets.token_hex(4.5)
        elif scale == 9:
            i = secrets.token_hex(5)
        elif scale == 10:
            i = secrets.token_hex(5.5)

# Handles the code for the generator
class Pass():
    def password(self):
        display = Text(window,height=1,width=32) # displays text
        results = secrets.token_hex(v.get())
        display.insert('1.0', results) # inserts the pasword generator into the text
        display.place(x=80,y=153) # displays the ext in a specific place
        display.config(state='disabled') # prevents user from editing password
        return results  
button = False
button = Button(window, text = 'Generate Password', command = Pass).place(x=350,y=150) # button for user to click and generate password.
s = Pass()

# Functions adds password generated in a txt file
n = button = True
def save():
    for l in range(n):
        with open('Pass.txt', 'a+') as f:
            f.write('\nPassword Generated:')
            f.write(Pass().password().r)
            f.write('\n')
        

# if user presses generate password then activate function save.
if button == True:
    save()
window.mainloop() # displays window infinitely

When running my code I get an error at the line "f.write(Pass().password().r)" what can I do to fix this error, I'm trying to save the results in a txt file but have been unsuccessful. This is not the entirety of the code but this should be enough I think.

EDIT:

line 64, in save
    f.write(Pass().password().r)
AttributeError: 'str' object has no attribute 'results'
0 Answers
Related