type元类创建类的方法
2024-09-06 07:43:29
一、代码
class_name='car'
dict_name={}
bases=(object,) class_body='''
def __init__(self,name):
self.name=name def driver(self):
print('%s汽车开走了',self.name) '''
#将类体内容放入名称空间
exec(class_body,{},dict_name)
print(dict_name)
car=type(class_name,bases,dict_name)
print(car)
最新文章
- Xamarin+Prism开发详解一:PCL跨平台类库与Profile的关系
- Linux 下如何安装软件
- sql server存储过程编程
- ";稀奇古怪的";delete this
- VS2010运行正常的控制台程序在VS2015中出现乱码的解决方法
- Linux netlink机制
- 转载linq to sql 的详解
- 使用EPEL和REMI第三方yum源
- HTML本地存储,localstorg的应用实例
- 【论文:麦克风阵列增强】Speech Enhancement Based on the General Transfer Function GSC and Postfiltering
- SpringMVC handleMapping 处理器映射器 属性清单
- C语言的第 次作业总结
- javascript 内存管理
- (转)Vue种key的作用
- python------面向对象进阶反射详解(重点)
- webservice跨域问题
- Unity之Application.runInBackground = true
- springcloud使用Hystrix实现微服务的容错处理
- sublime sftp注册码
- git merge和git rebase的区别(转)