Re: Formatted Output and Argument Parsing (was: Re: Flubbed it in the second interation through the string: range error... HOW?)

2024-05-29 Thread Chris Angelico via Python-list
On Wed, 29 May 2024 at 23:06, Dan Sommers via Python-list wrote: > (For the history-impaired, getopt existed long before Python and will > likely exist long after it, but getopt's "replacement" optparse lasted > only from 2003 until 2011.) Depends on your definition of "lasted". It's not getting

Formatted Output and Argument Parsing (was: Re: Flubbed it in the second interation through the string: range error... HOW?)

2024-05-29 Thread Dan Sommers via Python-list
On 2024-05-29 at 17:14:51 +1000, Chris Angelico via Python-list wrote: > I wouldn't replace str.format() everywhere, nor would I replace > percent encoding everywhere - but in this case, I think Thomas is > correct. Not because it's 2024 (f-strings were brought in back in > 2015, so they're hardl

Re: formatted output

2013-05-07 Thread Peter Otten
Roy Smith wrote: > In article , > Sudheer Joseph wrote: > >> Dear members, >> I need to print few arrays in a tabular form for example >> below array IL has 25 elements, is there an easy way to print >> this as 5x5 comma separated table? in python >> >> IL=[

Re: formatted output

2013-05-07 Thread Roy Smith
In article , Sudheer Joseph wrote: > Dear members, > I need to print few arrays in a tabular form for example below > array IL has 25 elements, is there an easy way to print this as > 5x5 comma separated table? in python > > IL=[] > for i in np.arange(1,bno

formatted output

2013-05-07 Thread Sudheer Joseph
Dear members, I need to print few arrays in a tabular form for example below array IL has 25 elements, is there an easy way to print this as 5x5 comma separated table? in python IL=[] for i in np.arange(1,bno+1): IL.append(i) print(IL) %

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,

Re: newbie question concerning formatted output

2005-11-30 Thread Thomas Liesner
Hi all, thanks for all your answers. Is see that there are - as ususal - several ways to accomplish this. I decided to go for the way Frederik suggested, because it looked as the most straight forward method for that kind of data. Thanks again, ./Tom -- http://mail.python.org/mailman/listinfo/py

Re: newbie question concerning formatted output

2005-11-29 Thread Bengt Richter
On Tue, 29 Nov 2005 17:40:08 GMT, Thomas Liesner <[EMAIL PROTECTED]> wrote: [...] >This is the codesnippet i am using: Sorry, I made no comment on your actual code. Some follows. > >#!/usr/bin/python > >import string I'm not seeing the need for importing string >inp = open("xyplan.nobreaks","r")

Re: newbie question concerning formatted output

2005-11-29 Thread Bengt Richter
On Tue, 29 Nov 2005 17:40:08 GMT, Thomas Liesner <[EMAIL PROTECTED]> wrote: >Hello all, > >i am having some hard time to format the output of my small script. I am >opening a file which containes just a very long string of hexdata >seperated by spaces. Using split() i can split this string into si

Re: newbie question concerning formatted output

2005-11-29 Thread Scott David Daniels
Thomas Liesner wrote: > ... i want to print always three of them in a single line and > after that a linebreak. How about: def emit(aFile): for line in aFile: for word in line.split(): yield word f = open('xyplan.nobreaks', 'r') gen = iter(

Re: newbie question concerning formatted output

2005-11-29 Thread dwelch
Thomas Liesner wrote: > Hello all, > > i am having some hard time to format the output of my small script. I am > opening a file which containes just a very long string of hexdata > seperated by spaces. Using split() i can split this string into single > words and print them on stdout. So far so g

Re: newbie question concerning formatted output

2005-11-29 Thread Patrick Down
>>> a = [str(i) for i in range(0,17)] >>> for i in range(0,len(a),3): ... print " ".join(a[i:i+3]) ... 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie question concerning formatted output

2005-11-29 Thread Micah Elliott
On Nov 29, Fredrik Lundh wrote: > inp = open("xyplan.nobreaks","r") > data = inp.read() > > import textwrap > for line in textwrap.wrap(data, 15): > print line Right -- if the data is that regular then every 15th item is the split-point. A variation on this theme then is: for i in range

Re: newbie question concerning formatted output

2005-11-29 Thread Fredrik Lundh
Thomas Liesner wrote: > i am having some hard time to format the output of my small script. I am > opening a file which containes just a very long string of hexdata > seperated by spaces. Using split() i can split this string into single > words and print them on stdout. So far so good. But i want

Re: newbie question concerning formatted output

2005-11-29 Thread [EMAIL PROTECTED]
You can try something like: #!/usr/bin/python import sys inp = open("xyplan.nobreaks") data = [ i.strip() for i in inp if i ] while data: print ' '.join(data[0:3]) del data[0:3] -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie question concerning formatted output

2005-11-29 Thread Dave Hansen
On Tue, 29 Nov 2005 17:40:08 GMT in comp.lang.python, Thomas Liesner <[EMAIL PROTECTED]> wrote: [...]> >So instead of: > >3905 >3009 > [...] > >i'd like to have: > >3905 3009 [...] > >This is the codesnippet i am using: > >#!/usr/bin/python > >import string >inp = open("xyplan.nobreaks","r

Re: newbie question concerning formatted output

2005-11-29 Thread Dennis Benzinger
Thomas Liesner schrieb: > [...] > i am having some hard time to format the output of my small script. I am > opening a file which containes just a very long string of hexdata > seperated by spaces. Using split() i can split this string into single > words and print them on stdout. So far so good. B

newbie question concerning formatted output

2005-11-29 Thread Thomas Liesner
Hello all, i am having some hard time to format the output of my small script. I am opening a file which containes just a very long string of hexdata seperated by spaces. Using split() i can split this string into single words and print them on stdout. So far so good. But i want to print always th