Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78863 > unrolled thread

Toggle

Started bySeymore4Head <Seymore4Head@Hotmail.invalid>
First post2014-10-08 20:11 -0400
Last post2014-10-10 13:44 +0200
Articles 20 on this page of 59 — 27 participants

Back to article view | Back to comp.lang.python


Contents

  Toggle Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-08 20:11 -0400
    Re: Toggle Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-09 12:29 +1100
      [OT] spelling colour / color was Re: Toggle mm0fmf <none@mailinator.com> - 2014-10-09 18:43 +0100
        Re: [OT] spelling colour / color was Re: Toggle duncan smith <buzzard@invalid.invalid> - 2014-10-09 19:24 +0100
          Re: [OT] spelling colour / color was Re: Toggle Tim Delaney <timothy.c.delaney@gmail.com> - 2014-10-10 06:53 +1100
            Re: [OT] spelling colour / color was Re: Toggle Marko Rauhamaa <marko@pacujo.net> - 2014-10-09 23:48 +0300
              Re: [OT] spelling colour / color was Re: Toggle alister <alister.nospam.ware@ntlworld.com> - 2014-10-10 17:31 +0000
                Re: [OT] spelling colour / color was Re: Toggle Marko Rauhamaa <marko@pacujo.net> - 2014-10-10 22:01 +0300
                  Re: [OT] spelling colour / color was Re: Toggle alister <alister.nospam.ware@ntlworld.com> - 2014-10-10 20:05 +0000
                    Re: [OT] spelling colour / color was Re: Toggle Christian Gollwitzer <auriocus@gmx.de> - 2014-10-11 11:37 +0200
                      Re: [OT] spelling colour / color was Re: Toggle mm0fmf <none@mailinator.com> - 2014-10-11 12:45 +0100
                        Re: [OT] spelling colour / color was Re: Toggle duncan smith <buzzard@invalid.invalid> - 2014-10-11 16:26 +0100
                          Re: [OT] spelling colour / color was Re: Toggle Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-11 15:20 -0400
                          Re: [OT] spelling colour / color was Re: Toggle William Ray Wing <wrw@mac.com> - 2014-10-11 15:55 -0400
                            Re: [OT] spelling colour / color was Re: Toggle duncan smith <buzzard@invalid.invalid> - 2014-10-12 00:40 +0100
                              Re: [OT] spelling colour / color was Re: Toggle giacomo boffi <pecore@pascolo.net> - 2014-10-18 09:06 +0200
                      Re: [OT] spelling colour / color was Re: Toggle Simon Ward <simon+python@bleah.co.uk> - 2014-10-11 15:45 +0100
          Re: [OT] spelling colour / color was Re: Toggle "Neil D. Cerutti" <neilc@norwich.edu> - 2014-10-10 10:46 -0400
          Re: [OT] spelling colour / color was Re: Toggle Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-10 18:45 +0100
        Re: [OT] spelling colour / color was Re: Toggle Terry Reedy <tjreedy@udel.edu> - 2014-10-09 18:53 -0400
          Re: [OT] spelling colour / color was Re: Toggle Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-10 18:11 +1100
            Re: [OT] spelling colour / color was Re: Toggle Marko Rauhamaa <marko@pacujo.net> - 2014-10-10 13:08 +0300
              Re: [OT] spelling colour / color was Re: Toggle Chris Angelico <rosuav@gmail.com> - 2014-10-10 21:40 +1100
                Re: [OT] spelling colour / color was Re: Toggle Marko Rauhamaa <marko@pacujo.net> - 2014-10-10 13:51 +0300
                  Re: [OT] spelling colour / color was Re: Toggle Chris Angelico <rosuav@gmail.com> - 2014-10-10 22:50 +1100
                  Re: [OT] spelling colour / color was Re: Toggle Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-10 20:19 -0400
                    Re: [OT] spelling colour / color was Re: Toggle Marko Rauhamaa <marko@pacujo.net> - 2014-10-11 13:33 +0300
                      Re: [OT] spelling colour / color was Re: Toggle Chris Angelico <rosuav@gmail.com> - 2014-10-11 22:03 +1100
        Re: [OT] spelling colour / color was Re: Toggle Chris Angelico <rosuav@gmail.com> - 2014-10-10 10:21 +1100
        Re: [OT] spelling colour / color was Re: Toggle Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-10 17:52 +1100
          Re: [OT] spelling colour / color was Re: Toggle Chris Angelico <rosuav@gmail.com> - 2014-10-10 18:04 +1100
        Re: [OT] spelling colour / color was Re: Toggle Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-10 18:38 +0100
    Re: Toggle Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-09 02:25 +0100
    Re:Toggle Dave Angel <davea@davea.name> - 2014-10-08 21:24 -0400
    Re: Toggle Ben Finney <ben+python@benfinney.id.au> - 2014-10-09 12:42 +1100
      Re: Toggle Rustom Mody <rustompmody@gmail.com> - 2014-10-08 19:34 -0700
        Re: Toggle Steven D'Aprano <steve@pearwood.info> - 2014-10-09 04:56 +0000
          Re: Toggle Rustom Mody <rustompmody@gmail.com> - 2014-10-08 22:39 -0700
            Re: Toggle Chris Angelico <rosuav@gmail.com> - 2014-10-09 16:55 +1100
            Re: Toggle Peter Otten <__peter__@web.de> - 2014-10-09 09:51 +0200
              Re: Toggle Rustom Mody <rustompmody@gmail.com> - 2014-10-09 05:42 -0700
                Re: Toggle Terry Reedy <tjreedy@udel.edu> - 2014-10-09 16:57 -0400
            Re: Toggle Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-10 18:18 +1100
              Re: Toggle Rustom Mody <rustompmody@gmail.com> - 2014-10-10 07:24 -0700
                Re: Toggle Rustom Mody <rustompmody@gmail.com> - 2014-10-10 07:28 -0700
                  Re: Toggle Chris Angelico <rosuav@gmail.com> - 2014-10-11 01:36 +1100
        Re: Toggle Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-09 10:07 -0600
          Re: Toggle Rustom Mody <rustompmody@gmail.com> - 2014-10-09 09:33 -0700
            Re: Toggle Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-10 18:15 +1100
    Re: Toggle Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-09 04:02 +0100
    Re: Toggle random832@fastmail.us - 2014-10-08 23:54 -0400
    Re: Toggle Chris Angelico <rosuav@gmail.com> - 2014-10-09 14:57 +1100
    Re: Toggle Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-10-09 17:57 +1300
      Re: Toggle Travis Griggs <travisgriggs@gmail.com> - 2014-10-08 22:38 -0700
      Re: Toggle alister <alister.nospam.ware@ntlworld.com> - 2014-10-09 15:23 +0000
        Re: Toggle Tony the Tiger <tony@tiger.invalid> - 2014-10-12 18:38 +0000
          Re: Toggle Chris Angelico <rosuav@gmail.com> - 2014-10-13 05:43 +1100
            Re: Toggle alister <alister.nospam.ware@ntlworld.com> - 2014-10-13 08:09 +0000
    Re: Toggle Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2014-10-10 13:44 +0200

