变量的类型是什么
我是 Python 的新手,我有以下代码:
from SOAPpy import WSDL
fichier_wsdl = 'http://geocoder.us/dist/eg/clients/GeoCoder.wsdl'
wsdl = WSDL.Proxy(fichier_wsdl)
callInfo = wsdl.methods['geocode']
ss = wsdl.geocode('1600 Pennsylvania Ave, Washington, DC.')
print(ss)
结果是:
IMPORT: http://schemas.xmlsoap.org/soap/encoding/
no schemaLocation attribute in import
<<class 'SOAPpy.Types.typedArrayType'> results at 21824752>: [<SOAPpy.Types.structType item at 21818984>: {'city': 'Washington', 'prefix': '', 'suffix': 'NW', 'zip': 20502, 'number': 1600, 'long': -77.037684, 'state': 'DC', 'street': 'Pennsylvania', 'lat': 38.898748, 'type': 'Ave'}]
我尝试了解我的 ss 变量( print(type(ss)) 得到 SOAPpy.Types.typedArrayType 的类型是什么,这对我来说不是很清楚)? 以及如何为城市或街道提供一个简单的变量?
I am a very newbie in Python I have the following code:
from SOAPpy import WSDL
fichier_wsdl = 'http://geocoder.us/dist/eg/clients/GeoCoder.wsdl'
wsdl = WSDL.Proxy(fichier_wsdl)
callInfo = wsdl.methods['geocode']
ss = wsdl.geocode('1600 Pennsylvania Ave, Washington, DC.')
print(ss)
The result is:
IMPORT: http://schemas.xmlsoap.org/soap/encoding/
no schemaLocation attribute in import
<<class 'SOAPpy.Types.typedArrayType'> results at 21824752>: [<SOAPpy.Types.structType item at 21818984>: {'city': 'Washington', 'prefix': '', 'suffix': 'NW', 'zip': 20502, 'number': 1600, 'long': -77.037684, 'state': 'DC', 'street': 'Pennsylvania', 'lat': 38.898748, 'type': 'Ave'}]
and I try to understand what type has my ss variable (the print(type(ss)) get SOAPpy.Types.typedArrayType which is not very clear for me)?
And how to have a simple variable, for the city or the street?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需执行
类型(变量名称)
即可。You can just do
type(variable name)
.让我们重新格式化该输出以提高可读性:
它告诉您变量的类型:
SOAPpy.Types.typedArrayType
...尝试阅读 SOAPpy 文档以了解这一点(我不是 SOAPpy 非用户,不是即使是新手)。您真正想知道的是如何使用该结果。在我看来,如果您执行
answer_dict = ss[0]
操作,您可以访问如下字段:print answer_dict['city']
应生成Washington< /code> 等,
这样你就可以做到
请注意,具有奇特类型的
ss
看起来就像一个列表......如果您的查询有多个答案(检查len(ss)
),您将需要迭代列表:Let's reformat that output for readability:
It's telling you what type your variable is:
SOAPpy.Types.typedArrayType
... try reading the SOAPpy docs to understand that (I'm a SOAPpy non-user, not even a newbie).What you really want to know is how to use that result. Looks to me like if you do
answer_dict = ss[0]
, you can access the fields like this:print answer_dict['city']
should produceWashington
etcso you can do
Note that
ss
with the fancy type looks like it acts like a list ... if your query has multiple answers (checklen(ss)
), you will need to iterate over the list: