我想制作两个单独的功能,一个连接到 azure 存储并使用 python 创建 table 下面是我正在尝试做的

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

我是编码新手。我想使用两个功能,一个是创建与存储 table 的连接,一个是在存储中创建一个 table。 已创建一个函数 connecToStorage 将连接到存储

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

现在我想访问 table_service 对象以在我连接的存储中创建一个 table。怎么做?我在下面尝试,但它不正确。

def create_tabel(tablename):
            connecToStorage.create_table(tablename)

我搜索了这个并找到了一个解决方案,我可以使用构造函数来执行此操作。我可以使用

创建构造函数
def __init__(self, accname, connstr):
    self.table_service = TableService(account_name=accname,account_key=acckey)

然后我可以创建 table 像:

def create_tabel(tablename):
      slef.table_service.create_table(tablename)