Page 2 of 3 — ← Prev page 1 [2] 3  Next page →


#78930 — Re: [OT] spelling colour / color was Re: Toggle

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-10-10 18:11 +1100
SubjectRe: [OT] spelling colour / color was Re: Toggle
Message-ID<5437868a$0$13011$c3e8da3$5496439d@news.astraweb.com>
In reply to#78916
Terry Reedy wrote:

> On 10/9/2014 1:43 PM, mm0fmf wrote:
>> On 09/10/2014 02:29, Steven D'Aprano wrote:
>>> Apart from the horrible spelling of colour :-)
>>
>> I've always spelt colour as "color" when programming and as "colour"
>> when writing language including documentation about software.
> 
> Like it or not, Python uses American English.
[...]
> Perhaps ironically, there are 52 uses of 'colour' in the stdlib, all but
> 4 in idlelib, and most of those in one file.  I just changed all except
> in the one file.

Well of course Python uses "color" *now*, you've just changed them all.

Which I think is bad practice Terry. That's needless code churn. I don't
think we should be churning code just to give preference to a minority
variant of spelling. "Colour" is preferred in the UK, Australia, New
Zealand, Canada, Nigeria, India, Pakistan, Kenya, Malaysia, the Philippines,
Ireland, South Africa, and many others. "Color" is preferred only in the
USA.

