This is an old copy of the Python FAQ. The information here may be outdated.

Is there a scanf() or sscanf() equivalent?

Not as such.

For simple input parsing, the easiest approach is usually to split the line into whitespace-delimited words using the split method of string objects and then convert decimal strings to numeric values using int or float. split supports an optional separator parameter which is useful if the line uses something other than whitespace as a separator.

For more complicated input parsing, regular expressions are more powerful than C’s sscanf() and better suited for the task.

CATEGORY: programming


A Django site. rendered by a django application. hosted by webfaction.