[pypy-dev] __builtin__ module

Thomas Heller theller at python.net
Wed Jan 22 17:57:22 CET 2003

Armin Rigo <arigo at tunes.org> writes:

> Fine!  The greatest benefits of your code is that it clearly shows what can be
> directly implemented in Python, what could be, and what cannot.
> A function like chr() is in the second category: it could be written in Python
> as you did, but it is not "how we feel a chr() implementation should be".  It
> should just build a one-string character, putting 'i' somewhere as an ASCII
> code.  But how?

I don't think so. For me, this is a fine implementation of chr():

def chr(i):
    return "\x00\x01\x02x03...\xFF"[i]

Maybe a check should be added to make sure 'i' is between 0 and 255 :-)

But the resposibility to construct string objects is not chr()'s
burdon, IMO.

In a CPython extension and probably also in the core there are helper
functions to build these strings, the implementor of chr() would use them.


More information about the Pypy-dev mailing list