String manipulation advice needed.

Raaijmakers, Vincent (GE Infrastructure) Vincent.Raaijmakers at ge.com
Wed Oct 13 12:17:10 EDT 2004


What is the easiest way of getting this information out of a string:

foo = "My number 70 is what I want to parse"  => 70
foo = "My info {info} between the curly brackets is what I want to parse" => {info}
foo = "My  info between [hello world] is what I want to parse" => [hello world]

At this moment my way to go is splitting the strings in substring, and do different checks on these substrings like:
- try: int(substring)
- substring.find('{') or substring.find('[')

Works but.. my guess is that it can be way more smarter, I must miss a strong library that can help me in simplifying the job.

Thanks,
Vincent


-----Original Message-----
From: python-list-bounces+vincent.raaijmakers=ge.com at python.org
[mailto:python-list-bounces+vincent.raaijmakers=ge.com at python.org]On
Behalf Of Duncan Booth
Sent: Monday, March 01, 2004 8:54 AM
To: python-list at python.org
Subject: Re: pyAlbum


Josiah Carlson <jcarlson at nospam.uci.edu> wrote in 
news:c1tgot$e2$1 at news.service.uci.edu:

> 
> Some fairly rudimentary fact-checking would have prevented the 
> errors/oversights listed above.

A few more:

Slide 17: 'Tuples are enclosed in parentheses'

The commas make the tuple, not the parentheses. The first example could 
equally be written:

   myTuple = 1, 4, 5

Parentheses are only required to remove ambiguity (or for empty tuples).

Slide 21, it is worth pointing out the weakness of '{', '}' which is that 
the parenthese you think match up by looking at the block structure aren't 
necessarily the ones that do match: as in the example given where the last 
'}' actually closes the else block.

The 'if' statement shows the full range if..elif..else. It would be 
consistent to mention the else clause on while and for loops also.
-- 
http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list