2017-02-18 3 views
2

Я пытаюсь сохранить объект в таблице хранения azure с помощью python. Но я получил следующую ошибку.ТипError: insert_or_replace_entity() принимает не более 4 аргументов (5 данных)

self.table_service.insert_or_replace_entity('myDataTable', 'A100', keyVal, self.task) 
TypeError: insert_or_replace_entity() takes at most 4 arguments (5 given) 

У меня есть обеспечить 4 аргументы только в insert_or_replace_entity() функции, но компилятор рассмотреть пять, почему? Я не понимаю, пожалуйста, помогите мне.

Мой код здесь:

#!/usr/bin/env python 

import time 
import csv 
import sys 

from azure.storage.table import TableService, Entity 

class Azure: 

    table_service = '' 
    task = {} 

    PartitionKey = '' 
    RowKey = '' 
    RPI_ID = '' 
     PIC_ID = '' 
    Date = '' 
    Time = '' 
     Temp = '' 


    def openAccount(self): 
     self.table_service = TableService(account_name='<My account name>', account_key='<My key>') 

    def createTable(self): 
     self.table_service.create_table('myDataTable') 

    def setEntity(self, i): 
     task_i = Entity() 
       task_i.PartitionKey = 'A100' 
      task_i.RowKey = str(i) 
     print task_i   

     task_i.RPI_ID = 'A100' 
       task_i.PIC_ID = 'P100' 
       task_i.Date = time.strftime("%d-%m-%Y") 
       task_i.Time = time.strftime("%I:%M") 
       task_i.Temp = '22.05' 

       self.task = task_i; 

     def insertOrReplaceEntity(self, keyVal): 
     self.table_service.insert_or_replace_entity('myDataTable', 'A100', keyVal, self.task) 

data = Azure() 

data.openAccount() 
data.createTable() 

cnt = 0 

while (cnt < 10): 
    data.setEntity(cnt) 
     data.insertOrReplaceEntity(cnt) 
    cnt = cnt + 1 
    time.sleep(1) 

Спасибо заранее.

ответ

1

insert_or_replace_entity(table_name, entity, timeout=None) (https://azure.github.io/azure-storage-python/ref/azure.storage.table.tableservice.html#azure.storage.table.tableservice.TableService.insert_or_replace_entity) на самом деле имеет подпись:

def insert_or_replace_entity(self, table_name, entity, timeout=None): 

Так с self.table_service.insert_or_replace_entity('myDataTable', 'A100', keyVal, self.task) вы на самом деле делать что-то вроде insert_or_replace_entity(self, 'myDataTable', 'A100', keyVal, self.task), отсюда и пять аргументов.

+1

Отлично работает. Огромное спасибо. – rsp