mbuzdalov / edx-io

I/O routines for programming courses by ITMO on the edX platform.
MIT License
36 stars 16 forks source link

Usage examples #9

Closed rpoletaev closed 3 years ago

rpoletaev commented 3 years ago

Hi! Could you add an example for using the python library? I'm a newbie with python but It seems much more suitable for the Algo course than golang. I don't know how to use it to send test tasks.

mbuzdalov commented 3 years ago

The README for Python already contains a simple example, verbatim as follows:

from edx_io import edx_io

with edx_io() as io:
    io.writeln(io.next_int() + io.next_int())

Basically, you import the edx_io object from the edx_io module, open it using the with statement, and then perform the input-output operations on the resulting opened object (io in this case).

Note that io.next_token() would return a bytes object, not str. You can just convert it, as in str(io.next_token()) - however, this not only brings you some convenience, but takes some time, which becomes noticeable if you try to read tens of megabytes within a second - so be aware when solving harder problems.

The testing system already contains this edx_io.py file, so you don't have to send it along with your solution (and, in fact, you should not). For local testing, it is necessary to have a local copy, typically in the same directory as your solution (but this may depend on the IDE used).

rpoletaev commented 3 years ago

Thanks