回答編集履歴

1

コードの追記です。

2021/01/30 06:19

投稿

退会済みユーザー
test CHANGED
@@ -1 +1,75 @@
1
- for文の外側でリストを定義すれば良いと思いますが、その実装の場合は問題ありますでしょうか。
1
+ 下記のようにfor文の外側でリストを定義すれば良いと思いますが、その実装の場合は問題ありますでしょうか。
2
+
3
+
4
+
5
+ ```python
6
+
7
+ import urllib.request
8
+
9
+ import urllib.parse
10
+
11
+ import json
12
+
13
+
14
+
15
+ from google.cloud import bigquery
16
+
17
+
18
+
19
+ def get_tags():
20
+
21
+ client = bigquery.Client()
22
+
23
+ tableName = ['clientA','clientB','test2']
24
+
25
+ tag_list = [] # 変更点
26
+
27
+ for table in tableName:
28
+
29
+ query = """SELECT column_name
30
+
31
+ FROM `test_project.test_table.INFORMATION_SCHEMA.COLUMNS`
32
+
33
+ where table_name = '{}' """.format(table)
34
+
35
+
36
+
37
+
38
+
39
+ job_config = bigquery.QueryJobConfig(
40
+
41
+ query_parameters=[
42
+
43
+ bigquery.ScalarQueryParameter("table", "STRING", table)
44
+
45
+ ]
46
+
47
+ )
48
+
49
+
50
+
51
+ query_job = client.query(query)
52
+
53
+ query_res = query_job.result()
54
+
55
+
56
+
57
+ # tag_list = []
58
+
59
+ for row in query_res:
60
+
61
+ tag_list.append(row[0])
62
+
63
+ print(tag_list)
64
+
65
+
66
+
67
+ # response = json.dumps(tag_list)
68
+
69
+ # return print(response)
70
+
71
+
72
+
73
+ get_tags()
74
+
75
+ ```