python - convert class to dictionary -
I have a sqlalchemy
mapped square, and I want to convert it to a Python dictionary In other words, I want to remove the code from the to_map
function in the code below:
def for the purpose of returning the object from the flask through JSNIF. To_map (user): m = {} m ['id'] = User.id m ['name'] = user.name return m @ app.route ("/ users.json") def some_route_function () user = [ To_map user (for user.query.all) ()] Return flask.jsonify ({'user': user})
one The quick one-liner will be
key.startswith ('_')}
in the DIR (user) key for getattr (user, key) key < P> Anyone working on the conference / impression that anything started with an underscore is private.
Comments
Post a Comment