0

How can the python create nested objects?

name = 'name'
print(name)
name

name.age = 'age'
print(name.age)
age

name.age.other = 'other'

print(name.age.other)
other

Is it even possible in python ? Thank you

1 Answer 1

3

Sure, you just need to wrap the value in your own class. You can't modify str itself.

class X(str):
    pass

name = X('name')
name.age = X('age')
name.age.other = 'other'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.