1

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?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
philnext
  • 3,242
  • 5
  • 39
  • 62

2 Answers2

5

You can just do type(variable name).

Katriel
  • 120,462
  • 19
  • 136
  • 170
Pradeep Nayak
  • 675
  • 1
  • 10
  • 24
  • Yes... so my question was not very clear. The answer is :'SOAPpy.Types.typedArrayType' ans I don't know how to use it (I change my question to be more clear) – philnext Mar 07 '11 at 19:50
  • for future answers, you don't need to add a signature line. You're name's already attached to the post :) – Karmastan Mar 07 '11 at 19:52
2

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
John Machin
  • 81,303
  • 11
  • 141
  • 189