python静态变量赋值
使用dir获取所有属性(包含静态),使用Exce赋值
- import json
- class Article(object):
- title = None
- link = None
- abstract = None
- keywords = []
- content = None
- pub_date = None
- xxx = '99999'
- def __init__(self):
- for p in dir(self):
- if not p[0:2] =='__':
- exec('self.'+p+' = Article.'+p)
- pass
- a = Article()
- print(a.__dict__)
- output: {'abstract': None, 'content': None, 'keywords': [], 'link': None, 'pub_date': None, 'title': None, 'xxx': '99999'}