Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.python
Generic string import like in strptime?
Andre
1/16/2008 8:35:00 AM
3 Answers
Neil Cerutti
1/16/2008 12:33:00 PM
0
On Jan 16, 2008 3:34 AM, Andre <joa@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
> [3456,'blub','blib',0.9]
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/pyt...
. None of them have
become popular enough with Python users to make it into the standard
distribution.
An excellent tool that can be used in these cases is pyparsing, which
is also not in the standard distribution.
http://pyparsing.wikis...
--
Neil Cerutti <mr.cerutti+python@gmail.com>
Paul Hankin
1/16/2008 4:11:00 PM
0
On Jan 16, 8:34 am, Andre <j...@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
>
> [3456,'blub','blib',0.9]
Use regular expressions: see
http://docs.python.org/lib/n...
--
Paul Hankin
Andre' John
1/16/2008 5:07:00 PM
0
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Generic string import like in strptime?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password