Created
February 6, 2018 03:42
-
-
Save akshaykarnawat/2fa69ae7f97ab9cdc2c6eb680ccbe682 to your computer and use it in GitHub Desktop.
Recursive Object Dictionary in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import uuid | |
import json | |
max_count = 200 #982 # use sys.setrecursionlimit(1000) for higher limits | |
count = 0 | |
dd = { 'id': str(uuid.uuid4()), 'obj': None } | |
def objectOfObject(obj, count, max_count): | |
# print(obj) | |
obj['obj'] = { 'id': str(uuid.uuid4()) } | |
count += 1 | |
if count != max_count: | |
objectOfObject(obj['obj'], count, max_count) | |
objectOfObject(dd, count, max_count) | |
# print(json.dumps(dd)) | |
with open('recursive_object.json', 'w') as file: | |
json.dump(dd, file, indent=2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment