how to cycle in python?










-2















I have the code to retrieve the parameters from the photo. I would need to put it in the loop so it would load all of my photos from the folder and write them down in Python`enter code here



import requests

BASE_URL = 'https://westeurope.api.cognitive.microsoft.com/face/v1.0/detect'
headers =
'Ocp-Apim-Subscription-Key': 'd7264e9252674c9292b0d8b295cf3251',
'Content-Type': 'application/octet-stream'

parameters =
'returnFaceId': 'true',
'returnFaceLandmarks': 'false',
'returnFaceAttributes': 'age,gender,emotion'


img_path = 'C:\Users\Pifko\Desktop\bakalarka\subject13session2_Moment5up.jpg'
img_data = open(img_path, 'rb').read()

def post_image(img_data):
response = requests.post(BASE_URL, params=parameters,
headers=headers, data=img_data)
try:
return response.json()
except:
return None
print(post_image(img_data))









share|improve this question



















  • 1





    Look into for and while

    – roganjosh
    Nov 14 '18 at 20:19















-2















I have the code to retrieve the parameters from the photo. I would need to put it in the loop so it would load all of my photos from the folder and write them down in Python`enter code here



import requests

BASE_URL = 'https://westeurope.api.cognitive.microsoft.com/face/v1.0/detect'
headers =
'Ocp-Apim-Subscription-Key': 'd7264e9252674c9292b0d8b295cf3251',
'Content-Type': 'application/octet-stream'

parameters =
'returnFaceId': 'true',
'returnFaceLandmarks': 'false',
'returnFaceAttributes': 'age,gender,emotion'


img_path = 'C:\Users\Pifko\Desktop\bakalarka\subject13session2_Moment5up.jpg'
img_data = open(img_path, 'rb').read()

def post_image(img_data):
response = requests.post(BASE_URL, params=parameters,
headers=headers, data=img_data)
try:
return response.json()
except:
return None
print(post_image(img_data))









share|improve this question



















  • 1





    Look into for and while

    – roganjosh
    Nov 14 '18 at 20:19













-2












-2








-2








I have the code to retrieve the parameters from the photo. I would need to put it in the loop so it would load all of my photos from the folder and write them down in Python`enter code here



import requests

BASE_URL = 'https://westeurope.api.cognitive.microsoft.com/face/v1.0/detect'
headers =
'Ocp-Apim-Subscription-Key': 'd7264e9252674c9292b0d8b295cf3251',
'Content-Type': 'application/octet-stream'

parameters =
'returnFaceId': 'true',
'returnFaceLandmarks': 'false',
'returnFaceAttributes': 'age,gender,emotion'


img_path = 'C:\Users\Pifko\Desktop\bakalarka\subject13session2_Moment5up.jpg'
img_data = open(img_path, 'rb').read()

def post_image(img_data):
response = requests.post(BASE_URL, params=parameters,
headers=headers, data=img_data)
try:
return response.json()
except:
return None
print(post_image(img_data))









share|improve this question
















I have the code to retrieve the parameters from the photo. I would need to put it in the loop so it would load all of my photos from the folder and write them down in Python`enter code here



import requests

BASE_URL = 'https://westeurope.api.cognitive.microsoft.com/face/v1.0/detect'
headers =
'Ocp-Apim-Subscription-Key': 'd7264e9252674c9292b0d8b295cf3251',
'Content-Type': 'application/octet-stream'

parameters =
'returnFaceId': 'true',
'returnFaceLandmarks': 'false',
'returnFaceAttributes': 'age,gender,emotion'


img_path = 'C:\Users\Pifko\Desktop\bakalarka\subject13session2_Moment5up.jpg'
img_data = open(img_path, 'rb').read()

def post_image(img_data):
response = requests.post(BASE_URL, params=parameters,
headers=headers, data=img_data)
try:
return response.json()
except:
return None
print(post_image(img_data))






python python-2.7 cycle






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 21:04









Jérôme Teisseire

1,0361919




1,0361919










asked Nov 14 '18 at 20:15









Ľubo Pifko RusnákĽubo Pifko Rusnák

13




13







  • 1





    Look into for and while

    – roganjosh
    Nov 14 '18 at 20:19












  • 1





    Look into for and while

    – roganjosh
    Nov 14 '18 at 20:19







1




1





Look into for and while

– roganjosh
Nov 14 '18 at 20:19





Look into for and while

– roganjosh
Nov 14 '18 at 20:19












2 Answers
2






active

oldest

votes


















0














I guess you want os.listdir



for fname in os.listdir(basepath):
if fname[-3:] in ["jpg","gif","png"]:
print("this is an image:",os.path.join(basepath,name))





share|improve this answer






























    0














    you can get a list of all your files with a '.jpg' extension using:



    import glob, os
    os.chdir("/mydir")
    for file in glob.glob("*.jpg"):
    print(file)


    You can put your code in a function and then call it for every file instead of the print statement.






    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%2f53308099%2fhow-to-cycle-in-python%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      I guess you want os.listdir



      for fname in os.listdir(basepath):
      if fname[-3:] in ["jpg","gif","png"]:
      print("this is an image:",os.path.join(basepath,name))





      share|improve this answer



























        0














        I guess you want os.listdir



        for fname in os.listdir(basepath):
        if fname[-3:] in ["jpg","gif","png"]:
        print("this is an image:",os.path.join(basepath,name))





        share|improve this answer

























          0












          0








          0







          I guess you want os.listdir



          for fname in os.listdir(basepath):
          if fname[-3:] in ["jpg","gif","png"]:
          print("this is an image:",os.path.join(basepath,name))





          share|improve this answer













          I guess you want os.listdir



          for fname in os.listdir(basepath):
          if fname[-3:] in ["jpg","gif","png"]:
          print("this is an image:",os.path.join(basepath,name))






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 20:19









          Joran BeasleyJoran Beasley

          73.4k680120




          73.4k680120























              0














              you can get a list of all your files with a '.jpg' extension using:



              import glob, os
              os.chdir("/mydir")
              for file in glob.glob("*.jpg"):
              print(file)


              You can put your code in a function and then call it for every file instead of the print statement.






              share|improve this answer



























                0














                you can get a list of all your files with a '.jpg' extension using:



                import glob, os
                os.chdir("/mydir")
                for file in glob.glob("*.jpg"):
                print(file)


                You can put your code in a function and then call it for every file instead of the print statement.






                share|improve this answer

























                  0












                  0








                  0







                  you can get a list of all your files with a '.jpg' extension using:



                  import glob, os
                  os.chdir("/mydir")
                  for file in glob.glob("*.jpg"):
                  print(file)


                  You can put your code in a function and then call it for every file instead of the print statement.






                  share|improve this answer













                  you can get a list of all your files with a '.jpg' extension using:



                  import glob, os
                  os.chdir("/mydir")
                  for file in glob.glob("*.jpg"):
                  print(file)


                  You can put your code in a function and then call it for every file instead of the print statement.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 14 '18 at 20:19









                  NathanNathan

                  1,276518




                  1,276518



























                      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%2f53308099%2fhow-to-cycle-in-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







                      這個網誌中的熱門文章

                      How to read a connectionString WITH PROVIDER in .NET Core?

                      Node.js Script on GitHub Pages or Amazon S3

                      Museum of Modern and Contemporary Art of Trento and Rovereto