Whether you count by number of countries, or by total population of
English speakers, users of American spelling make up a minority (less than
30% of English speakers world-wide, and much less by country count). I
don't mind Americans using their own spelling in code they write, but I do
mind when they churn the standard library to push their preference over
that of the original author. I would never go through a code base doing a
mass "correction" of American spelling to English, and I don't think you
should do the opposite.

I believe that documentation, in particular, should be written in a form
which is going to be most acceptable to readers world-wide, not just a small
minority. Python is an international product, not American.


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#78939 — Re: [OT] spelling colour / color was Re: Toggle

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-10-10 13:08 +0300
SubjectRe: [OT] spelling colour / color was Re: Toggle
Message-ID<877g08nsno.fsf@elektro.pacujo.net>
In reply to#78930
Steven D'Aprano <steve+comp.lang.python@pearwood.info>:

> Python is an international product, not American.

And American English is the international software engineering language,
minority or not.

The rest of us are using it; why should you not follow suit?


Marko

[toc] | [prev] | [next] | [standalone]


#78940 — Re: [OT] spelling colour / color was Re: Toggle

FromChris Angelico <rosuav@gmail.com>
Date2014-10-10 21:40 +1100
SubjectRe: [OT] spelling colour / color was Re: Toggle
Message-ID<mailman.14744.1412937646.18130.python-list@python.org>
In reply to#78939
On Fri, Oct 10, 2014 at 9:08 PM, Marko Rauhamaa <marko@pacujo.net> wrote:
> Steven D'Aprano <steve+comp.lang.python@pearwood.info>:
>
>> Python is an international product, not American.
>
> And American English is the international software engineering language,
> minority or not.
>
> The rest of us are using it; why should you not follow suit?

If Python ever grows a 'color' statement or keyword, then sure.
Otherwise, it's just identifiers and data, which are international.

ChrisA

[toc] | [prev] | [next] | [standalone]


#78941 — Re: [OT] spelling colour / color was Re: Toggle

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-10-10 13:51 +0300
SubjectRe: [OT] spelling colour / color was Re: Toggle
Message-ID<87y4somc3q.fsf@elektro.pacujo.net>
In reply to#78940
Chris Angelico <rosuav@gmail.com>:

> If Python ever grows a 'color' statement or keyword, then sure.
> Otherwise, it's just identifiers and data, which are international.

Do you mean that the Python syntax should use American spellings, but
the Python standard library could use words like "colour", "Farbe",
"väri" etc?


Marko

[toc] | [prev] | [next] | [standalone]


#78945 — Re: [OT] spelling colour / color was Re: Toggle

FromChris Angelico <rosuav@gmail.com>
Date2014-10-10 22:50 +1100
SubjectRe: [OT] spelling colour / color was Re: Toggle
Message-ID<mailman.14748.1412941848.18130.python-list@python.org>
In reply to#78941
On Fri, Oct 10, 2014 at 9:51 PM, Marko Rauhamaa <marko@pacujo.net> wrote:
> Chris Angelico <rosuav@gmail.com>:
>
>> If Python ever grows a 'color' statement or keyword, then sure.
>> Otherwise, it's just identifiers and data, which are international.
>
> Do you mean that the Python syntax should use American spellings, but
> the Python standard library could use words like "colour", "Farbe",
> "väri" etc?

