Fastest I/O on Python ?

Chris Angelico rosuav at gmail.com
Tue Jul 22 12:17:27 EDT 2014


On Wed, Jul 23, 2014 at 2:06 AM, Orochi <kartikjagdale11 at gmail.com> wrote:
> Is there in any other input/output faster than ("raw_input","input" / "print")
> As I am trying to solve competitive Programs on codechef.com using python i was wondering if there is any other way to print and scan the inputs fast.

What do you mean by faster? Are you really seeing performance problems
with them, or are you actually looking for something like C's printf
and scanf, which do more than just output and input?

The print function (use either Python 3 or a future import) has some
good formatting facilities, and if you need more, you can do something
like this:

>>> print("The price is $%.2f per kilo." % 1.5)
The price is $1.50 per kilo.

However, there's no comparable feature for input. It's generally
easiest to take a string from (raw_)input and then parse it yourself,
maybe with a regular expression, or splitting it on whitespace, or
whatever else is appropriate.

But you'll really need to explain what you're actually having issues
with, before we can advise further.

ChrisA



More information about the Python-list mailing list