I'm sorry if it's already been passed.
Q: Could you tell me how to view the results of IDLE execution?
Environment: python 2.7.10 (Mac OS high Sierra 10.13.2)
What you want to do:
I want to run the following source code from IDLE to see the output
#!/usr/bin/env python
# coding —utf-8
import urllib.request
from xml.etree.ElementTree import ElementTree
defmain(url):
xmlfile=urllib.request.urlopen(url)
tree=ElementTree(file=xmlfile)
root=tree.getroot()
for node in root.getchildren():
if node.tag=="{http://webservices.amazon.com/AWSECommerceService/2005-10-05}Items":
for subnode in node.getchildren():
if subnode.tag=="{http://webservices.amazon.com/AWSECommerceService/2005-10-05}TotalResults":
print(subnode.text)
elif subnode.tag=="{http://webservices.amazon.com/AWSECommerceService/2005-10-05}Item":
for item in subnode:
if item.tag=="{http://webservices.amazon.com/AWSECommerceService/2005-10-05} ASIN":
print(item.text)
if__name__=="__main__":
amazon_api_url="http://ecs.amazonaws.jp/onca/xml?Service=AWSECommerceService&Operation=ItemSearch&"
AWSAcessKeyId="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Keywords="Python"
url=amazon_api_url+"AWSAccessKeyId="+AWSAccessKeyId+"&SearchIndex=Books&Keywords="+Keywords
main(url)
What you did:
①Enter IDLE at Terminal
IDSelect to open the file to start IDLE
③Select amazon.py (source code above)
(Access Key ID is hidden)
RSelect Run→Runmodule
If you do the above, after IDLE says Restart, you leave with no results.
It's coming.
"I am referring to Sho Young's ""Learning Python Introductory Class in 10 Days"" with the expected results and
"
It's different.
I think it's some kind of elementary misconfiguration, but if there's someone who's into it,
Please let me know.
It's a program that only appears when the if statement meets the conditions (print statement is not executed), so you don't know what's going on.
If you print the data to be conditioned before the if statement, you can guess where the problem is.For example, try rewriting the main as shown in the example below.
defmain(url):
xmlfile=urllib.request.urlopen(url)
tree=ElementTree(file=xmlfile)
root=tree.getroot()
for node in root.getchildren():
print node
if node.tag=="{http://webservices.amazon.com/AWSECommerceService/2005-10-05}Items":
for subnode in node.getchildren():
print subnode
if subnode.tag=="{http://webservices.amazon.com/AWSECommerceService/2005-10-05}TotalResults":
print(subnode.text)
elif subnode.tag=="{http://webservices.amazon.com/AWSECommerceService/2005-10-05}Item":
for item in subnode:
print item
if item.tag=="{http://webservices.amazon.com/AWSECommerceService/2005-10-05} ASIN":
print(item.text)
© 2024 OneMinuteCode. All rights reserved.