Re: Creating formatted output using picture strings

2010-02-10 Thread John Posner
On 2/10/2010 2:57 PM, Grant Edwards wrote: On 2010-02-10, pyt...@bdurham.com wrote: [regardning "picture" output format specifiers] I was thinking that there was a built-in function for this common(?) use case I haven't seen that paradigm since my one-and-only exposure to COBOL in a class I

Re: Creating formatted output using picture strings

2010-02-10 Thread Chris Rebert
On Wed, Feb 10, 2010 at 12:19 PM, sstein...@gmail.com wrote: > On Feb 10, 2010, at 2:57 PM, Grant Edwards wrote: >> On 2010-02-10, pyt...@bdurham.com wrote: >> >> [regardning "picture" output format specifiers] >> >>> I was thinking that there was a built-in function for this >>> common(?) use ca

Re: Creating formatted output using picture strings

2010-02-10 Thread sstein...@gmail.com
On Feb 10, 2010, at 3:40 PM, Grant Edwards wrote: > On 2010-02-10, sstein...@gmail.com wrote: >> On Feb 10, 2010, at 2:57 PM, Grant Edwards wrote: >> >>> On 2010-02-10, pyt...@bdurham.com wrote: >>> >>> [regardning "picture" output format specifiers] >>> I was thinking that there was a

Re: Creating formatted output using picture strings

2010-02-10 Thread Grant Edwards
On 2010-02-10, sstein...@gmail.com wrote: > On Feb 10, 2010, at 2:57 PM, Grant Edwards wrote: > >> On 2010-02-10, pyt...@bdurham.com wrote: >> >> [regardning "picture" output format specifiers] >> >>> I was thinking that there was a built-in function for this >>> common(?) use case >> >> I hav

Re: Creating formatted output using picture strings

2010-02-10 Thread Tim Chase
Grant Edwards wrote: [regardning "picture" output format specifiers] I was thinking that there was a built-in function for this common(?) use case I haven't seen that paradigm since my one-and-only exposure to COBOL in a class I took back in 1979. Is the "picture" thing commonly used in other

Re: Creating formatted output using picture strings

2010-02-10 Thread sstein...@gmail.com
On Feb 10, 2010, at 2:57 PM, Grant Edwards wrote: > On 2010-02-10, pyt...@bdurham.com wrote: > > [regardning "picture" output format specifiers] > >> I was thinking that there was a built-in function for this >> common(?) use case > > I haven't seen that paradigm since my one-and-only exposure

Re: Creating formatted output using picture strings

2010-02-10 Thread Grant Edwards
On 2010-02-10, pyt...@bdurham.com wrote: [regardning "picture" output format specifiers] > I was thinking that there was a built-in function for this > common(?) use case I haven't seen that paradigm since my one-and-only exposure to COBOL in a class I took back in 1979. Is the "picture" thing

Re: Creating formatted output using picture strings

2010-02-10 Thread MRAB
Tim Chase wrote: pyt...@bdurham.com wrote: Original poster here. Thank you all for your ideas. I certainly learned some great techniques by studying everyone's solutions!! Thanks for the positive feedback -- it's something most folks like to hear when they try to assist and such thanks appea

Re: Creating formatted output using picture strings

2010-02-10 Thread donn
On 10/02/2010 20:36, pyt...@bdurham.com wrote: def picture(s, pic, placeholder='@'): nextchar=iter(s).next return ''.join(nextchar() if i == placeholder else i for i in pic) Hell's teeth - even I understood that! Amazing solution. \d -- Fonty Python and Things! -- http://otherwise.re

Re: Creating formatted output using picture strings

2010-02-10 Thread python
needed to learn :) Thanks again! Malcolm - Original message - From: "Arnaud Delobelle" To: python-list@python.org Date: Wed, 10 Feb 2010 18:21:35 +0000 Subject: Re: Creating formatted output using picture strings pyt...@bdurham.com writes: > Original poster here. > &g

Re: Creating formatted output using picture strings

