ajaanbaahu
ajaanbaahu

Reputation: 344

How to get all columns in azure table using python?

I am trying to query an azure table using the following code:

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)

When i iterate I get the output for the partitionkey or if I do (i.RowKey) I can get those as well.

Is there a way to get all the keys or columns (may not be using the right word 'column') if I do not know what all the columns are for each row?

Upvotes: 0

Views: 1445

Answers (1)

Peter Pan
Peter Pan

Reputation: 24138

In python, we can use ‘dir()’ or '__dir__()' function to get all properties in an object. In your scenarios, we should query an entity firstly, then we can use ‘dir()’ function to list the columns of entity. Please refer to the code below:

A:

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, '__')]

Upvotes: 3

Related Questions