That's up to the core devs. But mainly, I was talking about user level
code, where you most definitely can do that sort of thing.

ChrisA

[toc] | [prev] | [next] | [standalone]


#78977 — Re: [OT] spelling colour / color was Re: Toggle

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2014-10-10 20:19 -0400
SubjectRe: [OT] spelling colour / color was Re: Toggle
Message-ID<mailman.14772.1412986751.18130.python-list@python.org>
In reply to#78941
On Fri, 10 Oct 2014 22:50:45 +1100, Chris Angelico <rosuav@gmail.com>
declaimed the following:

>On Fri, Oct 10, 2014 at 9:51 PM, Marko Rauhamaa <marko@pacujo.net> wrote:
>> Chris Angelico <rosuav@gmail.com>:
>>
>>> If Python ever grows a 'color' statement or keyword, then sure.
>>> Otherwise, it's just identifiers and data, which are international.
>>
>> Do you mean that the Python syntax should use American spellings, but
>> the Python standard library could use words like "colour", "Farbe",
>> "väri" etc?
>
>That's up to the core devs. But mainly, I was talking about user level
>code, where you most definitely can do that sort of thing.
>

	And then there is REXX... Which deliberately has both centre() and
center() in its standard library -- and they do the same thing...
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#78981 — Re: [OT] spelling colour / color was Re: Toggle

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-10-11 13:33 +0300
SubjectRe: [OT] spelling colour / color was Re: Toggle
Message-ID<87y4sm3ng7.fsf@elektro.pacujo.net>
In reply to#78977
Dennis Lee Bieber <wlfraed@ix.netcom.com>:

> And then there is REXX... Which deliberately has both centre() and
> center() in its standard library -- and they do the same thing...

I'm getting a new appreciation for Lisp's age-old "car" and "cdr".

The scientists have done this international thing for centuries. Their
single-letter naming might be the secret of their glorious success.

Obscure acronyms for the win.


Marko

[toc] | [prev] | [next] | [standalone]


#78982 — Re: [OT] spelling colour / color was Re: Toggle

FromChris Angelico <rosuav@gmail.com>
Date2014-10-11 22:03 +1100
SubjectRe: [OT] spelling colour / color was Re: Toggle
Message-ID<mailman.14774.1413025408.18130.python-list@python.org>
In reply to#78981
On Sat, Oct 11, 2014 at 9:33 PM, Marko Rauhamaa <marko@pacujo.net> wrote:
> I'm getting a new appreciation for Lisp's age-old "car" and "cdr".
>
> The scientists have done this international thing for centuries. Their
> single-letter naming might be the secret of their glorious success.
>
> Obscure acronyms for the win.

If it means nothing to anybody, nobody's at a disadvantage compared to
anyone else...

ChrisA

[toc] | [prev] | [next] | [standalone]


#78917 — Re: [OT] spelling colour / color was Re: Toggle

FromChris Angelico <rosuav@gmail.com>
Date2014-10-10 10:21 +1100
SubjectRe: [OT] spelling colour / color was Re: Toggle
Message-ID<mailman.14732.1412896867.18130.python-list@python.org>
In reply to#78905
On Fri, Oct 10, 2014 at 9:53 AM, Terry Reedy <tjreedy@udel.edu> wrote:
>
>> colour in a programme doesn't seem right.
>
> Perhaps ironically, there are 52 uses of 'colour' in the stdlib, all but 4
> in idlelib, and most of those in one file.  I just changed all except in the
> one file.

I agree, although I wouldn't make the change without good reason
(avoiding code churn). The last time I used "COLOUR" in any code was
in Q-Basic; I had my own subroutine of that name, which did some
processing and then used the built-in COLOR command. In fact, the only
reason I used the "non-program" spelling of the word was because BASIC
doesn't allow shadowing of commands.

