http://hkn.eecs.berkeley.edu./~dyoo/python/scanf/
内网下载:scanf-12tar
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
- scanf(formatString) formatted scanning across sys.stdin. Returns a tuple of the captured results.
- sscanf(inputString, formatString) formatted scanning across strings. Returns a tuple of the captured results.
- fscanf(inputFile, formatString) formatted scanning across files. Returns a tuple of the captured results.
Supported syntax
% [*] [width] [type]
- [*] suppresses variable capture. Optional.
- [width] defines maximum number of characters. Optional.
-
[type] defines the type of the format string. We’ve implemented the following:
d decimal integer. i integer. The integer may be in octal (leading zero) or hexadecimal (leading 0x or 0X). o octal integer (with or without leading zero). x hexadecimal integer (with or without leading 0x or 0X) c characters. The next input characters (default 1) are placed at the indicated spot. The normal skip over white space is suppressed; to read the next non-white space character, use %1s. s character string (not quoted). f floating-point number with optional sign and optional decimal point. % literal %; no assignment is made.
The module docs have more details on usage and limitations.