Using a variable in the later part of the program (python)












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










share|improve this question























  • 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.

    – MaJoR
    Nov 24 '18 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.

    – John Rotenstein
    Nov 25 '18 at 0:13











  • @JohnRotenstein: This is two separate sections of the same file.

    – xfilokolo
    Nov 25 '18 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.

    – John Rotenstein
    Nov 25 '18 at 17:34
















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










share|improve this question























  • 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.

    – MaJoR
    Nov 24 '18 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.

    – John Rotenstein
    Nov 25 '18 at 0:13











  • @JohnRotenstein: This is two separate sections of the same file.

    – xfilokolo
    Nov 25 '18 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.

    – John Rotenstein
    Nov 25 '18 at 17:34














1












1








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










share|improve this question














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







python amazon-web-services






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 17:45









xfilokoloxfilokolo

223




223













  • 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.

    – MaJoR
    Nov 24 '18 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.

    – John Rotenstein
    Nov 25 '18 at 0:13











  • @JohnRotenstein: This is two separate sections of the same file.

    – xfilokolo
    Nov 25 '18 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.

    – John Rotenstein
    Nov 25 '18 at 17:34



















  • 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.

    – MaJoR
    Nov 24 '18 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.

    – John Rotenstein
    Nov 25 '18 at 0:13











  • @JohnRotenstein: This is two separate sections of the same file.

    – xfilokolo
    Nov 25 '18 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.

    – John Rotenstein
    Nov 25 '18 at 17:34

















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.

– MaJoR
Nov 24 '18 at 18:03





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.

– MaJoR
Nov 24 '18 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.

– John Rotenstein
Nov 25 '18 at 0:13





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.

– John Rotenstein
Nov 25 '18 at 0:13













@JohnRotenstein: This is two separate sections of the same file.

– xfilokolo
Nov 25 '18 at 17:28





@JohnRotenstein: This is two separate sections of the same file.

– xfilokolo
Nov 25 '18 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.

– John Rotenstein
Nov 25 '18 at 17:34





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.

– John Rotenstein
Nov 25 '18 at 17:34












1 Answer
1






active

oldest

votes


















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.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460840%2fusing-a-variable-in-the-later-part-of-the-program-python%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    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.






    share|improve this answer




























      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.






      share|improve this answer


























        2












        2








        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 24 '18 at 18:13









        IsaacIsaac

        311




        311






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460840%2fusing-a-variable-in-the-later-part-of-the-program-python%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)