Reading Soap struct type

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas Thomas

    #1

    Reading Soap struct type

    Hi All,

    I am receiving a hash below from my Soap Interface

    <SOAPpy.Types.s tructType item at 34661160>: {'Field12value' : ':C
    F3Value', 'Field8': 'Price Text:price_text ', 'Field9': 'Text with
    File:file_text
    ', 'Field11value': ':CF2Value', 'Field7': 'Product Code:product_co de',
    'Field7va
    lue': ':product_value s', 'Field2': 'Job Reference:job_r eference', 'Field3':
    'Job
    Description:job _description', 'Field6': 'Campaign Name:campaign_n ame',
    'Field10
    value': ':CF1Value', 'Field6value': ':campaign_valu es', 'Field5':
    'Keywords:keyw
    ords', 'Field10': 'CF1Title:custo m_field1', 'Field11':
    'CF2Title:custo m_field2',
    'Field12': 'CF3Title:custo m_field3', 'Field13': 'CF4Title:custo m_field4',
    'Fiel
    d14': 'Name:meta_file name', 'Field4': 'Display Name:display_na me',
    '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

  • Diez B. Roggisch

    #2
    Re: Reading Soap struct type

    Thomas Thomas schrieb:[color=blue]
    > Hi All,
    >
    > I am receiving a hash below from my Soap Interface
    >
    > <SOAPpy.Types.s tructType item at 34661160>: {'Field12value' : ':C
    > F3Value', 'Field8': 'Price Text:price_text ', 'Field9': 'Text with
    > File:file_text
    > ', 'Field11value': ':CF2Value', 'Field7': 'Product Code:product_co de',
    > 'Field7va
    > lue': ':product_value s', 'Field2': 'Job Reference:job_r eference', 'Field3':
    > 'Job
    > Description:job _description', 'Field6': 'Campaign Name:campaign_n ame',
    > 'Field10
    > value': ':CF1Value', 'Field6value': ':campaign_valu es', 'Field5':
    > 'Keywords:keyw
    > ords', 'Field10': 'CF1Title:custo m_field1', 'Field11':
    > 'CF2Title:custo m_field2',
    > 'Field12': 'CF3Title:custo m_field3', 'Field13': 'CF4Title:custo m_field4',
    > 'Fiel
    > d14': 'Name:meta_file name', 'Field4': 'Display Name:display_na me',
    > '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'[/color]

    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.st ructType is capable of. I suggest you look at it's source.

    Diez

    Comment

    • Simon Brunning

      #3
      Re: Reading Soap struct type

      On 5/10/06, Diez B. Roggisch <deets@nospam.w eb.de> wrote:[color=blue]
      > 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.st ructType is capable of. I suggest you look at it's source.[/color]

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

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

      --
      Cheers,
      Simon B,
      simon@brunningo nline.net,

      Comment

      Working...