Re: text formatting question

2013-03-01 Thread Chris Angelico
On Sat, Mar 2, 2013 at 12:52 AM, Dave Angel wrote: > The assumption Chris made is that the characters XYC do *not* appear > anywhere else in each string. if they do, then you need to write a spec as > to what criteria you can count on for the data. > Right. I should have mentioned that. Let's ho

Re: text formatting question

2013-03-01 Thread Dave Angel
On 03/01/2013 02:08 AM, idy wrote: On Friday, March 1, 2013 12:23:41 PM UTC+5:30, Chris Angelico wrote: You want to break the line immediately before the 'XYC'? That's quite easy; the line break is a character like any other, and can be used in a replace() call: formatted_error = Error.

Re: text formatting question

2013-02-28 Thread idy
On Friday, March 1, 2013 12:23:41 PM UTC+5:30, Chris Angelico wrote: > On Fri, Mar 1, 2013 at 5:49 PM, idy wrote: > > > Error = > > 'XYC.12345455LOcation/user/data/MYGLE-INGXYC.23344566LOcation/user/data/INGE-FTYXYC.22334566LOcation/user/data/GETN-YUNXYC.12345455LOcation/user/data/MYGLE-INGXYC.1

Re: text formatting question

2013-02-28 Thread Chris Angelico
On Fri, Mar 1, 2013 at 5:49 PM, idy wrote: > Error = > 'XYC.12345455LOcation/user/data/MYGLE-INGXYC.23344566LOcation/user/data/INGE-FTYXYC.22334566LOcation/user/data/GETN-YUNXYC.12345455LOcation/user/data/MYGLE-INGXYC.111LOcation/user/data/INGE-FTYXYC.333LOcation/user/data/GETN-YUN' > > I

text formatting question

2013-02-28 Thread idy
I have a text string of this format Error = 'XYC.12345455LOcation/user/data/MYGLE-INGXYC.23344566LOcation/user/data/INGE-FTYXYC.22334566LOcation/user/data/GETN-YUNXYC.12345455LOcation/user/data/MYGLE-INGXYC.111LOcation/user/data/INGE-FTYXYC.333LOcation/user/data/GETN-YUN' I need to writ

Re: Code formatting question: conditional expression

2009-08-26 Thread Jorgen Grahn
On Wed, 26 Aug 2009 16:47:33 +1000, Ben Finney wrote: > "Nicola Larosa (tekNico)" writes: > >> Nicola Larosa wrote: >> > Here's my take: >> > >> >     excessblk = Block(total - P.BASE, srccol, >> > carry_button_suppress=True >> >         ) if total > P.BASE else None >> >> Oops, it got shortened

Re: Code formatting question: conditional expression

2009-08-25 Thread Ben Finney
"Nicola Larosa (tekNico)" writes: > Nicola Larosa wrote: > > Here's my take: > > > >     excessblk = Block(total - P.BASE, srccol, > > carry_button_suppress=True > >         ) if total > P.BASE else None > > Oops, it got shortened out: line longer than 72 chars, acceptable in > code, but not in e

Re: Code formatting question: conditional expression

2009-08-25 Thread Nicola Larosa (tekNico)
Nicola Larosa wrote: > Here's my take: > >     excessblk = Block(total - P.BASE, srccol, > carry_button_suppress=True >         ) if total > P.BASE else None Oops, it got shortened out: line longer than 72 chars, acceptable in code, but not in email. I'll try again. If the first line is too long,

Re: Code formatting question: conditional expression

2009-08-25 Thread Nicola Larosa (tekNico)
John Posner wrote: > Is there any consensus on how to format a conditional expression > that is too long for one line? Here's my take: excessblk = Block(total - P.BASE, srccol, carry_button_suppress=True ) if total > P.BASE else None -- Nicola Larosa - http://www.tekNico.net/ Nobody

Re: Code formatting question: conditional expression

2009-08-21 Thread Aahz
In article <87ocqchl2k@benfinney.id.au>, Ben Finney wrote: >"Diez B. Roggisch" writes: >> >> excessblk = None >> if total > P.BASE: >> excessblk = ... >> >> You don't lose any vertical space, > >I don't see vertical space as such a scarce resource; we don't have an >imminent newline shor

Re: Code formatting question: conditional expression

