[pypy-dev] Help with "Exception: unexpected prebuilt constant"

Antonio Cuni anto.cuni at gmail.com
Fri Oct 9 10:46:18 CEST 2009

Hi Philip,

Philip Guo wrote:
> Sorry for another newbish question, but I'm having trouble getting PyPy 
> translated into C code.  I added some calls to open() throughout the 
> interpreter codebase (to log some info to files), but it failed 
> translation with the following error:
>   [translation:ERROR]  Exception: unexpected prebuilt constant: 
> <built-in function open>
> I then tried doing 'import os' and then using os.fdopen, but with the 
> same error:
>   [translation:ERROR]  Exception: unexpected prebuilt constant: 
> <built-in function fdopen>

as you have noticed, neither os.open nor os.fdopen are supported by RPython.
The only low-level supported way to deal with files is using 

However, you might want to have a look to rlib.streamio, that provides a 
higher level API to deal with files, offering features such as buffering, 
CR/LF conversions etc.  In particular, you can use 
streamio.open_file_as_stream to get a file like object similar to the builtin 
python ones.

> In general, what Python standard library calls can I make from my 
> modified PyPy code and still have it translate properly?  Specifically, 
> how do I read/write files from within PyPy?

see above :-)


More information about the Pypy-dev mailing list