class PhoneInfoBinder:
def __init__(self):
self.phone_data = {}
def bind_phone_info(self, system, model, version):
"""绑定手机信息"""
if not all([system, model, version]):
raise ValueError("所有参数(系统、型号、版本)都必须提供")
self.phone_data = {
"system": system,
"model": model,
"version": version,
"binding_time": self._get_current_time()
}
return self.phone_data
def get_phone_info(self):
"""获取已绑定的手机信息"""
if not self.phone_data:
return "未绑定任何手机信息"
return self.phone_data
def _get_current_time(self):
"""获取当前时间"""
from datetime import datetime
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
示例使用
if name == "main":
binder = PhoneInfoBinder()
# 绑定手机信息
phone_info = binder.bind_phone_info(
system="Android",
model="Samsung Galaxy S23",
version="Android 13"
)
print("手机信息绑定成功:")
print(f"系统: {phone_info['system']}")
print(f"型号: {phone_info['model']}")
print(f"版本: {phone_info['version']}")
print(f"绑定时间: {phone_info['binding_time']}")
# 获取已绑定的信息
print("\n获取已绑定的手机信息:")
print(binder.get_phone_info())
