Thinking Pythonically (was Re: gah! I hate the new string syntax)
Magnus Lie Hetland
mlh at idi.ntnu.no
Fri Mar 2 16:31:33 EST 2001
"Mark Pilgrim" <f8dy at yahoo.com> wrote in message
news:97oupq$qijrh$1 at ID-77331.news.dfncis.de...
[snip]
> >>> [line for line in output if line[:4]=='Tag:']
> ['Tag: /vobs/intranet\\012', 'Tag: /vobs/project\\012']
>
> Now I think: OK, I have a list of the lines I want, but I just want the
> name, not the "Tag:" prefix or all the whitespace.
>
> >>> vobs = [line.replace('Tag:', '').strip() for line in output if
> line[:4]=='Tag:']
> >>> vobs
> ['/vobs/intranet', '/vobs/project']
I can't resist fiddling with little snippets of code... Why don't you
use:
>>> vobs = [line[4:-1] for line in output if line[:4] == 'Tag:']
Oh, well...
--
Magnus Lie Hetland http://www.hetland.org
"Reality is what refuses to disappear when you stop
believing in it" -- Philip K. Dick
More information about the Python-list
mailing list