Regular Expressions and Dividing Strings
Christoph Haas
email at christoph-haas.de
Tue Nov 8 18:05:47 EST 2005
On Tuesday 08 November 2005 23:59, James Colannino wrote:
> Hey everyone, I have a file containing the following type of data (only
> an example):
>
> root:root
>
> What I want to do is take this line and divide it into two separate
> strings (the ':' character would divide the two strings, so the result
> of the example above would be "root" and "root.") The names will vary
> in length (this refers to username/group ownerships.) I'm probably
> missing something extremely basic. I found the module re to do the
> regular expression matching I need, but I'm not quite sure how I can
> actually split this line up into two separate variables.
You probably mean:
a="root:root"
b,c = a.split(":")
b and c contain both sides of the colon.
Christoph
--
~
~
".signature" [Modified] 1 line --100%-- 1,48 All
More information about the Python-list
mailing list