Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Saving information
#9
I see scope issues all over this. You have a function named password that has a variable password, and you have variables named password in your main code.

Also, you define a function inside an if statement. Is the function undefined if the criteria are not met? Bad idea.

The else in line 29 is connected to which if?

You define the order in the class User definition username followed by password. When you create a class instance in line 13 it is password, username.

In line 37 you define password as a print statement. That is why you get a function.

No idea where or why the import of User.

There is an extra parenthesis in line 44

This gets you a lot closer, but your passwords will all be just strings of stars....
class User:
    def __init__(self, username, password):
        self.username = username
        self.password = password

def translate(password):
    translation = ""
    for letter in password:
        if letter in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890":
            if letter.isupper():
                translation = translation + "*"
            else:
                translation = translation + "*"
        else:
            translation = translation + letter
    return translation

select = input("Enter login/register: ")
 
user1 = User('','')

if select == "login":
    username = input("Username: ")
    password = input("Password: ")
    user1 = User(username, password)
elif select == "register":
    username = input("Please make a username: ")
    print("Your password may contain any combination of uppercase and lowercase letters and numbers.")
    password = translate(input("Please make a password: "))
    user1 = User(username,password)

else:
    print("invalid selection.")
print(user1.username,user1.password) 
appendMe = user1.password
appendFile = open("passwordsFile.txt", "a")
appendFile.write(str(appendMe))
appendFile.close
Reply


Messages In This Thread
Saving information - by Justice_py - Nov-15-2019, 04:35 PM
RE: Saving information - by Larz60+ - Nov-15-2019, 05:06 PM
RE: Saving information - by jefsummers - Nov-15-2019, 05:37 PM
RE: Saving information - by Justice_py - Nov-16-2019, 01:34 AM
RE: Saving information - by jefsummers - Nov-17-2019, 02:35 AM
RE: Saving information - by Justice_py - Nov-26-2019, 02:08 AM
RE: Saving information - by buran - Nov-26-2019, 03:14 AM
RE: Saving information - by Justice_py - Nov-26-2019, 04:37 AM
RE: Saving information - by jefsummers - Nov-26-2019, 01:16 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020