[pypy-dev] __builtin__ module

Thomas Heller theller at python.net
Fri Jan 24 12:02:25 CET 2003

Armin Rigo <arigo at tunes.org> writes:

> About chr(i) vs. '%c'%i vs. '\x00\x01...\xFF'[i]: what I feel this
> shows is that one of these solutions must be thought as the
> primitive way to build a character, and the others should use it;
> and I definitely feel that chr() is the primitive way to build a
> character.  Contrary to what I said in a previous e-mail I don't
> think that chr() should be implemented with '%c'%i.  On the other
> hand, I guess that the strings' % operator could nicely be
> implemented in pure Python.  It would then have to use chr() to
> implement the %c format code.  It looks more reasonable than the
> other way around.

I don't want to beat this to death, but I've a different opinion.
There is no 'character' data type in Python, only a 'string', which
consists of 0 to n characters.

This is also reflected in Python/bltinmodule.c, where the code is:

	s[0] = (char)x;
	return PyString_FromStringAndSize(s, 1);

So even the C code creates a 'character array', and passes it to
PyString_FromStringAndSize, which I would call to canonical way to
build a string of whatever size. Of course there's a lot going
on what this function does behind the scenes...


More information about the Pypy-dev mailing list