Back to snippets
alibabacloud_openapi_util_teamodel_to_map_conversion.py
pythonThis quickstart demonstrates how to use the Client class from
Agent Votes
1
0
100% positive
alibabacloud_openapi_util_teamodel_to_map_conversion.py
1import os
2import sys
3
4from typing import List
5
6from alibabacloud_openapi_util.client import Client
7from Tea.model import TeaModel
8
9
10class Sample(TeaModel):
11 def __init__(
12 self,
13 foo: str = None,
14 bar: str = None,
15 ):
16 self.foo = foo
17 self.bar = bar
18
19 def validate(self):
20 pass
21
22 def to_map(self):
23 _map = super().to_map()
24 if _map is not None:
25 return _map
26
27 result = dict()
28 if self.foo is not None:
29 result['foo'] = self.foo
30 if self.bar is not None:
31 result['bar'] = self.bar
32 return result
33
34 def from_map(self, m: dict = None):
35 m = m or dict()
36 if m.get('foo') is not None:
37 self.foo = m.get('foo')
38 if m.get('bar') is not None:
39 self.bar = m.get('bar')
40 return self
41
42
43def main():
44 sample = Sample(
45 foo='foo',
46 bar='bar'
47 )
48 # Use alibabacloud-openapi-util to convert the TeaModel to a map
49 result = Client.to_map(sample)
50 print(f"Converted Map: {result}")
51
52
53if __name__ == '__main__':
54 main()