table_dict = [] for table in targetTables: grants = spark.sql(f'show GRANT on {table}').collect() for grant in grants: table_dict.append(f"{json_dict['orgId']}|{''}|{table}|{grant['Principal']}|{grant['ActionType']}|{grant['ObjectType']}|{grant['ObjectKey']}") 请修改为打印targetTables数量和目前循环到第几个
时间: 2023-12-20 08:05:27 浏览: 59
打印table表格数据
5星 · 资源好评率100%
可以在循环前添加一个计数器变量,并在循环内部打印出来。修改后的代码如下:
```
table_dict = []
table_count = len(targetTables)
for i, table in enumerate(targetTables):
grants = spark.sql(f'show GRANT on {table}').collect()
for grant in grants:
table_dict.append(f"{json_dict['orgId']}|{''}|{table}|{grant['Principal']}|{grant['ActionType']}|{grant['ObjectType']}|{grant['ObjectKey']}")
print(f"Processed {i+1}/{table_count} tables")
```
这样在循环期间就会打印出当前处理的表的数量和总表数。
阅读全文