Reading Soap struct type

Diez B. Roggisch deets at nospam.web.de
Wed May 10 03:49:12 EDT 2006


Thomas Thomas schrieb:
> Hi All,
> 
> I am receiving a hash below from my Soap Interface
> 
> <SOAPpy.Types.structType item at 34661160>: {'Field12value': ':C
> F3Value', 'Field8': 'Price Text:price_text', 'Field9': 'Text with
> File:file_text
> ', 'Field11value': ':CF2Value', 'Field7': 'Product Code:product_code',
> 'Field7va
> lue': ':product_values', 'Field2': 'Job Reference:job_reference', 'Field3':
> 'Job
>  Description:job_description', 'Field6': 'Campaign Name:campaign_name',
> 'Field10
> value': ':CF1Value', 'Field6value': ':campaign_values', 'Field5':
> 'Keywords:keyw
> ords', 'Field10': 'CF1Title:custom_field1', 'Field11':
> 'CF2Title:custom_field2',
>  'Field12': 'CF3Title:custom_field3', 'Field13': 'CF4Title:custom_field4',
> 'Fiel
> d14': 'Name:meta_filename', 'Field4': 'Display Name:display_name',
> 'Field13value
> ': ':CF4Value'}
> 
> How can i iterarte through it bcz when do try do something like
> myHash.values()
> I am getting the error
> AttributeError: structType instance has no attribute 'values'

That is because it is no hash - AFAIK SOAP doesn't support hashes (or 
dicts, in python-lingo) out of the box. What you see above essentially a 
named tuple. Conceptionally like this:

class MyStruct:

     def __init__(self, foo, bar):
          self.foo = foo
          self.bar = bar


Either you access the individual values by name - or maybe there is a 
way to enumerate the names for you, but that depends on what the 
SOAPpy.Types.structType is capable of. I suggest you look at it's source.

Diez



More information about the Python-list mailing list