Scanf --- a pure Python scanf-like module

If you've ever wanted to say:

import scanf
print scanf.sscanf("/usr/sbin/sendmail - 0 errors, 4 warnings",
                   "%s - %d errors, %d warnings")
well, now you can! *grin*

Releases

All software releases of this package are licensed under the New BSD license.

Description

scanf provides formatted input from standard input, strings, or files, using a format-string syntax that's similar to C's scanf(). The syntax should be familiar to C programmers, and offers very simple pattern matching against strings and files.

Functions

Supported syntax

% [*] [width] [type]
The module docs have more details on usage and limitations.

History and related modules

There is a sscanfmodule.c extension module in contrib section of Python.org, although I'm not sure how fresh this is. There was also a fairly large thread about this on comp.lang.python, although it looks like the consensus was to recommend regular expressions.

There was also a discussion on Python-dev about adding another scanf-like operator, to offer symmetry with String Formatting. Although adding a new operator didn't appear to fly, it looks like people agreed that having a scanf module might be a good idea.

Back to python.