pythonspyne

How to get the element name with a hyphen on a Spyne WebServer?


I am using Spyne to create a WebService from an existing WSDL (we can not change any element names, etc.).

I am facing this issue that one element name has a hyphen.

The code fragment is below:

class RequestType(ComplexModel):
    _type_info = [
        ('Book_Name', Unicode(min_occurs=1)),
        ('orderedCount-totalCount', Unicode(min_occurs=1)),
        ......

The code

print(RequestType.orderedCount-totalCount)

raises this error:

AttributeError: 'RequestType' object has no attribute 'orderedCount'

It seems Python does not understand the hyphen character.

I can not change the element name because of strict name rules, which are required by the existing WebClient.

Is there any way to access the value from this element in Spyne/Python?

Can we read values based on their order instead of their names?


Solution

  • You can use getattr(inst, 'orderedCount-totalCount')