1

I'm trying to connect two separate codes into one program. I need to put one string from first to second part.

First:

import boto3

if __name__ == "__main__":

    bucket='BUCKET-NAME'
    collectionId='COLLECTION-ID'
    fileName='input.jpg'
    threshold = 70
    maxFaces=1

    client=boto3.client('rekognition')


    response=client.search_faces_by_image(CollectionId=collectionId,
                                Image={'S3Object':{'Bucket':bucket,'Name':fileName}},
                                FaceMatchThreshold=threshold,
                                MaxFaces=maxFaces)


    faceMatches=response['FaceMatches']
    for match in faceMatches:
            print (match['Face']['FaceId'])

Second:

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

dynamodb = boto3.resource('dynamodb')

table = dynamodb.Table('faces')

response = table.scan(
    FilterExpression=Attr('faceid').eq('FaceId')
)
items = response['Items']
print(items)

I need to put ID shown by print (match['Face']['FaceId']) from first code to FaceId in second code.

I tried to define a variable and put a value into it and then get it later but I could not do it correctly

4
  • Maybe, write the variable to a text file, and read it from the other code? P.S I have no idea how code on AWS is executed. If they are executed in parallel, then my next best guess would be to create an async call from the first script to the other. Commented Nov 24, 2018 at 18:03
  • Are these two separate programs, or simply separate sections of the same file? What is triggering each code block? I ask because the calling method could be used to pass information between the blocks. Commented Nov 25, 2018 at 0:13
  • @JohnRotenstein: This is two separate sections of the same file. Commented Nov 25, 2018 at 17:28
  • If they are both in the same file, how does the second code block get called? You should either pass information between functions, or use a global variable to store something you need to access from multiple portions of code. Commented Nov 25, 2018 at 17:34

1 Answer 1

2

Typically, you're write your first block of code as a library/module with a function that does some unit of work and returns the result. Then the second block of code would import the first and call the function.

# lib.py
def SomeFunction(inputs):
  output = doSomething(inputs)
  return output

# main.py
import lib
data = ...
result = lib.SomeFunction(data)
moreWork(result)

If you want two separate programs that run independently and share data, you want Inter-process communication. You can get processes to share information with each other via: a file/fifo in the filesystem; a network socket; shared memory; and STDIO (and probably more). However, IPC is definitely more work than synchronous library calls.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.