how to cycle in python?
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
add a comment |
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
1
Look intofor
andwhile
– roganjosh
Nov 14 '18 at 20:19
add a comment |
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
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
python python-2.7 cycle
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 intofor
andwhile
– roganjosh
Nov 14 '18 at 20:19
add a comment |
1
Look intofor
andwhile
– 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
add a comment |
2 Answers
2
active
oldest
votes
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))
add a comment |
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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))
add a comment |
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))
add a comment |
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))
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))
answered Nov 14 '18 at 20:19
Joran BeasleyJoran Beasley
73.4k680120
73.4k680120
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 14 '18 at 20:19
NathanNathan
1,276518
1,276518
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
Look into
for
andwhile
– roganjosh
Nov 14 '18 at 20:19