Joe Strout wrote:
Catching up on what's new in Python since I last used it a decade ago,
I've just been reading up on template strings. These are pretty cool!
However, just as a template string has some advantages over %
substitution for building a string, it seems like it would have
Joe templ = Template(The $object in $location falls mainly in the
$subloc.)
Joe d = templ.match(s)
Joe and then d would either by None (if s doesn't match), or a
Joe dictionary with values for 'object', 'location', and 'subloc'.
Joe But I couldn't find anything like
Tino Yeah, its a bit hard to spot:
Tino
http://docs.python.org/library/stdtypes.html#string-formatting-operations
That shows how to use the template formatting as it currently exists. To my
knowledge there is no support for the inverse operation, which is what Joe
asked about. Given
Joe Strout wrote:
Catching up on what's new in Python since I last used it a decade ago,
I've just been reading up on template strings. These are pretty cool!
However, just as a template string has some advantages over %
substitution for building a string, it seems like it would have
Pyparsing makes building expressions with named fields pretty easy.
from pyparsing import Word, alphas
wrd = Word(alphas)
templ = The + wrd(object) + in + wrd(location) + \
stays mainly in the + wrd(subloc) + .
tests = \
The rain in Spain stays mainly in the plain.
The snake in
[EMAIL PROTECTED] wrote:
Tino Yeah, its a bit hard to spot:
Tino
http://docs.python.org/library/stdtypes.html#string-formatting-operations
That shows how to use the template formatting as it currently exists. To my
knowledge there is no support for the inverse operation, which is
On Oct 9, 2008, at 7:05 AM, [EMAIL PROTECTED] wrote:
Tino
http://docs.python.org/library/stdtypes.html#string-formatting-operations
That shows how to use the template formatting as it currently
exists. To my
knowledge there is no support for the inverse operation, which is
what Joe
Joe Strout wrote:
Catching up on what's new in Python since I last used it a decade ago,
I've just been reading up on template strings. These are pretty
cool!
I don't think they've gained much traction and expect them to be superseded
by PEP 3101 (see
Tino ??? can you elaborate? I don't see the problem.
Tino %(foo)s % mapping
Joe wants to go in the other direction. Using your example, he wants a
function which takes a string and a template string and returns a dict.
Here's a concrete example:
s = My dog has fleas
fmt = My
Catching up on what's new in Python since I last used it a decade ago,
I've just been reading up on template strings. These are pretty
cool! However, just as a template string has some advantages over %
substitution for building a string, it seems like it would have
advantages over
Wow, this was harder than I thought (at least for a rusty Pythoneer
like myself). Here's my stab at an implementation. Remember, the
goal is to add a match method to Template which works like
Template.substitute, but in reverse: given a string, if that string
matches the template, then
On Oct 9, 5:20 pm, Joe Strout [EMAIL PROTECTED] wrote:
Wow, this was harder than I thought (at least for a rusty Pythoneer
like myself). Here's my stab at an implementation. Remember, the
goal is to add a match method to Template which works like
Template.substitute, but in reverse:
12 matches
Mail list logo