[Python-3000] tp_bytes and __bytes__ magic method

Victor Stinner victor.stinner at haypocalc.com
Thu Aug 9 00:49:30 CEST 2007


On Thursday 09 August 2007 00:22:51 Christian Heimes wrote:
> Hey Pythonistas!
>
> Victor Stinner just made a good point at #python. The py3k has no magic
> method and type slot for bytes.

And another problem: mix of __str__ and __unicode__ methods.

class A:
  def __str__(self): return '__str__'

class B:
  def __str__(self): return '__str__'
  def __unicode__(self): return '__unicode__'

print (repr(str( A() )))  # display '__str__'
print (repr(str( B() )))  # display '__unicode__'


Proposition:

  __str__() -> str (2.x) becomes __bytes__() -> bytes (3000)
  __unicode__() -> unicode (2.x) becomes __str__() -> str (3000)

Victor Stinner aka haypo


More information about the Python-3000 mailing list