(I don't even remember what the COLOUR command did. Probably something
like coping with red-block - when a CRT screen starts to die and the
red channel isn't functional. Hacks to deal with faults, that's what
we do!)

ChrisA

[toc] | [prev] | [next] | [standalone]


#78926 — Re: [OT] spelling colour / color was Re: Toggle

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-10-10 17:52 +1100
SubjectRe: [OT] spelling colour / color was Re: Toggle
Message-ID<54378212$0$13009$c3e8da3$5496439d@news.astraweb.com>
In reply to#78905
mm0fmf wrote:

> On 09/10/2014 02:29, Steven D'Aprano wrote:
>> Apart from the horrible spelling of colour :-)
> 
> I've always spelt colour as "color" when programming and as "colour"
> when writing language including documentation about software.
> 
> colour in a programme doesn't seem right.

"Normal" programmers spell words the same in code as they do outside of
code, e.g.:

    age
    address
    length

modulo the odd abbreviation like "len", "addr", etc., and coding conventions
like camelCase, underscore_words, sHungarianNotation, etc. So if you spell
colour with a U outside of code, I would expect you to spell it with a U
inside of code too.

Unix programmers take every opportunity to obfuscate their code by dropping
nouns and consonants, so I'd expect them to spell "colo(u)r" as something
like clr, colr, clor, or even clour.

Web programmers tend to make random spelling mistakes ("referer"), so I'd
expect "coluor", or perhaps "kolour".

But I've never come across your convention of spelling it "colour" in
documentation and "color" in code before. How very strange.



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#78929 — Re: [OT] spelling colour / color was Re: Toggle

FromChris Angelico <rosuav@gmail.com>
Date2014-10-10 18:04 +1100
SubjectRe: [OT] spelling colour / color was Re: Toggle
Message-ID<mailman.14742.1412924700.18130.python-list@python.org>
In reply to#78926
On Fri, Oct 10, 2014 at 5:52 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> "Normal" programmers spell words the same in code as they do outside of
> code, e.g.:
>
>     age
>     address
>     length

There's a difference between identifiers and commands, though. I would
expect, for instance, that a customer's address is stored in the
database in an address table, which will have an id, which I can
reference in Python using the name id. (Yes, that mandates shadowing.)
But if I need to reference something that the language/library author
provides, I expect that to use American spelling, mainly because
that's the most common. REXX is somewhat unusual in providing 'center'
and 'centre' functions (identical, just like operator.add and
operator.__add__), but I always used center() because it felt wrong to
use British spelling in language features.

ChrisA

[toc] | [prev] | [next] | [standalone]


#78959 — Re: [OT] spelling colour / color was Re: Toggle

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-10-10 18:38 +0100
SubjectRe: [OT] spelling colour / color was Re: Toggle
Message-ID<mailman.14757.1412962731.18130.python-list@python.org>
In reply to#78905
On 09/10/2014 23:53, Terry Reedy wrote:

>
> Like it or not, Python uses American English.
>

It is my understanding that this has been agreed to by a Dutch born 
dictator.  The traitor should be shot, selling out his fellow Europeans 
to the North Americans indeed :)

-- 
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]


#78865

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-10-09 02:25 +0100
Message-ID<mailman.14701.1412817961.18130.python-list@python.org>
In reply to#78863
On 09/10/2014 01:11, Seymore4Head wrote:
> I want to toggle between color="Red" and color="Blue"
> Here is one:
>      if color == "Red":
>          color = "Blue"
>      else:
>          color = "Red"
> Here is two:
> if x = "True" color = "Red"
> else:
> color="Blue"
> x= not x
>
> Others?
>

Here http://stackoverflow.com/questions/8381735/toggle-a-value-in-python 
but why couldn't you search in the first place?

-- 
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]


#78866

