Re: String formatters with variable argument length

2006-12-01 Thread John Machin
Peter Otten wrote: > John Machin wrote: > > >> > Fredrik Tolf wrote: > > >> > > The thing is, I want to get format strings from the user, and I don't > >> > > want to require the user to consume all the arguments. > > > what's ugly about this: > > [untested]: > > > > def count_format_args(s): > >

Re: String formatters with variable argument length

2006-12-01 Thread Peter Otten
John Machin wrote: >> > Fredrik Tolf wrote: >> > > The thing is, I want to get format strings from the user, and I don't >> > > want to require the user to consume all the arguments. > what's ugly about this: > [untested]: > > def count_format_args(s): > pending = False > count = 0 >

Re: String formatters with variable argument length

2006-11-30 Thread John Machin
Fredrik Tolf wrote: > On Thu, 2006-11-30 at 16:26 -0800, John Machin wrote: > > Fredrik Tolf wrote: > [...] > > > The thing is, I want to get format strings from the user, and I don't > > > want to require the user to consume all the arguments. docs.python.org > > > doesn't seem to have any clues o

Re: String formatters with variable argument length

2006-11-30 Thread Matimus
> Could it be as I fear, that it is impossible? p'shaw, you underestimate the power of the Python... I think this is a poor solution (I would go with the solution in John Machin's second post) but here it is anyway since it does essentially what you asked for: [code] def print_data(fmtstr):

Re: String formatters with variable argument length

2006-11-30 Thread Fredrik Tolf
On Thu, 2006-11-30 at 16:26 -0800, John Machin wrote: > Fredrik Tolf wrote: [...] > > The thing is, I want to get format strings from the user, and I don't > > want to require the user to consume all the arguments. docs.python.org > > doesn't seem to have any clues on how to achieve this, and I can

Re: String formatters with variable argument length

2006-11-30 Thread John Machin
John Machin wrote: > Fredrik Tolf wrote: > > I've been trying to get the string formatting operator (%) to work with > > more arguments than the format string requires, but I can find no way to > > do that. For example: > > > > >>> "%i" % 10 > > '10' > > >>> "i" % 10 > > Traceback (most recent cal

Re: String formatters with variable argument length

2006-11-30 Thread John Machin
Fredrik Tolf wrote: > I've been trying to get the string formatting operator (%) to work with > more arguments than the format string requires, but I can find no way to > do that. For example: > > >>> "%i" % 10 > '10' > >>> "i" % 10 > Traceback (most recent call last): > File "", line 1, in ? > T

Re: String formatters with variable argument length

2006-11-30 Thread [EMAIL PROTECTED]
How do you know which ones to use? Your best bet is to write a handler for the TypeError and give a meaningful error message. Fredrik Tolf wrote: > I've been trying to get the string formatting operator (%) to work with > more arguments than the format string requires, but I can find no way to > d

String formatters with variable argument length

2006-11-30 Thread Fredrik Tolf
I've been trying to get the string formatting operator (%) to work with more arguments than the format string requires, but I can find no way to do that. For example: >>> "%i" % 10 '10' >>> "i" % 10 Traceback (most recent call last): File "", line 1, in ? TypeError: not all arguments converted d