473,326 Members | 2,095 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Generic string import like in strptime?

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]
Many thanks

Andre
Jan 16 '08 #1
3 1426
On Jan 16, 2008 3:34 AM, Andre <jo*@hrz.tu-chemnitz.dewrote:
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/python/scanf/. 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.wikispaces.com/

--
Neil Cerutti <mr***************@gmail.com>
Jan 16 '08 #2
On Jan 16, 8:34 am, Andre <j...@hrz.tu-chemnitz.dewrote:
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/node49.html

--
Paul Hankin
Jan 16 '08 #3
Nice. Thanks a lot.

Andre
On Wed, 16 Jan 2008, Paul Hankin wrote:
On Jan 16, 8:34 am, Andre <j...@hrz.tu-chemnitz.dewrote:
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/node49.html

--
Paul Hankin
Jan 16 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: MikeyG | last post by:
Hi, I have a date string in the ctime() format ('Sat Mar 5 10:38:07 2005') and I want to know how long ago that was in whole days. So far I have: import time import datetime age =
3
by: Ilja Booij | last post by:
Hi all, I have some trouble with the following: I'm getting a time string, in YYYY-MM-DD HH:mm:ss format, which I need to translate into a string with DD-Mon-YYYY HH:mm:ss +HHMM, where the...
6
by: google0 | last post by:
I know this is a trivial function, and I've now spent more time searching for a surely-already-reinvented wheel than it would take to reinvent it again, but just in case... is there a published,...
2
by: Stefan Antonelli | last post by:
Hi, i have to convert several timestamps. The given format, eg "yyyy-mm-dd hh:mm:ss" has to be converted to an epoch string. Is there any proper way to do this? If not, i have to split the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.