2009-08-19 Thread John Posner
Diez wrote: No. I love them. But not if they are so large that they stretch over several lines (or to many columns). foo = bar if cond else baz is more than fine for me. But foo = I_need_to_do_something_really_complicated_here() if cond else baz isn't, because one doesn't grasp as easily in

Re: Code formatting question: conditional expression

2009-08-19 Thread Bruno Desthuilliers
Richard Brodie a écrit : "John Posner" wrote in message news:mailman.26.1250604346.2854.python-l...@python.org... if total > P.BASE: excessblk = Block(total - P.BASE, srccol, carry_button_suppress=True) else: excessblk = None I wonder if it is appropriate to replace the None sen

Re: Code formatting question: conditional expression

2009-08-19 Thread Diez B. Roggisch
> BTW, from the (admittedly few) responses to my original post, it seems > there's some sentiment that "conditional expressions" are a non-Pythonic > misfeature. Interesting ... No. I love them. But not if they are so large that they stretch over several lines (or to many columns). foo = bar if

Re: Code formatting question: conditional expression

2009-08-18 Thread John Yeung
On Aug 18, 1:25 pm, John Posner wrote: > BTW, from the (admittedly few) responses to my original > post, it seems there's some sentiment that "conditional > expressions" are a non-Pythonic misfeature. Interesting ... Well, it's not like Guido was especially eager to add it in the first place. I

Re: Code formatting question: conditional expression

2009-08-18 Thread Ben Finney
John Posner writes: > > excessblk = None > > if total > P.BASE: > > excessblk = ... > > […] > But doesn't it violate the DRY principle? The token "excessblk" > appears twice instead of once. No, the DRY principle http://c2.com/cgi/wiki?DontRepeatYourself> doesn't speak against assigning two

Re: Code formatting question: conditional expression

2009-08-18 Thread Ben Finney
"Diez B. Roggisch" writes: > excessblk = None > if total > P.BASE: > excessblk = ... > > You don't lose any vertical space, I don't see vertical space as such a scarce resource; we don't have an imminent newline shortage, to my knowledge. I value it far lower than, say, local readability. >

Re: Code formatting question: conditional expression

2009-08-18 Thread Ben Finney
John Posner writes: > Is there any consensus on how to format a conditional expression that > is too long for one line? How about this: > > excessblk = (Block(total - P.BASE, srccol, carry_button_suppress=True) > if total > P.BASE else > None) > > The above format sep

Re: Code formatting question: conditional expression

2009-08-18 Thread Jan Kaliszewski
18-08-2009 Steven D'Aprano wrote: On Tue, 18 Aug 2009 10:04:36 -0400, John Posner wrote: [snip] How about this: excessblk = (Block(total - P.BASE, srccol, carry_button_suppress=True) if total > P.BASE else None) If you insist on using the conditional expres

Re: Code formatting question: conditional expression

2009-08-18 Thread Ethan Furman
John Posner wrote: BTW, from the (admittedly few) responses to my original post, it seems there's some sentiment that "conditional expressions" are a non-Pythonic misfeature. Interesting ... -John I didn't read it that way. One of the (to me) core points of Pythonic is readability. A

Re: Code formatting question: conditional expression

2009-08-18 Thread John Posner
I wonder if it is appropriate to replace the None sentinel with one that is an instance of Block() e.g. size = total - P.BASE excessblk = Block(size, srccol, carry_button_suppress=True, empty_block=(size <= 0) ) In this particular case, Richard, I don't think so. The Block class is an a

Re: Code formatting question: conditional expression

2009-08-18 Thread Jean-Michel Pichavant
John Posner wrote: My choice would be excessblk = None if total > P.BASE: excessblk = ... Diez and Jean-Michel, Ha! Your suggestion above was my *original* coding. It looks like I'm evolving backwards! But doesn't it violate the DRY principle? The token "excessblk" appears twice ins

Re: Code formatting question: conditional expression

2009-08-18 Thread Richard Brodie
"John Posner" wrote in message news:mailman.26.1250604346.2854.python-l...@python.org... > if total > P.BASE: > excessblk = Block(total - P.BASE, srccol, carry_button_suppress=True) > else: > excessblk = None I wonder if it is appropriate to replace the None sentinel with one that

Re: Code formatting question: conditional expression

