Reading Soap struct type

T

Thomas Thomas

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'

any help

Thomas
 
D

Diez B. Roggisch

Thomas said:
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
 
S

Simon Brunning

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.

IIRC, SOAPpy's structType has a _keys() function - so somethign like
the following (untested) might work:

struct_as_a_dict = dict((key, getattr(struct, key)) for key in struct._keys())
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top