数据对象映射
jangli的Python项目详细描述
Jangli
范围
- 数据定义
- 数据映射
将json转换为python对象。
from jangli.json_utils.json_to_object import json_to_obj
data = '{"password": "123456", "id": 1, "name": "abhimanyu"}'
class Student:
def __init__(self):
self.id = None
self.name = None
self.password = None
s = json_to_obj(data, Student)
print(s.name)
将json转换为python对象。
from jangli.json_utils.json_to_object import json_to_obj
data_2 = '{"password": "123456", "id": 1, "name": "abhimanyu", "school" : "SOHS"}'
class Student:
school = None
def __init__(self):
self.id = None
self.name = None
self.password = None
s2 = json_to_obj(data_2, Student)
print(s2.school)
自定义对象列表
from jangli.list_of_object import ListObject
class A:
def __init__(self, b):
self.b = b
lt = ListObject(A)
lt.append(A(7))
lt.insert(1, A(8))
print(lt)
Output : [<__main__.A object at 0x00CA3730>, <__main__.A object at 0x00CC6E10>]
病例转换为camelcase
from jangli.case_type import CamelCase
@CamelCase
class NewClass:
def __init__(self):
self.a = 7
self.b = "hi"
self.c = True
self._from = None
new = NewClass()
print(new.__dict__)
麻省理工学院许可证:版权所有(c)2019 Abhimanyu Haralukallu