2009-08-18 Thread John Posner
My choice would be excessblk = None if total > P.BASE: excessblk = ... Diez and Jean-Michel, Ha! Your suggestion above was my *original* coding. It looks like I'm evolving backwards! But doesn't it violate the DRY principle? The token "excessblk" appears twice instead of once. Than

Re: Code formatting question: conditional expression

2009-08-18 Thread Steven D'Aprano
On Tue, 18 Aug 2009 10:04:36 -0400, John Posner wrote: > While refactoring some code, I ran across an opportunity to use a > conditional expression. Original: > > if total > P.BASE: > excessblk = Block(total - P.BASE, srccol, > carry_button_suppress=True) > else: > excessblk

Re: Code formatting question: conditional expression

2009-08-18 Thread Jean-Michel Pichavant
Diez B. Roggisch wrote: John Posner wrote: While refactoring some code, I ran across an opportunity to use a conditional expression. Original: if total > P.BASE: excessblk = Block(total - P.BASE, srccol, carry_button_suppress=True) else: excessblk = None Is there any

Re: Code formatting question: conditional expression

2009-08-18 Thread Diez B. Roggisch
John Posner wrote: > While refactoring some code, I ran across an opportunity to use a > conditional expression. Original: > > if total > P.BASE: > excessblk = Block(total - P.BASE, srccol, > carry_button_suppress=True) > else: > excessblk = None > > Is there any consensus

Code formatting question: conditional expression

2009-08-18 Thread John Posner
While refactoring some code, I ran across an opportunity to use a conditional expression. Original: if total > P.BASE: excessblk = Block(total - P.BASE, srccol, carry_button_suppress=True) else: excessblk = None Is there any consensus on how to format a conditional expression that i

Re: Beginner String formatting question

2008-01-26 Thread John Machin
On Jan 27, 7:15 am, [EMAIL PROTECTED] wrote: > I apologize for the lack of details in my last post. There is nothing to apologise for. Unlike some, you gave enough information, without prompting, to get answers to your questions. Don't go to the other extreme :-) > This time > formatting program

Re: Beginner String formatting question

2008-01-26 Thread JAMoore84
I apologize for the lack of details in my last post. This time formatting program is a piece of a larger program I am trying to write to de-clutter GPS transmission. I have a GPS receiver that transmits its readings via bluetooth. I've been able to use pySerial and store X number of bytes, then

Re: Beginner String formatting question

2008-01-26 Thread Gary Herron
[EMAIL PROTECTED] wrote: > Hi all, > > I am trying to write a simple program that will accept an integral > "time" input in the HHMMSS format and output a "HH:MM:SS" form. My > code is as follows: > > import string > > def FormatTime(time): > '''Converts an HHMMSS string

Re: Beginner String formatting question

2008-01-26 Thread chaosgy
On 1月27日, 上午1时02分, [EMAIL PROTECTED] wrote: > Hi all, > > I am trying to write a simple program that will accept an integral > "time" input in the HHMMSS format and output a "HH:MM:SS" form. My > code is as follows: > > import string > > def FormatTime(time): > '''Conver

Re: Beginner String formatting question

