【发布时间】:2014-01-26 18:50:20
【问题描述】:
我想编译 instance's attributes 以编程方式从外部 (.csv) 文件导入数据。到目前为止,我可以一次手动完成一个实例。使用此工作流程:
class RS: #the calss has the importer method and many attributes
...
#workflow starts here
a=RS() #I create the instance
a.importer('pathofthefile') #the importer method fills the attributes of the instance with the exeternal file
#ends here and restart...
b=RS()
b.importer('path...
我想以编程方式创建实例并用importer 或class 填充它们。如何在大量文件上迭代此过程?例如使用listdir从文件夹中导入所有文件?
我想这样来创建实例:
for i in 'abcd':
eval('%s=RS()' %(i))
但当然似乎不起作用..
【问题讨论】:
标签: python class metaprogramming