[Tutor] Starting to write a scanf-like module for Python

Alan Gauld alan.gauld at blueyonder.co.uk
Sun Aug 15 11:26:45 CEST 2004


> I thought it might make a nice weekend project to write scanf for
Python;
> it's nowhere near done yet, but it's sorta working... *grin*
>
>     http://hkn.eecs.berkeley.edu/~dyoo/python/scanf.py
>
> I want to gauge some input from folks on the list to see if this
might be
> useful for folks.

If it were sscanf() it would be really useful. scanf() has so many
bugs/features nobody in their right mind uses it do they? It's
certainly a certain red flag in a code review if any of my guys
ever use raw scanf... [f]gets();sscanf() is the normal pairing.

But the principle is good, The ability to easily parse out values
from a strng is useful.

> It doesn't support everything that C's scanf can do yet, and
probably
> never will.  I'm just trying to implement just enough to make it
easy to
> do the stuff from Programming Challenges without having to worry too
much
> about input/output.  But if there's something that folks feel really
> should be in the module, I'll try to be receptive.

Sounds good, but I would seriously consider sscanf() as a better
project
- and easier - and leave the acquiring the input string to raw_input
or
file.read()

Alan G.



More information about the Tutor mailing list