I have the following code:
PROJECT_ID = 'test'
BQ_TABLE_NAME_CATEGORIES = 'categories'
BQ_TABLE_NAME_MANUFACTURERS = 'manufacturers'
list = [BQ_TABLE_NAME_CATEGORIES, BQ_TABLE_NAME_MANUFACTURERS]
table_categories = PROJECT_ID + '.' + BQ_TABLE_NAME_CATEGORIES
table_manufacturers = PROJECT_ID + '.' + BQ_TABLE_NAME_MANUFACTURERS
for table in list:
....
source_objects=['table_{0}'.format(table)] #reference to the correct var
....
然而,这将字符串放在source_objects
中。我希望它引用变量(无论变量中保存了什么)的内容。
也就是说,我实际上想要的是以下等效内容:
当table = BQ_TABLE_NAME_CATEGORIES
时
source_objects = [ table_categories ]
当
table = BQ_TABLE_NAME_MANUFACTURERS
时source_objects = [ table_manufacturers ]
table_categories
的内容放进一个列表里吗?还是只是想引用它的字符串值? - saudlist
对象是不好的编程实践。 - saud