---
title: "Discussion on \"A method to convert python object to dict(supporting recursion)\" | Hashnode"
description: "Discussion on \"A method to convert python object to dict(supporting recursion)\". Code\ndef object2Map(obj:object):\n    \"\"\"covert object to dict\"\"\"\n    m = obj.__dict__\n    for k in m.keys():\n        v = m[k]\n        if hasattr(v, \"__dict__\"):\n            m[k] = object2Map(v)\n    return m\n\nTest\nclass Test:\n    def __init__(self):\n ..."
url: "https://hashnode.com/posts/a-method-to-convert-python-object-to-dictsupporting-recursion/632697a5dd55cd8b89b20a1e"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [A method to convert python object to dict(supporting recursion)](https://xue1.top/a-method-to-convert-python-object-to-dictsupporting-recursion?utm_source=hashnode&utm_medium=feed)

Code def object2Map(obj:object): """covert object to dict""" m = obj.\_\_dict\_\_ for k in m.keys(): v = m\[k\] if hasattr(v, "\_\_dict\_\_"): m\[k\] = object2Map(v) return m Test class Test: def \_\_init\_\_(self): ...

Sep 18, 2022 · 1 min read · xue1.top  
Read the article

-   [#python](https://hashnode.com/tag/python)

## Written by

[Yuanfei Yang](https://hashnode.com/@yuanfei)

@yuanfei · Beijing, China

  
[View profile](https://hashnode.com/@yuanfei)

never give up!

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
