Ask Your Question

# Revision history [back]

1) The problem is that on a=complex(1), we have that a.real and a.imag are attributes.

On b=CC(1) we have that b.real is a method so you need to call b.real() to get the part. Alternatively, you can use b.real_part().

In sage it's become customary to access data via methods, not via attributes. That's a common tool to make it easy to hide implementation details. Strictly speaking it's not necessary in python because @property allows "getters" and "setters" that can be accessed as if they were attributes.

2) see python modules.

3) The methods available on a certain type of objects are the choice of that object. You don't get to change that. You can subclass, however, and then you can implement whatever methods you like in that subclass.