Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #77002 > unrolled thread
| Started by | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| First post | 2014-08-25 16:14 -0400 |
| Last post | 2014-08-26 14:50 -0400 |
| Articles | 13 on this page of 33 — 14 participants |
Back to article view | Back to comp.lang.python
This formating is really tricky Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-25 16:14 -0400
Re: This formating is really tricky Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-25 21:52 +0100
Re: This formating is really tricky Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-25 23:12 -0400
Re: This formating is really tricky Rustom Mody <rustompmody@gmail.com> - 2014-08-25 14:05 -0700
Re: This formating is really tricky Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-25 23:14 -0400
Re: This formating is really tricky Larry Hudson <orgnut@yahoo.com> - 2014-08-26 23:46 -0700
Re: This formating is really tricky Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-27 09:36 -0400
Re: This formating is really tricky Terry Reedy <tjreedy@udel.edu> - 2014-08-25 18:22 -0400
Re: This formating is really tricky Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-25 20:51 -0400
Re: This formating is really tricky Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-25 21:16 -0400
Re: This formating is really tricky Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-26 15:31 -0400
Re: This formating is really tricky Peter Otten <__peter__@web.de> - 2014-08-27 09:16 +0200
Re: This formating is really tricky Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-27 09:35 -0400
Re: This formating is really tricky Peter Otten <__peter__@web.de> - 2014-08-26 00:48 +0200
Re: This formating is really tricky Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-25 20:52 -0400
Re: This formating is really tricky Joel Goldstick <joel.goldstick@gmail.com> - 2014-08-25 21:10 -0400
Re: This formating is really tricky Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-08-26 18:17 +1200
Re: This formating is really tricky Chris Angelico <rosuav@gmail.com> - 2014-08-26 16:22 +1000
Re: This formating is really tricky alister <alister.nospam.ware@ntlworld.com> - 2014-08-26 09:27 +0000
Re: This formating is really tricky Marko Rauhamaa <marko@pacujo.net> - 2014-08-26 12:32 +0300
Re: This formating is really tricky alister <alister.nospam.ware@ntlworld.com> - 2014-08-26 10:32 +0000
Re: This formating is really tricky Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-26 06:57 +0100
Re: This formating is really tricky MRAB <python@mrabarnett.plus.com> - 2014-08-26 12:24 +0100
Re: This formating is really tricky Joel Goldstick <joel.goldstick@gmail.com> - 2014-08-26 09:28 -0400
Re: This formating is really tricky Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-26 17:09 +0100
Re: This formating is really tricky Chris Angelico <rosuav@gmail.com> - 2014-08-27 02:13 +1000
Re: This formating is really tricky Peter Otten <__peter__@web.de> - 2014-08-26 18:28 +0200
Re: This formating is really tricky Chris Angelico <rosuav@gmail.com> - 2014-08-27 02:33 +1000
Re: This formating is really tricky Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-26 18:19 +0100
Re: This formating is really tricky Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-08-27 09:39 +1200
Re: This formating is really tricky Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-26 12:45 +1000
Re: This formating is really tricky Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-25 23:10 -0400
Re: This formating is really tricky Gene Heskett <gheskett@wdtv.com> - 2014-08-26 14:50 -0400
Page 2 of 2 — ← Prev page 1 [2]
| From | alister <alister.nospam.ware@ntlworld.com> |
|---|---|
| Date | 2014-08-26 10:32 +0000 |
| Message-ID | <HmZKv.75533$rb.65301@fx16.am4> |
| In reply to | #77034 |
On Tue, 26 Aug 2014 12:32:14 +0300, Marko Rauhamaa wrote: > alister <alister.nospam.ware@ntlworld.com>: > >> Oh Wow I didn't know Python was that old - it even pre-dates >> Electricity :-) > > Electricity arose already before the Great Inflation. > > > Marko but it was not in controlled use by mankind at that time -- Whip me. Beat me. Make me maintain AIX. -- Stephan Zielinski
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-08-26 06:57 +0100 |
| Message-ID | <mailman.13440.1409032651.18130.python-list@python.org> |
| In reply to | #77012 |
On 26/08/2014 02:10, Joel Goldstick wrote: > you should try python-tudor mailing list > I'd try python-stewart and please don't top post, you've been around long enough and ought to know better :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2014-08-26 12:24 +0100 |
| Message-ID | <mailman.13451.1409052269.18130.python-list@python.org> |
| In reply to | #77012 |
On 2014-08-26 06:57, Mark Lawrence wrote: > On 26/08/2014 02:10, Joel Goldstick wrote: >> you should try python-tudor mailing list >> > > I'd try python-stewart and please don't top post, you've been around > long enough and ought to know better :) > Should that be "python-stuart"?
[toc] | [prev] | [next] | [standalone]
| From | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| Date | 2014-08-26 09:28 -0400 |
| Message-ID | <mailman.13453.1409059720.18130.python-list@python.org> |
| In reply to | #77012 |
>>> you should try python-tudor mailing list >>> >> >> I'd try python-stewart and please don't top post, you've been around >> long enough and ought to know better :) >> > Should that be "python-stuart"? > -- > https://mail.python.org/mailman/listinfo/python-list Glad I could add to the discussion -- Joel Goldstick http://joelgoldstick.com
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-08-26 17:09 +0100 |
| Message-ID | <mailman.13463.1409069405.18130.python-list@python.org> |
| In reply to | #77012 |
On 26/08/2014 12:24, MRAB wrote: > On 2014-08-26 06:57, Mark Lawrence wrote: >> On 26/08/2014 02:10, Joel Goldstick wrote: >>> you should try python-tudor mailing list >>> >> >> I'd try python-stewart and please don't top post, you've been around >> long enough and ought to know better :) >> > Should that be "python-stuart"? I'm not sure which is the UK version and which is the US version, can others assist? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-08-27 02:13 +1000 |
| Message-ID | <mailman.13464.1409069627.18130.python-list@python.org> |
| In reply to | #77012 |
On Wed, Aug 27, 2014 at 2:09 AM, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote: > On 26/08/2014 12:24, MRAB wrote: >> >> On 2014-08-26 06:57, Mark Lawrence wrote: >>> >>> On 26/08/2014 02:10, Joel Goldstick wrote: >>>> >>>> you should try python-tudor mailing list >>>> >>> >>> I'd try python-stewart and please don't top post, you've been around >>> long enough and ought to know better :) >>> >> Should that be "python-stuart"? > > > I'm not sure which is the UK version and which is the US version, can others > assist? According to Wikipedia, the name spelling was changed at some point. So both are correct. We're now beautifully off-topic, but hey, that's what python-list seems to do best... ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2014-08-26 18:28 +0200 |
| Message-ID | <mailman.13466.1409070520.18130.python-list@python.org> |
| In reply to | #77012 |
MRAB wrote: > On 2014-08-26 06:57, Mark Lawrence wrote: >> On 26/08/2014 02:10, Joel Goldstick wrote: >>> you should try python-tudor mailing list >>> >> >> I'd try python-stewart and please don't top post, you've been around >> long enough and ought to know better :) >> > Should that be "python-stuart"? No, "python-flight-attendant" ;) http://xkcd.com/353/
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-08-27 02:33 +1000 |
| Message-ID | <mailman.13467.1409070788.18130.python-list@python.org> |
| In reply to | #77012 |
On Wed, Aug 27, 2014 at 2:28 AM, Peter Otten <__peter__@web.de> wrote: > No, "python-flight-attendant" ;) > > http://xkcd.com/353/ Would be nice if that could be made Python 3 compatible. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-08-26 18:19 +0100 |
| Message-ID | <mailman.13472.1409073565.18130.python-list@python.org> |
| In reply to | #77012 |
On 26/08/2014 17:33, Chris Angelico wrote: > On Wed, Aug 27, 2014 at 2:28 AM, Peter Otten <__peter__@web.de> wrote: >> No, "python-flight-attendant" ;) >> >> http://xkcd.com/353/ > > Would be nice if that could be made Python 3 compatible. > > ChrisA > Easy. from __past__ import print_statement (untested) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Gregory Ewing <greg.ewing@canterbury.ac.nz> |
|---|---|
| Date | 2014-08-27 09:39 +1200 |
| Message-ID | <c64d3rF4bm5U1@mid.individual.net> |
| In reply to | #77059 |
Mark Lawrence wrote: > from __past__ import print_statement (untested) I don't think the PEP for the __past__ module has been accepted yet, so you'd have to precede that with from __future__ import __past__ -- Greg
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2014-08-26 12:45 +1000 |
| Message-ID | <53fbf4da$0$29981$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #77002 |
Seymore4Head wrote:
> import random
> sets=3
> for x in range(0, sets):
> pb1=random.choice([1,2,3,4,5,6,7,8,9,10 [...] 52,53])
> pb2=random.choice([1-53])
You can avoid the annoyance of typing out long lists of sequential numbers
by using the range() function. And you can avoid writing out the same value
over and over again by giving it a name. So:
numbers = list(range(1, 54)) # 1 is included, 54 is excluded.
random.choice(numbers)
will randomly select a number between 1 and 53 inclusive.
random.choice([1-53]) doesn't do what you hope. It calculates 1-53 which
gives -52, puts that inside a list [-52], then randomly chooses one of the
items in the list -- the *only* item in the list, -52 every single time.
Having said all that, *none* of the above code is relevant to your subject
line. Yes, formatting is tricky, but nothing seen so far is about
formatting.
A well-designed program should be like a sandwich, not a stew. If I have a
problem with a stew, there's no individual parts that I can easily point
to. "The stew doesn't taste nice, please fix it." There's not a lot to go
by. "Doesn't taste nice" could mean anything, and the only way to
understand the stew is to consider *everything*, from the start to the
finish, and that's hard work.
But consider a sandwich: "When I put the bread on the tomato, it keeps
falling off. Here is my tomato, why won't the bread stay on?" Answer: you
forgot to slice the tomato. It's easy to see, because you can ignore the
lettuce and the cheese and meat and the pickles and just look at the tomato
in isolation of everything else, and it's obvious.
In this case, the trick is to isolate the parts of your code that are to do
with formatting, and ignore everything else. That might mean writing a new,
smaller program. This will actually help you to understand what is going
on, by digesting it in small chunks, rather than everything at once.
So we come to the next part:
> alist = sorted([pb1, pb2, pb3, pb4, pb5])
> print ("Your numbers: {} Powerball: {}".format(alist, pb6))
There is no need to show all the stuff about selecting random numbers, or
that this is in a loop, or any of that. (Although, in this case you've
hopefully inadvertently learned something by doing so, in another case you
may just cause people reading to say "that's too hard, I'm too busy to read
all that code" and your question goes unanswered.) But the *real* reason to
learn to isolate the fault is that fault isolation is an essential skill
that you, as a programmer, will need all through your career.
Since the problem is with formatting, we can isolate the fault to just the
formatting:
print("Your numbers: {} Powerball: {}".format([1, 2, 3, 4, 5], 23))
print("Your numbers: {} Powerball: {}".format([11, 21, 31, 41, 51], 7))
And the results are:
Your numbers: [1, 2, 3, 4, 5] Powerball: 23
Your numbers: [11, 21, 31, 41, 51] Powerball: 7
They certainly don't line up. Did you expect them to? How is the first print
line supposed to know how far apart to space the numbers to match the
second print line?
Let's simplify even further:
print("Powerball: {}".format(23))
print("Powerball: {}".format(7))
which gives:
Powerball: 23
Powerball: 7
but we want the numbers to line up on the right, not the left. It's not
obvious how to do that, the formatting mini-language is a bit obscure, but
by reading the documentation, a bit of guesswork from half-remembered bits
and pieces, trial and error, and/or asking someone else, I came up with:
print("Powerball: {: >2}".format(23))
print("Powerball: {: >2}".format(7))
Powerball: 23
Powerball: 7
Success! The " >2" part of the format code inside the {} means to format the
value using two columns, padding with spaces on the left if needed.
So now we can format five columns for the five numbers, plus the powerball:
template = "Numbers: {: >2} {: >2} {: >2} {: >2} {: >2} Powerball: {: >2}"
print(template.format(1, 2, 3, 4, 5, 23))
print(template.format(11, 21, 31, 41, 51, 7))
which gives:
Numbers: 1 2 3 4 5 Powerball: 23
Numbers: 11 21 31 41 51 Powerball: 7
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2014-08-25 23:10 -0400 |
| Message-ID | <13unv9psfs9nabv3llerpkm0grahkdn1ij@4ax.com> |
| In reply to | #77018 |
On Tue, 26 Aug 2014 12:45:45 +1000, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
>Seymore4Head wrote:
>
>> import random
>> sets=3
>> for x in range(0, sets):
>> pb1=random.choice([1,2,3,4,5,6,7,8,9,10 [...] 52,53])
>> pb2=random.choice([1-53])
>
>You can avoid the annoyance of typing out long lists of sequential numbers
>by using the range() function. And you can avoid writing out the same value
>over and over again by giving it a name. So:
>
>numbers = list(range(1, 54)) # 1 is included, 54 is excluded.
>random.choice(numbers)
>
>will randomly select a number between 1 and 53 inclusive.
>
>random.choice([1-53]) doesn't do what you hope. It calculates 1-53 which
>gives -52, puts that inside a list [-52], then randomly chooses one of the
>items in the list -- the *only* item in the list, -52 every single time.
>
>Having said all that, *none* of the above code is relevant to your subject
>line. Yes, formatting is tricky, but nothing seen so far is about
>formatting.
>
>A well-designed program should be like a sandwich, not a stew. If I have a
>problem with a stew, there's no individual parts that I can easily point
>to. "The stew doesn't taste nice, please fix it." There's not a lot to go
>by. "Doesn't taste nice" could mean anything, and the only way to
>understand the stew is to consider *everything*, from the start to the
>finish, and that's hard work.
>
>But consider a sandwich: "When I put the bread on the tomato, it keeps
>falling off. Here is my tomato, why won't the bread stay on?" Answer: you
>forgot to slice the tomato. It's easy to see, because you can ignore the
>lettuce and the cheese and meat and the pickles and just look at the tomato
>in isolation of everything else, and it's obvious.
>
>In this case, the trick is to isolate the parts of your code that are to do
>with formatting, and ignore everything else. That might mean writing a new,
>smaller program. This will actually help you to understand what is going
>on, by digesting it in small chunks, rather than everything at once.
>
>So we come to the next part:
>
>> alist = sorted([pb1, pb2, pb3, pb4, pb5])
>> print ("Your numbers: {} Powerball: {}".format(alist, pb6))
>
>There is no need to show all the stuff about selecting random numbers, or
>that this is in a loop, or any of that. (Although, in this case you've
>hopefully inadvertently learned something by doing so, in another case you
>may just cause people reading to say "that's too hard, I'm too busy to read
>all that code" and your question goes unanswered.) But the *real* reason to
>learn to isolate the fault is that fault isolation is an essential skill
>that you, as a programmer, will need all through your career.
>
>Since the problem is with formatting, we can isolate the fault to just the
>formatting:
>
>print("Your numbers: {} Powerball: {}".format([1, 2, 3, 4, 5], 23))
>print("Your numbers: {} Powerball: {}".format([11, 21, 31, 41, 51], 7))
>
>And the results are:
>
>Your numbers: [1, 2, 3, 4, 5] Powerball: 23
>Your numbers: [11, 21, 31, 41, 51] Powerball: 7
>
>They certainly don't line up. Did you expect them to? How is the first print
>line supposed to know how far apart to space the numbers to match the
>second print line?
>
>Let's simplify even further:
>
>print("Powerball: {}".format(23))
>print("Powerball: {}".format(7))
>
>which gives:
>
>Powerball: 23
>Powerball: 7
>
>but we want the numbers to line up on the right, not the left. It's not
>obvious how to do that, the formatting mini-language is a bit obscure, but
>by reading the documentation, a bit of guesswork from half-remembered bits
>and pieces, trial and error, and/or asking someone else, I came up with:
>
>print("Powerball: {: >2}".format(23))
>print("Powerball: {: >2}".format(7))
>
>Powerball: 23
>Powerball: 7
>
>Success! The " >2" part of the format code inside the {} means to format the
>value using two columns, padding with spaces on the left if needed.
>
>So now we can format five columns for the five numbers, plus the powerball:
>
>template = "Numbers: {: >2} {: >2} {: >2} {: >2} {: >2} Powerball: {: >2}"
>print(template.format(1, 2, 3, 4, 5, 23))
>print(template.format(11, 21, 31, 41, 51, 7))
>
>which gives:
>
>Numbers: 1 2 3 4 5 Powerball: 23
>Numbers: 11 21 31 41 51 Powerball: 7
Thank you
I will give these a try.
[toc] | [prev] | [next] | [standalone]
| From | Gene Heskett <gheskett@wdtv.com> |
|---|---|
| Date | 2014-08-26 14:50 -0400 |
| Message-ID | <mailman.13476.1409079047.18130.python-list@python.org> |
| In reply to | #77002 |
On Tuesday 26 August 2014 12:13:37 Chris Angelico did opine And Gene did reply: > On Wed, Aug 27, 2014 at 2:09 AM, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote: > > On 26/08/2014 12:24, MRAB wrote: > >> On 2014-08-26 06:57, Mark Lawrence wrote: > >>> On 26/08/2014 02:10, Joel Goldstick wrote: > >>>> you should try python-tudor mailing list > >>> > >>> I'd try python-stewart and please don't top post, you've been > >>> around long enough and ought to know better :) > >> > >> Should that be "python-stuart"? > > > > I'm not sure which is the UK version and which is the US version, can > > others assist? > > According to Wikipedia, the name spelling was changed at some point. > So both are correct. We're now beautifully off-topic, but hey, that's > what python-list seems to do best... > > ChrisA And that is what you folks to best, when trying to out-standup the last poster. Then it gets quite funny. ;-) Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page <http://geneslinuxbox.net:6309/gene> US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.python
csiph-web