Hi Just wondering, what's the right way to do IO in an RPython program? sys.stdin/sys.stdout don't work, neither does opening files using open(), and raw_input doesn't work. All I can get is print. I can't find anything about this in the docs, and I haven't been able to understand how the PyPy interpreter is doing it from looking at the source code so far. I've been playing around with using the PyPy framework to implement a small interpreter, and this is currently blocking me from translating it. -- Ben Mellor
There are two official ways: 1. use directly os.read/os.open/os.write, rather tedious if you ask me 2. use interfaces that are present in pypy/rlib/streamio.py. I think only documentation for that is in tests unfortunately :( It has interface similar to python's streams, but adapted a bit to accomodate rpythonism. Cheers, fijal On Tue, Mar 17, 2009 at 10:03 AM, Ben Mellor <cumber@netspace.net.au> wrote:
Hi
Just wondering, what's the right way to do IO in an RPython program?
sys.stdin/sys.stdout don't work, neither does opening files using open(), and raw_input doesn't work. All I can get is print. I can't find anything about this in the docs, and I haven't been able to understand how the PyPy interpreter is doing it from looking at the source code so far.
I've been playing around with using the PyPy framework to implement a small interpreter, and this is currently blocking me from translating it.
-- Ben Mellor _______________________________________________ pypy-dev@codespeak.net http://codespeak.net/mailman/listinfo/pypy-dev
Thanks! Got it working now. If I do: stdin_fd = sys.stdin.fileno() during import time and then use that with os.read (either directly or indirectly through streams), will it also be translated correctly for the other non-C backends?
There are two official ways:
1. use directly os.read/os.open/os.write, rather tedious if you ask me 2. use interfaces that are present in pypy/rlib/streamio.py. I think only documentation for that is in tests unfortunately :(
It has interface similar to python's streams, but adapted a bit to accomodate rpythonism.
Cheers, fijal
On Tue, Mar 17, 2009 at 10:03 AM, Ben Mellor <cumber@netspace.net.au> wrote:
Hi
Just wondering, what's the right way to do IO in an RPython program?
sys.stdin/sys.stdout don't work, neither does opening files using open(), and raw_input doesn't work. All I can get is print. I can't find anything about this in the docs, and I haven't been able to understand how the PyPy interpreter is doing it from looking at the source code so far.
I've been playing around with using the PyPy framework to implement a small interpreter, and this is currently blocking me from translating it.
-- Ben Mellor _______________________________________________ pypy-dev@codespeak.net http://codespeak.net/mailman/listinfo/pypy-dev
participants (2)
-
Ben Mellor
-
Maciej Fijalkowski