[IronPython] What C# methods do __repr__ and __str__ use?
Dino Viehland
dinov at exchange.microsoft.com
Wed May 28 21:55:59 CEST 2008
You'll want to implement the ICodeFormattable interface. It looks like we don't pick up a method that's just named __repr__ right now. I could see us fixing that but I wouldn't think it's a high priority unless someone finds implementing ICodeFormattable burdensome.
-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Douglas S. Blank
Sent: Wednesday, May 28, 2008 12:22 PM
To: Discussion of IronPython
Subject: Re: [IronPython] What C# methods do __repr__ and __str__ use?
Anyone have an answer for this: I can't write C# code that has its own
method for use in repr(). Am I missing something?
-Doug
Douglas S. Blank wrote:
> On Fri, May 23, 2008 3:37 pm, Toni Alatalo said:
>> Douglas S. Blank kirjoitti:
>>> will use it? Likewise, what C# method is used in Python's str(obj)?
>>>
>> i don't know, but would guess ToString() .. and wonder about it if it
>> wasn't that but something else :o
>> repr() can't guess, i don't think there's an equivalent in .net, but can
>> very well be mistaken there.
>
> It looks like the C# method __str__ is used for the Python method, but in
> IP2B2 the C# method __repr__ is getting overwritten by an auto generated
> method. Is that a bug, or is there something I'm missing?
>
> $ ipy2 -i python/graphics.py
>>>> pm = Pixmap()
>>>> pm.getPixel(0,0) # What is this calling?
> <Pixel object at 0x2B>
>>>> pm.getPixel(0,0).__repr__() # This is repr() too
> '<GraphicsCore+Pixel object at 0x2C [GraphicsCore+Pixel]>'
>>>> pm.getPixel(0,0).__Repr__() # This is mine
> '<Pixel at (0,0)>'
>>>> pm.getPixel(0,0).__str__() # That is mine, and str()
> '<Pixel at (0,0)>'
>>>> pm.getPixel(0,0).ToString() # Used by __repr__
> 'GraphicsCore+Pixel'
>
> -Doug
>
>>> -Doug
>>>
>> ~Toni
>>
>> _______________________________________________
>> Users mailing list
>> Users at lists.ironpython.com
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>>
>
>
_______________________________________________
Users mailing list
Users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
More information about the Ironpython-users
mailing list