代码如下:
# -*- coding: utf-8 -*-
import sys
name0 = 'this is name0'
name1 = 'this is name1'
module = sys.modules[__name__]
for i in range(2):
attr_name = 'name{0}'.format(i)
attr = getattr(module, attr_name)
print('attr - {0} value is: {1}'.format(attr_name, attr))