0

I have some program like below

import boto3
from boto3.dynamodb.conditions import Key, Attr
import sys

dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('g_data')
#var1 = sys.argv[1]
data = table.scan(
       FilterExpression=Attr('customer_id').eq(1)) 

print(data['Items'][0]['customer_id'])
print(data['Items'][0]['tools_type']['antivirus'])

it works when hard code customer id at below line

FilterExpression=Attr('customer_id').eq(1)) 

But I want to pass this customer id via runtime sys.argv if i mention like this

FilterExpression=Attr('customer_id').eq(var1))

I am getting error like below:

Traceback (most recent call last):
  File "C:\csv\abdynmodb\abdynamodb1.py", line 15, in <module>
    print(data['Items'][0]['tools_type']['antivirus'])
IndexError: list index out of range
asp
  • 777
  • 3
  • 14
  • 33
  • 1
    Argv is a list of strings, in your first example you pass an integer to `eq`, try this: `var1=int(sys.argv[1])`. – redxef Jul 15 '20 at 11:18
  • 1
    Does this answer your question? [How do I access command line arguments in Python?](https://stackoverflow.com/questions/4033723/how-do-i-access-command-line-arguments-in-python) – bigbounty Jul 15 '20 at 11:18
  • @redxef thats the right answer..it works now thank you – asp Jul 15 '20 at 11:21

0 Answers0