2010-02-10 Thread python
Hi Tim, Thank you very much for your update to MRAB's creative solution. > You don't give the expected output for these test cases, so > it's hard to tell whether you want to pad-left or pad-right. To be honest, I wasn't sure myself :) My original post was the result of doing some simple forma

Re: Creating formatted output using picture strings

2010-02-10 Thread Arnaud Delobelle
pyt...@bdurham.com writes: > Original poster here. > > Thank you all for your ideas. I certainly learned some great techniques > by studying everyone's solutions!! > > I was thinking that there was a built-in function for this common(?) use > case which is why I shied away from writing my own in t

Re: Creating formatted output using picture strings

2010-02-10 Thread Tim Chase
pyt...@bdurham.com wrote: Original poster here. Thank you all for your ideas. I certainly learned some great techniques by studying everyone's solutions!! Thanks for the positive feedback -- it's something most folks like to hear when they try to assist and such thanks appears too rarely on

Re: Creating formatted output using picture strings

2010-02-10 Thread python
Original poster here. Thank you all for your ideas. I certainly learned some great techniques by studying everyone's solutions!! I was thinking that there was a built-in function for this common(?) use case which is why I shied away from writing my own in the first place ... hoping to not-reinven

Re: Creating formatted output using picture strings

2010-02-10 Thread Stephen Hansen
On Wed, Feb 10, 2010 at 1:45 AM, Peter Otten <__pete...@web.de> wrote: > A basic implementation without regular expressions: > > >>> def picture(s, pic, placeholder="@"): > ... parts = pic.split(placeholder) > ... result = [None]*(len(parts)+len(s)) > ... result[::2] = parts > ...

Re: Creating formatted output using picture strings

2010-02-10 Thread MRAB
Olof Bjarnason wrote: 2010/2/10 Peter Otten <__pete...@web.de>: pyt...@bdurham.com wrote: Does Python provide a way to format a string according to a 'picture' format? For example, if I have a string '123456789' and want it formatted like '(123)-45-(678)[9]', is there a module or function tha

Re: Creating formatted output using picture strings

2010-02-10 Thread Olof Bjarnason
2010/2/10 Alf P. Steinbach : > * Olof Bjarnason: >> >> 2010/2/10 Peter Otten <__pete...@web.de>: >>> >>> pyt...@bdurham.com wrote: >>> Does Python provide a way to format a string according to a 'picture' format? For example, if I have a string '123456789' and want it formatted

Re: Creating formatted output using picture strings

2010-02-10 Thread Alf P. Steinbach
* Olof Bjarnason: 2010/2/10 Peter Otten <__pete...@web.de>: pyt...@bdurham.com wrote: Does Python provide a way to format a string according to a 'picture' format? For example, if I have a string '123456789' and want it formatted like '(123)-45-(678)[9]', is there a module or function that wi

Re: Creating formatted output using picture strings

2010-02-10 Thread Olof Bjarnason
2010/2/10 Peter Otten <__pete...@web.de>: > pyt...@bdurham.com wrote: > >> Does Python provide a way to format a string according to a >> 'picture' format? >> >> For example, if I have a string '123456789' and want it formatted >> like '(123)-45-(678)[9]', is there a module or function that will >>

Re: Creating formatted output using picture strings

2010-02-10 Thread Peter Otten
pyt...@bdurham.com wrote: > Does Python provide a way to format a string according to a > 'picture' format? > > For example, if I have a string '123456789' and want it formatted > like '(123)-45-(678)[9]', is there a module or function that will > allow me to do this or do I need to code this typ

Re: Creating formatted output using picture strings

2010-02-09 Thread Stephen Hansen
On Tue, Feb 9, 2010 at 8:45 PM, wrote: > Does Python provide a way to format a string according to a 'picture' > format? > > For example, if I have a string '123456789' and want it formatted like > '(123)-45-(678)[9]', is there a module or function that will allow me to do > this or do I need to

Creating formatted output using picture strings

2010-02-09 Thread python
Does Python provide a way to format a string according to a 'picture' format? For example, if I have a string '123456789' and want it formatted like '(123)-45-(678)[9]', is there a module or function that will allow me to do this or do I need to code this type of transformation myself? Thank you,