Re: Enumerating formatting strings

2005-04-21 Thread Michael Spencer
Steve Holden wrote: Michael Spencer wrote: Andrew Dalke wrote: I see you assume that only \w+ can fit inside of a %() in a format string. The actual Python code allows anything up to the balanced closed parens. Gah! I guess that torpedoes the regexp approach, then. Thanks for looking at this Micha

Re: Enumerating formatting strings

2005-04-21 Thread Bengt Richter
On Wed, 20 Apr 2005 17:09:16 -0700, Michael Spencer <[EMAIL PROTECTED]> wrote: >Andrew Dalke wrote: > >> I see you assume that only \w+ can fit inside of a %() >> in a format string. The actual Python code allows anything >> up to the balanced closed parens. >> >Gah! I guess that torpedoes the r

Re: Enumerating formatting strings

2005-04-21 Thread Steve Holden
Michael Spencer wrote: Andrew Dalke wrote: I see you assume that only \w+ can fit inside of a %() in a format string. The actual Python code allows anything up to the balanced closed parens. Gah! I guess that torpedoes the regexp approach, then. Thanks for looking at this Michael While Andrew may

Re: Enumerating formatting strings

2005-04-20 Thread Greg Ewing
Peter Otten wrote: Greg Ewing wrote: This seems to happen even with a custom subclass of tuple, so it must be doing an exact type check. No, it doesn't do an exact type check, but always calls the tuple method: I guess you mean len(). On further investigation, this seems to be right, except that it

Re: Enumerating formatting strings

2005-04-20 Thread Michael Spencer
Andrew Dalke wrote: I see you assume that only \w+ can fit inside of a %() in a format string. The actual Python code allows anything up to the balanced closed parens. Gah! I guess that torpedoes the regexp approach, then. Thanks for looking at this Michael -- http://mail.python.org/mailman/listin

Re: Enumerating formatting strings

2005-04-20 Thread Andrew Dalke
Michael Spencer wrote: > I have wrapped up my current understanding in the following class: I see you assume that only \w+ can fit inside of a %() in a format string. The actual Python code allows anything up to the balanced closed parens. >>> class Show: ... def __getitem__(self, text): ...

Re: Enumerating formatting strings

2005-04-20 Thread Michael Spencer
Bengt Richter wrote: On Wed, 20 Apr 2005 11:01:28 +0200, Peter Otten <[EMAIL PROTECTED]> wrote: ... "%s %(x)s %(y)s" % D() My experiments suggest that you can have a maximum of one unnamed argument in a mapping template - this unnamed value evaluates to the map itself ... So under what circumstanc

Re: Enumerating formatting strings

2005-04-20 Thread Bengt Richter
On Wed, 20 Apr 2005 11:01:28 +0200, Peter Otten <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: > >> Parse might be a big word for >> >> >> def tupreq(fmt): return sum(map(lambda s:list(s).count('%'), >> >> fmt.split('%%'))) >> .. >> >> tupreq('%s this %(x)s not %% but %s') >> >> (if it wor

Re: Enumerating formatting strings

2005-04-20 Thread Peter Otten
Bengt Richter wrote: > Parse might be a big word for > > >> def tupreq(fmt): return sum(map(lambda s:list(s).count('%'), > >> fmt.split('%%'))) > .. > >> tupreq('%s this %(x)s not %% but %s') > > (if it works in general ;-) Which it doesn't: >>> def tupreq(fmt): return sum(map(lambda s:lis

Re: Enumerating formatting strings

2005-04-20 Thread Bengt Richter
On Wed, 20 Apr 2005 09:14:40 +0200, Peter Otten <[EMAIL PROTECTED]> wrote: >Greg Ewing wrote: > >> Steve Holden wrote: >> >>> I've been wondering whether it's possible to perform a similar analysis >>> on non-mapping-type format strings, so as to know how long a tuple to >>> provide, >> >> I jus

Re: Enumerating formatting strings

2005-04-20 Thread Peter Otten
Greg Ewing wrote: > Steve Holden wrote: > >> I've been wondering whether it's possible to perform a similar analysis >> on non-mapping-type format strings, so as to know how long a tuple to >> provide, > > I just tried an experiment, and it doesn't seem to be possible. > > The problem seems to

Re: Enumerating formatting strings

2005-04-19 Thread Greg Ewing
Steve Holden wrote: I've been wondering whether it's possible to perform a similar analysis on non-mapping-type format strings, so as to know how long a tuple to provide, I just tried an experiment, and it doesn't seem to be possible. The problem seems to be that it expects the arguments to be in

Re: Enumerating formatting strings

2005-04-19 Thread Peter Otten
Steve Holden wrote: > I was messing about with formatting and realized that the right kind of > object could quite easily tell me exactly what accesses are made to the > mapping in a string % mapping operation. This is a fairly well-known > technique, modified to tell me what keys would need to be

Re: Enumerating formatting strings

2005-04-18 Thread Bengt Richter
On Mon, 18 Apr 2005 16:24:39 -0400, Steve Holden <[EMAIL PROTECTED]> wrote: >I was messing about with formatting and realized that the right kind of >object could quite easily tell me exactly what accesses are made to the >mapping in a string % mapping operation. This is a fairly well-known >te

Re: Enumerating formatting strings

2005-04-18 Thread Michael Spencer
Steve Holden wrote: I've been wondering whether it's possible to perform a similar analysis on non-mapping-type format strings, so as to know how long a tuple to provide, or whether I'd be forced to lexical analysis of the form string. regards Steve I do not know if it is possible to do that. B

Enumerating formatting strings

2005-04-18 Thread Steve Holden
I was messing about with formatting and realized that the right kind of object could quite easily tell me exactly what accesses are made to the mapping in a string % mapping operation. This is a fairly well-known technique, modified to tell me what keys would need to be present in any mapping u