为什么我一直允许访问Access: 在python3中
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为什么我一直允许访问Access: 在python3中相关的知识,希望对你有一定的参考价值。
它不断打印“Access allowed:<property object at 0x0000024D87D9CD68>in python
”而不是打印"Enter the password:
“。我不知道问题是什么。请知道我错过了什么部分让我回到正轨。
class BankAccount:
def __init__ (self, firstname, lastname, money):
self.firstname = firstname
self.lastname = lastname
self.money = money
self.fullname = self.firstname + " " + self.lastname
self._allowed_access = False
@property
def username(self):
return '--> Fullname: {} || Money: {}'.format(self.fullname, self.money)
@property
def allowed_access(self):
return self._allowed_access
@allowed_access.setter
def allowed_access(self, value):
if value:
password = input("Enter the password: ")
if password == "Empress":
self._allowed_access = value
else:
raise ValueError("Warning, Intruder Alert")
user_1 = BankAccount("Empress", "Obazee", 0)
print(user_1.username)
print("Access allowed: " + str(BankAccount.allowed_access))
BankAccount.allowed_access = True
print("Access allowed: " + str(BankAccount.allowed_access))
user_1.money = 10000
print(user_1.username)
答案
class BankAccount:
def __init__ (self, firstname, lastname, money):
self.firstname = firstname
self.lastname = lastname
self.money = money
self.fullname = self.firstname + " " + self.lastname
self._allowed_access = False
@property
def username(self):
return '--> Fullname: {} || Money: {}'.format(self.fullname, self.money)
@property
def allowed_access(self):
return self._allowed_access
@allowed_access.setter
def allowed_access(self, value):
if value:
password = input("Enter the password: ")
if password == "Empress":
self._allowed_access = value
else:
raise ValueError("Warning, Intruder Alert")
user_1 = BankAccount("Empress", "Obazee", 0)
print(user_1.username)
print("Access allowed: " + str(user_1.allowed_access))
user_1.allowed_access = True
print("Access allowed: " + str(user_1.allowed_access))
user_1.money = 10000
print(user_1.username)
以上是关于为什么我一直允许访问Access: 在python3中的主要内容,如果未能解决你的问题,请参考以下文章
Python 中的链接 API 错误 - “Empty oauth2 access token”即使给出了访问令牌