FromDave Angel <davea@davea.name>
Date2014-10-08 21:24 -0400
Message-ID<mailman.14700.1412817696.18130.python-list@python.org>
In reply to#78863
Seymore4Head <Seymore4Head@Hotmail.invalid> Wrote in message:
> I want to toggle between color="Red" and color="Blue"
> Here is one:
>     if color == "Red":
>         color = "Blue"
>     else:
>         color = "Red"
> Here is two:
> if x = "True" color = "Red"
> else:
> color="Blue"
> x= not x
> 
> Others?
> 

One looks like it wrks and two looks like nonsense.   Just what
 are you trying to ask?

-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#78868

FromBen Finney <ben+python@benfinney.id.au>
Date2014-10-09 12:42 +1100
Message-ID<mailman.14703.1412818949.18130.python-list@python.org>
In reply to#78863
Seymore4Head <Seymore4Head@Hotmail.invalid> writes:

> I want to toggle between color="Red" and color="Blue"

It's good to cultivate ongoing familiarity with the standard library
<URL:https://docs.python.org/3/library/itertools.html#itertools.cycle>
so that you can make use of wheels already invented and maintained::

    import itertools

    colours = ["Red", "Blue"]
    colour_cycle = itertools.cycle(colours)

    next(colour_cycle)    # → "Red"
    next(colour_cycle)    # → "Blue"
    next(colour_cycle)    # → "Red"
    next(colour_cycle)    # → "Blue"
    next(colour_cycle)    # → "Red"

    for colour in colour_cycle:
        # … loops indefinitely
        # with ‘colour’ bound to each value in turn …

