变量的类型是什么

发布于 2024-10-20 20:49:20 字数 819 浏览 2 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

口干舌燥 2024-10-27 20:49:20

您只需执行类型(变量名称)即可。

You can just do type(variable name).

野心澎湃 2024-10-27 20:49:20

让我们重新格式化该输出以提高可读性:

<<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'
     }
 ]

它告诉您变量的类型:SOAPpy.Types.typedArrayType ...尝试阅读 SOAPpy 文档以了解这一点(我不是 SOAPpy 非用户,不是即使是新手)。

您真正想知道的是如何使用该结果。在我看来,如果您执行 answer_dict = ss[0] 操作,您可以访问如下字段:

print answer_dict['city'] 应生成 Washington< /code> 等,

这样你就可以做到

city = answer_dict['city']
street = answer_dict['street']
# et cetera

请注意,具有奇特类型的 ss 看起来就像一个列表......如果您的查询有多个答案(检查 len(ss)),您将需要迭代列表:

for answer_dict in ss:
    process_each_answer(answer_dict) # substitute your code here

Let's reformat that output for readability:

<<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'
     }
 ]

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 produce Washington etc

so you can do

city = answer_dict['city']
street = answer_dict['street']
# et cetera

Note that ss with the fancy type looks like it acts like a list ... if your query has multiple answers (check len(ss)), you will need to iterate over the list:

for answer_dict in ss:
    process_each_answer(answer_dict) # substitute your code here
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文