Python Forum
[PyQt] [Solved]Help Passing Variables
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] [Solved]Help Passing Variables
#4
You can convert a str to an int.
userInputPassword = int(self.PasswordInput.text())
But now you have to worry about the user typing something that cannot be converted to an int, like "cat" or even "1.0". To be safe you should wrap the dangerous conversion inside a try except.
try:
    userInputPassword = self.PasswordInput.text()
except ValueError:
    #Do something here to handle the error
But this adds a lot of complication to the code. And for what? Why do you want to convert the str to an int? Are you going to do math with the passwords? Does the numerical value of the password have some significance? Why not make the passwords all str?
    admins = {
        "Admin" : "1234",
        "Joe" : "0000",
        "Randall" : "1111"
    }
If there is no reason for it t be a number, and it is more convenient for it to be a str, let it be a str.
Reply


Messages In This Thread
[Solved]Help Passing Variables - by Extra - May-12-2022, 08:04 PM
RE: Help Passing Variables - by deanhystad - May-12-2022, 08:29 PM
RE: Help Passing Variables - by Extra - May-12-2022, 08:39 PM
RE: Help Passing Variables - by deanhystad - May-12-2022, 09:02 PM
RE: Help Passing Variables - by Extra - May-12-2022, 11:04 PM

Forum Jump:

User Panel Messages

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