how to avoid leading white spaces
Ethan Furman
ethan at stoneleaf.us
Fri Jun 3 18:11:24 EDT 2011
Chris Torek wrote:
>> On 2011-06-03, rurpy at yahoo.com <rurpy at yahoo.com> wrote:
> [prefers]
>>> re.split ('[ ,]', source)
>
> This is probably not what you want in dealing with
> human-created text:
>
> >>> re.split('[ ,]', 'foo bar, spam,maps')
> ['foo', '', 'bar', '', 'spam', 'maps']
I think you've got a typo in there... this is what I get:
--> re.split('[ ,]', 'foo bar, spam,maps')
['foo', 'bar', '', 'spam', 'maps']
I would add a * to get rid of that empty element, myself:
--> re.split('[ ,]*', 'foo bar, spam,maps')
['foo', 'bar', 'spam', 'maps']
~Ethan~
More information about the Python-list
mailing list