python-3.x - AttributeError: 'Scanner' 对象没有属性 '_Scanner__expiry'
问题描述
问题: - 类描述: 笔记本电脑:
qrcode:笔记本电脑到期唯一标识码:布尔值,表示笔记本电脑的分配到期状态。True - 分配已过期,False - 分配尚未过期
扫描器:
emp_laptop_dict:存储员工ID作为键和对应的笔记本电脑对象作为值的字典 scan(empid,laptop):接受需要扫描的员工ID和笔记本电脑。检查给定员工是否分配给给定笔记本电脑如果笔记本电脑分配尚未过期,则返回 true。Else return false Else return false 执行区分大小写的字符串比较。创建几个笔记本电脑类的对象,用它来初始化emp_laptop_dict并使用emp_laptop_dict创建一个Scanner类的对象。通过传递不同的 empid 和笔记本电脑在 Scanner 对象上调用 scan(empid, laptop) 并测试您的程序。
我想要 Scanner 类中的 self.__expiry 实例变量,但它向我显示了这个错误
""""
笔记本电脑类:def init (self,expiry,grcode): self.__grcode = grcode self.__expiry = expiry
def get_grcode(self):
return self.__grcode
def get_expiry(self):
print("hell")
return self.__expiry
#lex_auth_012752542731378688302
#开始在这里写你的代码
class Laptop:
def __init__(self,expiry,grcode):
self.__grcode = grcode
self.__expiry = expiry
def get_grcode(self):
return self.__grcode
def get_expiry(self):
print("hell")
return self.__expiry
#lex_auth_012752542731378688302
#Start writing you code here
class Laptop:
def __init__(self,expiry,grcode):
self.__grcode = grcode
self.__expiry = expiry
def get_grcode(self):
return self.__grcode
def get_expiry(self):
print("hell")
return self.__expiry
class Scanner(Laptop):
def __init__(self,emp_laptop_dict):
#self.__empid=empid
self.__emp_laptop_dict=emp_laptop_dict
super().__init__(False,"1233456789")
def scan(self,empid,laptop):
#x = Laptop.get_expiry(self)
print(self.__expiry)
if(empid in self.__emp_laptop_dict):
if(self.__expiry == False):
return True
else:
return False
obj=Laptop(False ,"GR777")
obj1=Scanner({'8632':['OOP_101_8'], '1682':['OOP_101_9'], '7555':['OOP_101_7']})
obj1.scan("123",obj)
class Scanner(Laptop):
def __init__(self,emp_laptop_dict):
#self.__empid=empid
self.__emp_laptop_dict=emp_laptop_dict
def scan(self,empid,laptop):
#x = Laptop.get_expiry(self)
super().__init__(self,empid)
if(empid in self.__emp_laptop_dict):
if( self.__expiry == False):
return True
else:
return False
obj=Laptop(False ,"GR777")
obj1=Scanner({'8632':['OOP_101_8'], '1682':['OOP_101_9'], '7555':['OOP_101_7']})
obj1.scan("123",obj)
解决方案
推荐阅读
- sql - SAP HANA 随机数生成器
- python - WxPython 选择字段仅在 Mac 上不可见
- python - 如何检索 Spotify 上的所有专辑对象?
- python - Nuitka TypeError 类型“生成器”的编译器错误对象没有 len()
- canvas - 在paperjs中以形状显示边界矩形
- angular - Angular 6:从后端服务器获取文件对象后下载文件
- sql - 使用 UNPIVOT 将代码从 sql 重写为 redshift
- c# - 遍历单个实体到 HTML 无序列表
- google-cloud-endpoints-v2 - 端点框架客户端库版本
- regex - matching string using regular expression