Is it possible to add attributes to a object outside of its scope?
I.e: The following code doesnt works, how do I do what I intended to do with that code?
b = object()
b.foo = "bar"
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In general, it is possible. However, it is not possible for most types that are implemented in C, instead of in Python. Unfortunately, this applies to the most often-used of the standard Python interpreter’s built-in types.
If you define a class of your own in Python, you’ll see that it works fine.