Generic string import like in strptime?
mr.cerutti at gmail.com
Wed Jan 16 13:33:11 CET 2008
On Jan 16, 2008 3:34 AM, Andre <joa at hrz.tu-chemnitz.de> wrote:
> Hi there
> Is there a function like strptime, which takes a string and converts it
> into an array depending on a format string I provide. Like:
> >>> a = '3456\tblub-blib.0.9'
> >>> b = '%d\t%s-%s.%f'
> >>> c = mysticalfunction(a,b)
> >>> print c
No, not in the standard distribution of Python.
In Python, you're expected to use appropriate string methods, or hold
your nose and drag out the re module. There are some scanf-like
libraries for Python available on the net, e.g.,
http://hkn.eecs.berkeley.edu/~dyoo/python/scanf/. None of them have
become popular enough with Python users to make it into the standard
An excellent tool that can be used in these cases is pyparsing, which
is also not in the standard distribution.
Neil Cerutti <mr.cerutti+python at gmail.com>
More information about the Python-list