2017-09-03 3 views
-1
source_table = raw_input("Enter the table name : ") 
PK = raw_input("Enter the primary key : ") 
PriKeyData = raw_input("Enter the data type for Primary key int-number, str-string :") 
with open('PriSortKeys.csv', 'rb') as csvfile: 
    csvreader = csv.reader(csvfile, delimiter='\t', quotechar='|') 
    for row in csvreader: 
     if PriKeyData == "int": 
       prikeyvalue = int(row[0]) 
      else: 
       prikeyvalue = str(row[0]) 
      logger.info("Checking for Key :" + str(prikeyvalue)) 
      ## Fetching data from table based on primarykey 
      sourcetable_data= source_table.query(KeyConditionExpression=Key(PK).eq(prikeyvalue)) 

파이썬에는 속성 '쿼리'가 없습니다 :내가 AttributeError를 얻고있다 : 'STR'개체가 나는 기본 키 및 사용자 입력으로 값을 시도하고에 조회하려고하지만 난 다음 오류가 받고 있어요

'str' object has no attribute 'query'

+1

'source_table = raw_input()'... 항상'str'입니다 ... 어떤 객체가'query()'를 실행하려고합니까? –

답변

0
source_table = raw_input("Enter the table name : ") 

테이블의 이름 만이 아닌 테이블 자체를 반환합니다. 표를 먼저 열고 표에 query()을 열어야합니다.

0
source_table = raw_input("Enter the table name : ") 
PK = raw_input("Enter the primary key : ") 
PriKeyData = raw_input("Enter the data type for Primary key int-number, str-string :") 
dynamodb = boto3.resource('dynamodb') 
s_table = dynamodb.Table(source_table.format(**locals())) 
with open('PriSortKeys.csv', 'rb') as csvfile: 
    csvreader = csv.reader(csvfile, delimiter='\t', quotechar='|') 
    for row in csvreader: 
     if PriKeyData == "int": 
       prikeyvalue = int(row[0]) 
      else: 
       prikeyvalue = str(row[0]) 
     logger.info("Checking for Key :" + str(prikeyvalue)) 
     ## Fetching data from table based on primarykey 
     s_table = source_table.query(KeyConditionExpression=Key(PK).eq(prikeyvalue))