2008-01-26 Thread Mark Tolonen
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi all, > > I am trying to write a simple program that will accept an integral > "time" input in the HHMMSS format and output a "HH:MM:SS" form. My > code is as follows: > > import string > > def FormatTime(ti

Beginner String formatting question

2008-01-26 Thread JAMoore84
Hi all, I am trying to write a simple program that will accept an integral "time" input in the HHMMSS format and output a "HH:MM:SS" form. My code is as follows: import string def FormatTime(time): '''Converts an HHMMSS string to HH:MM:SS format.''' timeString = str

Re: simple string formatting question

2007-12-14 Thread Neil Cerutti
On 2007-12-14, Neal Becker <[EMAIL PROTECTED]> wrote: > I have a list of strings (sys.argv actually). I want to print them as a > space-delimited string (actually, the same way they went into the command > line, so I can cut and paste) > > So if I run my program like: > ./my_prog a b c d > > I wan

Re: simple string formatting question

2007-12-14 Thread Gary Herron
Neal Becker wrote: > I have a list of strings (sys.argv actually). I want to print them as a > space-delimited string (actually, the same way they went into the command > line, so I can cut and paste) > > So if I run my program like: > ./my_prog a b c d > > I want it to print: > > './my_prog' 'a'

Re: simple string formatting question

2007-12-14 Thread Bruno Desthuilliers
Neal Becker a écrit : > I have a list of strings (sys.argv actually). I want to print them as a > space-delimited string (actually, the same way they went into the command > line, so I can cut and paste) > > So if I run my program like: > ./my_prog a b c d > > I want it to print: > > './my_prog

simple string formatting question

2007-12-14 Thread Neal Becker
I have a list of strings (sys.argv actually). I want to print them as a space-delimited string (actually, the same way they went into the command line, so I can cut and paste) So if I run my program like: ./my_prog a b c d I want it to print: './my_prog' 'a' 'b' 'c' 'd' Just print sys.argv wil

Re: Formatting question.

2007-11-22 Thread M.-A. Lemburg
Dennis Lee Bieber wrote: > On Wed, 21 Nov 2007 08:36:28 -0800 (PST), mike5160 <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > >> Thanks to you for your reply. I am a newbie to Python and appreciate >> you helping me. Now, I am importing data from an excel sheet and >> getting

Re: Formatting question.

2007-11-21 Thread mike5160
On Nov 21, 11:36 am, mike5160 <[EMAIL PROTECTED]> wrote: > On Nov 21, 1:22 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > > > > > On Tue, 20 Nov 2007 15:11:38 -0800 (PST), mike5160 <[EMAIL PROTECTED]> > > declaimed the following in comp.lang.python: > > > > Hi all, > > > > My input file looks l

Re: Formatting question.

2007-11-21 Thread mike5160
On Nov 21, 1:22 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Tue, 20 Nov 2007 15:11:38 -0800 (PST), mike5160 <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > > > > > Hi all, > > > My input file looks like this : ( the data is separated by tabs ) > > > 11/26/2007 56.366

Re: Fwd: Formatting question.

2007-11-21 Thread mike5160
On Nov 20, 9:13 pm, "Sergio Correia" <[EMAIL PROTECTED]> wrote: > Hey Mike, > Welcome to Python! > > About your first issue, just change the line > outfile.write( "'%s'," % (LoL[x][y])) > With > outfile.write( "'%s'," % (LoL[x][y][:-1])) > > Why? Because when you do the line.split, you are includin

Fwd: Formatting question.

2007-11-20 Thread Sergio Correia
Hey Mike, Welcome to Python! About your first issue, just change the line outfile.write( "'%s'," % (LoL[x][y])) With outfile.write( "'%s'," % (LoL[x][y][:-1])) Why? Because when you do the line.split, you are including the '\n' at the end, so a new line is created. Now, what you are doing is not

Formatting question.

2007-11-20 Thread mike5160
Hi all, My input file looks like this : ( the data is separated by tabs ) 11/26/2007 56.366 898.90 -10.086 23.11 1212.3 11/26/2007 52.25 897.6 -12.5 12.61.5 11/26/2007 52.25 897.6 -12.5 12.6133.5 The output I'm trying to get is as follows : ( Insert N

Re: Tkinter Listbox string formatting question - how to kill a dancingsnake ?

2006-11-02 Thread Hendrik van Rooyen
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote: In the meantime, I have produced this evil hack, that takes advantage of the difference in pixel widths between the space, and either the fullstop or the single quote... It will only work if you have quite a lot of space to waste between columns, an

Re: Tkinter Listbox string formatting question - how to kill adancingsnake ?

2006-10-31 Thread Hendrik van Rooyen
"Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote: > "Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > > > instead of trying to force the listbox to behave like a multicolumn > > widget, maybe you could switch to another widget? some alternatives include > > > > a Text widget (you have to roll your

Re: Tkinter Listbox string formatting question - how to kill a dancingsnake ?

2006-10-31 Thread Hendrik van Rooyen
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > instead of trying to force the listbox to behave like a multicolumn > widget, maybe you could switch to another widget? some alternatives include > > a Text widget (you have to roll your own selection logic) I _really_ don't feel strong enough

Re: Tkinter Listbox string formatting question - how to kill a dancing snake ?

2006-10-31 Thread Fredrik Lundh
Hendrik van Rooyen wrote: > Is there a way to format this so it will line up with *any* font ? > > I would prefer not to give up and use a fixed width font - it looks so > teletypish... sounds like contradicting requirements to me. instead of trying to force the listbox to behave like a multi

Tkinter Listbox string formatting question - how to kill a dancing snake ?

2006-10-30 Thread Hendrik van Rooyen
I am populating a listbox from a directory that looks like this: variable_dict = {"funny_long_or_short_variable_name_as_key": (2,45),.. the tuple represents a "card, line" pair. medf is a font object and a forward reference here. I write: for x in variable_dict: txt = x while medf.m

Re: Simple string formatting question

2006-04-07 Thread Peter Otten
Steven D'Aprano wrote: > I have a sinking feeling I'm missing something really, > really simple. > > I'm looking for a format string similar to '%.3f' > except that trailing zeroes are not included. > > To give some examples: > > FloatString > 1.0 1 > 1.1 1.1 > 12.1234

Re: Simple string formatting question

2006-04-06 Thread Fredrik Lundh
Paul McGuire wrote: > Ooops, don't combine the two calls to rstrip(). > > def format(f, width=3): return ("%.*f" % (width, f)).rstrip(".0") > > print format(3.140) > print format(3.000) > print format(3.001) > print format(30.) > print format(30.000) hey, I'm doing test-driven develop

Re: Simple string formatting question

2006-04-06 Thread Ben Finney
"Steven D'Aprano" <[EMAIL PROTECTED]> writes: > On Thu, 06 Apr 2006 22:16:05 +1000, Ben Finney wrote: > > "Steven D'Aprano" <[EMAIL PROTECTED]> writes: 1> >> I'm looking for a format string similar to '%.3f' except that > >> trailing zeroes are not included. > > > > Can;t be done, to my knowledge

Re: Simple string formatting question

2006-04-06 Thread Steven D'Aprano
On Thu, 06 Apr 2006 22:16:05 +1000, Ben Finney wrote: > "Steven D'Aprano" <[EMAIL PROTECTED]> writes: >> I'm looking for a format string similar to '%.3f' except that >> trailing zeroes are not included. > > Can;t be done, to my knowledge. You specify a particular precision, > and the number wil

Re: Simple string formatting question

2006-04-06 Thread Paul McGuire
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Steven D'Aprano wrote: > > > Here is a (quick and dirty) reference implementation: > > > > def format(f, width=3): > > fs = '%%.%df' % width > > s = fs % f > > return s.rstrip('0').rstrip('.') > > > > Is there

Re: Simple string formatting question

2006-04-06 Thread Fredrik Lundh
Steven D'Aprano wrote: > Here is a (quick and dirty) reference implementation: > > def format(f, width=3): > fs = '%%.%df' % width > s = fs % f > return s.rstrip('0').rstrip('.') > > Is there a way of getting the same result with just a > single string format expression? not with % it

Re: Simple string formatting question

2006-04-06 Thread Ben Finney
"Steven D'Aprano" <[EMAIL PROTECTED]> writes: > I have a sinking feeling I'm missing something really, really > simple. "Oh no, everyone in the galaxy gets that, that's perfectly natural paranoia." > I'm looking for a format string similar to '%.3f' except that > trailing zeroes are not included

Simple string formatting question

2006-04-06 Thread Steven D'Aprano
I have a sinking feeling I'm missing something really, really simple. I'm looking for a format string similar to '%.3f' except that trailing zeroes are not included. To give some examples: FloatString 1.0 1 1.1 1.1 12.1234 12.123 12.0001 12 and similar. He

Re: HTML/text formatting question

2005-08-25 Thread Edvard Majakari
"Dr. Who" <[EMAIL PROTECTED]> writes: > This seems clunky and my next step was going to be to define generic > functions which would generate the surrounding html tags only when > passed the proper argument. I was wondering if there was a better way > to do this with a standard Python library. I

Re: HTML/text formatting question

2005-08-03 Thread Steven Bethard
Dr. Who wrote: > I have a tool that outputs data in either html or text output. > > Currently I'm writing chucnks like: > > if html: > print '' > print '' > print '' > print 'Differences %s: %s' % (htypestr, lbl1) > if html: > ... I'd create two Formatter classes, one for HTML

HTML/text formatting question

2005-08-03 Thread Dr. Who
I have a tool that outputs data in either html or text output. Currently I'm writing chucnks like: if html: print '' print '' print '' print 'Differences %s: %s' % (htypestr, lbl1) if html: ... This seems clunky and my next step was going to be to define generic functions whi