我尝试使用以下代码查询 azure 表:
from azure.storage import TableService,Entity
ts=TableService(account_name='user',account_key='key')
tasks=ts.query_entities('Events', filter=None, select=None, top=10,next_partition_key=None, next_row_key=None)
for i in tasks:
print(i.PartitionKey)
当我迭代时,我会得到分区键的输出,或者如果我这样做(i.RowKey),我也可以获得这些输出。
如果我不知道每行的所有列是什么,有没有办法获取所有键或列(可能没有使用正确的单词“列”)?
最佳答案
在Python中,我们可以使用“dir()”或“__dir__()”函数来获取对象中的所有属性。在您的场景中,我们应该首先查询一个实体,然后我们可以使用“dir()”函数列出实体的列。请引用以下代码:
答:
from azure.storage import TableService,Entity
ts=TableService(account_name='user',account_key='key')
tasks=ts.query_entities('Events', filter=None, select=None, top=10,next_partition_key=None, next_row_key=None)
task = tasks[0]
columns = [ column for column in task.__dir__() if not str.startwith(column, '__')]
B:
from azure.storage import TableService,Entity
import struct
ts=TableService(account_name='user',account_key='key')
tasks=ts.query_entities('Events', filter=None, select=None, top=10,next_partition_key=None, next_row_key=None)
task = tasks[0]
columns = [ column for column in dir(task) if not str.startwith(column, '__')]
关于python - 如何使用python获取azure表中的所有列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32061933/