类的声明和使用

import json
class Person(object):
    """docstring for Person"""
    def __init__(self, name, age):
        super(Person, self).__init__()
        self.name = name
        self.age = age

person = Person("Scott",18)

res = json.dumps(person.__dict__)
print(res) #{"age": 18, "name": "Scott"}

results matching ""

    No results matching ""