def scanf(format, s=None, collapseWhitespace=True):
if s is None:<EOL><INDENT>s = sys.stdin<EOL><DEDENT>if hasattr(s, "<STR_LIT>"):<EOL><INDENT>s = s.readline()<EOL><DEDENT>format_re, casts = scanf_compile(format, collapseWhitespace)<EOL>found = format_re.search(s)<EOL>if found:<EOL><INDENT>groups = found.groups()<EOL>return tuple([casts[i](groups[i]) for i in range(len(groups))])<EOL><DEDENT>
scanf supports the following formats:
  %c        One character
  %5c       5 characters
  %d, %i    int value
  %7d, %7i  int value with length 7
  %f        float value
  %o        octal value
  %X, %x    hex value
  %s        string terminated by whitespace

Examples:
>>> scanf("%s - %d errors, %d warnings", "/usr/sbin/sendmail - 0 errors, 4 warnings")
('/usr/sbin/sendmail', 0, 4)
>>> scanf("%o %x %d", "0123 0x123 123")
(83, 291, 123)


scanf.scanf returns a tuple of found values
or None if the format does not match.