I want to make two separate function one to connect to azure storage and create table using Python below is what I am trying to do

Question:

I am new to coding. I want to make two functions to be used one is to create connection to storage table and one is to create a table in storage.
Have created a function connecToStorage which will connect to storage

def connecToStorage(accname, acckey,connstr):
                table_service = TableService(account_name=accname,
                                             account_key=acckey)
                table_service = TableService(connection_string=connstr)
                return table_service

Now I want to access the table_service object to create a table in the storage I connected to. how to do that? I am trying below but its not correct.

def create_tabel(tablename):
            connecToStorage.create_table(tablename)
Asked By: Santosh sanwal

||

Answers:

I searched for this and found a solution that i can use constructor for doing this. i can create a constructor using

def __init__(self, accname, connstr):
    self.table_service = TableService(account_name=accname,account_key=acckey)

and after it i can create table like:

def create_tabel(tablename):
      slef.table_service.create_table(tablename)
Answered By: Santosh sanwal
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.