Why doesn't Python (error msg) tell me WHAT the actual (arg) values are ?
Peter J. Holzer
hjp-python at hjp.at
Fri Feb 24 14:06:06 EST 2023
On 2023-02-23 20:32:26 -0700, Michael Torrie wrote:
> On 2/23/23 01:08, Hen Hanna wrote:
> > Python VM is seeing an "int" object (123) (and telling me that)
> > ... so it should be easy to print that "int" object What does
> > Python VM know ? and when does it know it ?
> It knows there is an object and its name and type. It knows this from
> the first moment you create the object and bind a name to it.
> > it seems like it is being playful, teasing (or mean), and
> > hiding the ball from me
>
> Sorry you aren't understanding. Whenever you print() out an object,
> python calls the object's __repr__() method to generate the string to
> display. For built-in objects this is obviously trivial. But if you
> were dealing an object of some arbitrary class, there may not be a
> __repr__() method
Is this even possible? object has a __repr__ method, so all other
classes would inherit that if they don't define one themselves. I guess
it's possible to explicitely remove it ...
> which would cause an exception, or if the __repr__()
> method itself raised an exception,
Yup. That is possible and has happened to me several times - of course
always in a situation where I really needed that output ...
hp
--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp at hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/python-list/attachments/20230224/9bab0fc0/attachment.sig>
More information about the Python-list
mailing list