[FRPythoneers] dynamically created format strings?

Brian Jarrett bjarrett at garcoschools.org
Mon Jan 26 13:51:51 MST 2004


Yep, that's it.  Thanks!

I figured there was a quick way to do that, just hadn't looked into it enough.

Brian

> -----Original Message-----
> From: Sean Reifschneider [mailto:jafo at tummy.com]
> Sent: Monday, January 26, 2004 11:39 AM
> To: Front Range Python Users -- General Discussion
> Subject: Re: [FRPythoneers] dynamically created format strings?
> 
> 
> On Mon, Jan 26, 2004 at 09:22:40AM -0700, Brian Jarrett wrote:
> >iRight now I have a separate function created for each name and
> >just pass it the data.  Also, I have do deal with alot of numbers,
> >so I use format strings in separate functions like "%02d" and "%010d"
> >to zero-pad numbers.  I'd like to just to be able to pass 
> the number in
> >and an integer representing how many digits should be used.
> 
> If I understand you correctly:
> 
>    >>> def foo(size, value): return(('%%0%dd' % size) % value)
>    ... 
>    >>> print foo(10, 1)
>    0000000001
>    >>> print foo(5, 10)
>    00010
> 
> %% gets replaced by % in format string expansion, so the 
> "'%%0%dd' % 10"
> changes into '%010d'.
> 
> Sean
> -- 
>  A "fuddish" is when you *REALLY* like Looney Toons.
> Sean Reifschneider, Member of Technical Staff <jafo at tummy.com>
> tummy.com, ltd. - Linux Consulting since 1995.  Qmail, 
> Python, SysAdmin
>       Back off man. I'm a scientist.   http://HackingSociety.org/
> _______________________________________________
> This message sent by the FRPythoneers mailing list.
> Unsubscribe: echo unsubscribe | 
> FRPythoneers-request at lists.community.tummy.com
> URL: http://lists.community.tummy.com/mailman/listinfo/frpythoneers
> 



More information about the FRPythoneers mailing list