I'd like to get output formatting for my own classes that mimics the
built-in output formatting. For example,
[color=blue][color=green][color=darkred]
>>> x = 4.54
>>> print "%4.2f" % x[/color][/color][/color]
4.54
In other words, if I substitute a class instance for "x" above, I'd
like to make the format string apply to an element or elements of the
instance. Can I somehow overload the "%" operator for that? Thanks.
On an unrelated matter, I think the complex class in Python is too
complex, so I plan to clean it up and implement it right. (just
kidding, folks!)
built-in output formatting. For example,
[color=blue][color=green][color=darkred]
>>> x = 4.54
>>> print "%4.2f" % x[/color][/color][/color]
4.54
In other words, if I substitute a class instance for "x" above, I'd
like to make the format string apply to an element or elements of the
instance. Can I somehow overload the "%" operator for that? Thanks.
On an unrelated matter, I think the complex class in Python is too
complex, so I plan to clean it up and implement it right. (just
kidding, folks!)
Comment