当前位置:网站首页>getattr() function analysis
getattr() function analysis
2022-08-02 03:33:00 【woshicaiji12138】
1Brief
getattr(object, name [, default ])object is an object, and name must be a string; if the value of name is an attribute of the object object, the function outputs the attribute of the object, which is equivalent to object.name.
class Student:def __init__(self,name):self.name = names = Stduent('zhangsan')getattr(s,'name')The output result is zhangsan.
If the value of name is not an attribute of the object object, if the default value is set at this time, the function will output the default value; otherwise, an error will be reported.
class Student:def __init__(self,name):self.name = namegetattr(s,'age',1) #The attribute age does not exist, but a default value is provided, return the default value#will output 12 Application
In general, the above functions are multi-purposed with a certain attribute of object. However, for an object with multiple attributes, the getattr() function can be used when the type of the attribute needs to be called at present.When you can realize which property you need, you can type the name to get the corresponding value.
边栏推荐
- AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘/yolov5-5.0/models/commo
- 线性代数学习笔记3-1:矩阵与线性变换、常见矩阵(逆矩阵、伴随矩阵、正交矩阵等)
- oracle内连接和外连接
- Redis笔记进阶篇:万字长文-整理Redis,各种知识点,建议收藏
- ImportError: libGL.so.1: cannot open shared object file: No such file or directory
- Day34 LeetCode
- 多个el-select下拉框无法选中相同内容
- [Basic Tutorial of Remote Control Development 1] Crazy Shell Open Source Formation Drone-GPIO (Remote Control Indicator Light Control)
- [Remote Control Development Basic Tutorial 3] Crazy Shell Open Source Formation UAV-ADC (Joystick Control)
- CV-Model【4】:MobileNet v3
猜你喜欢

磷脂-聚乙二醇-巯基,DSPE-PEG-Thiol,DSPE-PEG-SH,MW:5000

MySQL8.0安装教程,在Linux环境安装MySQL8.0教程,最新教程 超详细

黑马案例--实现 clock 时钟的web服务器

磷脂-聚乙二醇-靶向新生血管靶向肽APRPG,DSPE-PEG-APRPG

【深度学习】从LeNet-5识别手写数字入门深度学习

MongoDB文档存储
[email protected]在static属性上的使用"/>@Autowired详解[email protected]在static属性上的使用

亚马逊卖家怎么提升转化率

周日数据库作业

subprocess.CalledProcessError: Command 'pip install 'thop'' returned non-zero exit status 1.
随机推荐
基本运算符
Good Key, Bad Key (thinking, temporary exchange, classic method)
Redis笔记进阶篇:万字长文-整理Redis,各种知识点,建议收藏
动态代理工具类
mysql创建表
HCIP Day 11_MPLS Experiment
@Autowired详解[email protected]在static属性上的使用
科研试剂DMPE-PEG-Mal 二肉豆蔻酰磷脂酰乙醇胺-聚乙二醇-马来酰亚胺
「PHP基础知识」PHP中对象的使用
Using WebShell to get Shell Skills
Freeswitch操作基本配置
LeetCode:1374. 生成每种字符都是奇数个的字符串【签到题】
Error: with open(txt_path,'r') as f: FileNotFoundError: [Errno 2] No such file or directory:
Redis安装,基本命令,持久化方式,集群
磷脂-聚乙二醇-醛基 DSPE-PEG-Aldehyde DSPE-PEG-CHO MW:5000
化学试剂磷脂-聚乙二醇-羟基,DSPE-PEG-OH,DSPE-PEG-Hydroxyl,MW:5000
APK的安装过程分析 PMS包管理器
Daily practice------There are n integers, so that the previous numbers are moved back m positions in order, and the last m numbers become the first m numbers
DSPE-PEG-DBCO 磷脂-聚乙二醇-二苯并环辛炔 一种线性杂双官能聚乙二醇化试剂
亚马逊卖家怎么提升转化率