[Soap-Python] rpclib - dynamic key names

Chris Austin chris at sydneysys.com
Thu Apr 5 20:44:56 CEST 2012


Would something like the following work for you?

>>> from rpclib.model.complex import ComplexModel
>>> class A(ComplexModel):
...     def foo(self):
...         return "bar"
...         
...     
... 
>>> from rpclib.model.primitive import Unicode
>>> for x in xrange(5):
...     setattr(A, "u%s" % x, Unicode)
...     
... 
>>> dir(A)
['Annotations', 'Attributes', 'Empty', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__len__', '__metaclass__', '__module__', '__namespace__', '__new__', '__reduce__', '__reduce_ex__', '__rep
r__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__type_name__', '__weakref__', '_force_own_namespace', '_s_customize', '_type_info', 'alias', 'customize', 'foo', 'from_string', 'get_deserialization_instance', 'get_flat_type_info', 'get_members_pairs',
 'get_namespace', 'get_namespace_prefix', 'get_serialization_instance', 'get_simple_type_info', 'get_type_name', 'get_type_name_ns', 'is_default', 'produce', 'resolve_namespace', 'to_dict', 'to_string', 'to_string_iterable', 'u0', 'u1', 'u2', 'u3', 'u4', 'validate_nativ
e', 'validate_string']
>>> A.u0
<class 'rpclib.model.primitive.Unicode'>
>>> 

	
On Apr 5, 2012, at 11:11 AM, azurIt wrote:

> 
> Hi,
> 
> any hints how can i return data structure with dynamic key names (so they cannot be specified in type definition)? For example, something like this:
> 
> data = {}
> for i in xrange(1000):
>  data["a%s" % i] = u"something"
> return data
> 
> 
> without creating type:
> 
> class test(ComplexModel):
>  a0 = Unicode
>  a1 = Unicode
>  ...
>  a999 = Unicode
> 
> 
> Thnx!
> 
> azur
> _______________________________________________
> Soap mailing list
> Soap at python.org
> http://mail.python.org/mailman/listinfo/soap

Chris Austin
chris at sydneysys.com





More information about the Soap mailing list