binding a reference to a variable

Fredrik Lundh fredrik at pythonware.com
Wed Apr 10 12:14:15 EDT 2002


Andrew Koenig wrote:

> The point of this example is the . operator, which takes a pattern
> (by value) as its left argument and a variable (by reference) as its
> right argument.  The result is a pattern that matches the same strings
> as the left argument, but if the match is successful, it assigns
> the substring matched to the variable that is the right argument.

you could of course use a RE-like approach:

    m = match(name, pos(0) + break("@", "id") + "@" + rpos(0, "domain"))
    if m:
        print m.group("id", "domain")
        # or perhaps: print m.id, m.domain

</F>

<!-- (the eff-bot guide to) the python standard library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->





More information about the Python-list mailing list