-- 
 \      “My roommate got a pet elephant. Then it got lost. It's in the |
  `\                              apartment somewhere.” —Steven Wright |
_o__)                                                                  |
Ben Finney

[toc] | [prev] | [next] | [standalone]


#78869

FromRustom Mody <rustompmody@gmail.com>
Date2014-10-08 19:34 -0700
Message-ID<64c26ed7-33cc-4be9-93ac-8d2b84b92451@googlegroups.com>
In reply to#78868
On Thursday, October 9, 2014 7:12:41 AM UTC+5:30, Ben Finney wrote:
> Seymore4Head writes:

> > I want to toggle between color="Red" and color="Blue"

> It's good to cultivate ongoing familiarity with the standard library

And language. In recent python3:

>>> class Color(Enum):
...   Red = 0
...   Blue = 1
... 
>>> Color.Red
<Color.Red: 0>
>>> print (Color.Red)
Color.Red

# Not sure what to make of that distinction...

>>> c=Color.Red
>>> c = Color.Blue if c==Color.Red else Color.Red
>>> c
<Color.Blue: 1>
>>> 

>>> # Better
>>> def toggle(c): return Color.Blue if c==Color.Red else Color.Red
... 
>>> toggle(c)
<Color.Blue: 1>
>>> toggle(c)
<Color.Blue: 1>

# which means the c has not changed



>>> toggle(toggle(c))
<Color.Red: 0>


[Yeah and like Steven I find the colour of 'color' colourless]

[toc] | [prev] | [next] | [standalone]


#78873

FromSteven D'Aprano <steve@pearwood.info>
Date2014-10-09 04:56 +0000
Message-ID<5436157d$0$12918$c3e8da3$5496439d@news.astraweb.com>
In reply to#78869
On Wed, 08 Oct 2014 19:34:30 -0700, Rustom Mody wrote:

>>>> Color.Red
> <Color.Red: 0>
>>>> print (Color.Red)
> Color.Red
> 
> # Not sure what to make of that distinction...

That's because the interactive interpreter displays the repr() of objects 
(except for None, which it suppresses), while print outputs the str() of 
them.

py> class Test:
...     def __repr__(self): return "repr"
...     def __str__(self): return "str"
... 
py> x = Test()
py> x
repr
py> print(x)
str

That's an old, old part of Python, going back to Python 1.5 or older, if 
I remember correctly.



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#78876

FromRustom Mody <rustompmody@gmail.com>
Date2014-10-08 22:39 -0700
Message-ID<8dba70e4-9670-40d3-9a3f-d2b593d52ac6@googlegroups.com>
In reply to#78873
On Thursday, October 9, 2014 10:26:41 AM UTC+5:30, Steven D'Aprano wrote:
> On Wed, 08 Oct 2014 19:34:30 -0700, Rustom Mody wrote:

> >>>> Color.Red
> >>>> print (Color.Red)
> > Color.Red
> > # Not sure what to make of that distinction...

> That's because the interactive interpreter displays the repr() of objects 
> (except for None, which it suppresses), while print outputs the str() of 
> them.

Yeah...

What I meant to wonder upon was: "Is this behavior what the pro-print or the
anti-print folks like?"

In any case that the P in REPL is not *exactly* the same as print
(or equivalently the distinction between str and repr) makes for some
intricate noob confusions.

BTW is there some flag that can make them identical?

[toc] | [prev] | [next] | [standalone]


#78877

FromChris Angelico <rosuav@gmail.com>
Date2014-10-09 16:55 +1100
Message-ID<mailman.14708.1412834106.18130.python-list@python.org>
In reply to#78876
On Thu, Oct 9, 2014 at 4:39 PM, Rustom Mody <rustompmody@gmail.com> wrote:
> On Thursday, October 9, 2014 10:26:41 AM UTC+5:30, Steven D'Aprano wrote:
>> On Wed, 08 Oct 2014 19:34:30 -0700, Rustom Mody wrote:
>
>> >>>> Color.Red
>> >>>> print (Color.Red)
>> > Color.Red
>> > # Not sure what to make of that distinction...
>
>> That's because the interactive interpreter displays the repr() of objects
>> (except for None, which it suppresses), while print outputs the str() of
>> them.
>
> Yeah...
>
> What I meant to wonder upon was: "Is this behavior what the pro-print or the
> anti-print folks like?"
>
> In any case that the P in REPL is not *exactly* the same as print
> (or equivalently the distinction between str and repr) makes for some
> intricate noob confusions.
>
> BTW is there some flag that can make them identical?

I haven't used a proprinter since our XL24E died. Never used an
antiprinter, myself.

Here's how to make print() output the repr() of something:

_ORIG_PRINT = print
def print(*args, **kw):
    return _ORIG_PRINT(*(repr(arg) for arg in args), **kw)

But what's the point?

(Also: Have fun backporting that to 2.5, it won't be easy.)

ChrisA

[toc] | [prev] | [next] | [standalone]


#78880

FromPeter Otten <__peter__@web.de>
Date2014-10-09 09:51 +0200
Message-ID<mailman.14709.1412841089.18130.python-list@python.org>
In reply to#78876
Rustom Mody wrote:

> On Thursday, October 9, 2014 10:26:41 AM UTC+5:30, Steven D'Aprano wrote:
>> On Wed, 08 Oct 2014 19:34:30 -0700, Rustom Mody wrote:
> 
>> >>>> Color.Red
>> >>>> print (Color.Red)
>> > Color.Red
>> > # Not sure what to make of that distinction...
> 
>> That's because the interactive interpreter displays the repr() of objects
>> (except for None, which it suppresses), while print outputs the str() of
>> them.
> 
> Yeah...
> 
> What I meant to wonder upon was: "Is this behavior what the pro-print or
> the anti-print folks like?"
> 
> In any case that the P in REPL is not *exactly* the same as print
> (or equivalently the distinction between str and repr) makes for some
> intricate noob confusions.
> 
> BTW is there some flag that can make them identical?

No flag, but you can tweak that P:

>>> import sys
>>> sys.displayhook = print
>>> "foo"
foo
>>> def f(): pass
... 
>>> f()
None

[toc] | [prev] | [next] | [standalone]


Page 2 of 3 — ← Prev page 1 [2] 3  Next page →

Back to top | Article view | comp.lang.python


csiph-web