Re: List replication operator

2018-05-26 Thread Alan Bawden
If the behaviour of * on a sequence is confusing, then isn't the following behaviour also confusing for exactly the same reason? >>> a = [[]] >>> b = a + a >>> b [[], []] >>> b[0].append(5) >>> b [[5], [5]] And if so, shouldn't there also be a concatenation operator that perf

Re: List replication operator

2018-05-26 Thread Steven D'Aprano
On Fri, 25 May 2018 09:58:19 -0700, Rob Gaddi wrote: > I agree that it's non-obvious, but I disagree with your diagnosis. A further data point: "I was not properly appreciating that that these repeated objects were the *same identical* objects that were in the pre-replicated list."

Re: Why cannot I use __slots__ and weakrefs together?

2018-05-26 Thread Steven D'Aprano
On Sat, 26 May 2018 11:53:42 +0200, Christian Heimes wrote: >> Why does weakref hate my Eggs class? > > Weakref needs some place to store reference information. It works if you > add "__weakref__" to your slots: > > class Eggs: > __slots__ = ['spanish_inquisition', '__weakref__'] Thanks!

Re: '_' and '__'

2018-05-26 Thread Ben Finney
Mike McClain writes: > Steven D'Aprano and Ben Finney used these '_' and '__'. > Steve said, "[[] for _ in range(5)]". > Ben said, "[ [] for __ in range(5) ]". > > These aren't listed separately in the index That's right, the names ‘_’ and ‘__’ have no special meaning in Python-the-language

Re: '_' and '__'

2018-05-26 Thread Cameron Simpson
On 27May2018 09:46, Chris Angelico wrote: On Sun, May 27, 2018 at 9:40 AM, Thomas Jollans wrote: There's nothing special about _, it's just a possible name of a variable, albeit a very short and entirely uninformative one. Normally, it's not something you'd actually want to name a variable, of

Re: '_' and '__'

2018-05-26 Thread Chris Angelico
On Sun, May 27, 2018 at 9:40 AM, Thomas Jollans wrote: > On 27/05/18 01:19, Mike McClain wrote: >> In their discussion of 'List replication operator' >> Steven D'Aprano and Ben Finney used these '_' and '__'. >> Steve said, "[[] for _ in range(5)]". >> Ben said, "[ [] for __ in range(5) ]". >>

Re: '_' and '__'

2018-05-26 Thread Thomas Jollans
On 27/05/18 01:19, Mike McClain wrote: > In their discussion of 'List replication operator' > Steven D'Aprano and Ben Finney used these '_' and '__'. > Steve said, "[[] for _ in range(5)]". > Ben said, "[ [] for __ in range(5) ]". > > These aren't listed separately in the index, where migh

'_' and '__'

2018-05-26 Thread Mike McClain
In their discussion of 'List replication operator' Steven D'Aprano and Ben Finney used these '_' and '__'. Steve said, "[[] for _ in range(5)]". Ben said, "[ [] for __ in range(5) ]". These aren't listed separately in the index, where might I find written discussion of these? Thanks, Mike

Re: Raw string statement (proposal)

2018-05-26 Thread Mikhail V
On Sat, May 26, 2018 at 10:21 PM, Chris Angelico wrote: > > I'm done. Argue with brick walls for the rest of eternity if you like. I see you like me, but I can reciprocate your feelings. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/

Re: Some Issues on Tagging Text

2018-05-26 Thread Cameron Simpson
On 26May2018 04:02, Subhabrata Banerjee wrote: On Saturday, May 26, 2018 at 3:54:37 AM UTC+5:30, Cameron Simpson wrote: It sounds like you want a more general purpose parser, and that depends upon your purposes. If you're coding to learn the basics of breaking up text, what you're doing is fine

Re: Raw string statement (proposal)

2018-05-26 Thread Chris Angelico
On Sun, May 27, 2018 at 5:13 AM, Mikhail V wrote: > On Sat, May 26, 2018 at 7:10 PM, Steven D'Aprano >> temp = >>| Mikhail's syntax for {65290} is {65290} >> Can you see the problem yet? How does your collapse function f() >> distinguish between the escape code {65290} and the literal string

Re: Raw string statement (proposal)

2018-05-26 Thread Mikhail V
On Sat, May 26, 2018 at 7:10 PM, Steven D'Aprano wrote: > On Sat, 26 May 2018 18:22:15 +0300, Mikhail V wrote: > >>> Here is a string assigned to name `s` using Python's current syntax: >>> >>> s = "some\ncharacters\0abc\x01\ndef\uFF0A\nhere" >>> >>> How do you represent that assignment using your

Re: Enums: making a single enum

2018-05-26 Thread Ethan Furman
On 05/26/2018 01:00 AM, Steven D'Aprano wrote: I wish there was a simpler way to define symbols with identity but no state or behaviour... Check out the Constant class in aenum. You still might want to customize the repr, though. -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/pytho

Re: Re: The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

2018-05-26 Thread Peter Otten
Paul St George wrote: > Thank you. > You are very right. The show() method is intended for debugging purposes > and is useful for that, but what method should I be using and is PIL the > best imaging library for my purposes? I do not want to manipulate > images, I only want to show images (full sc

Re: Raw string statement (proposal)

2018-05-26 Thread Steven D'Aprano
On Sat, 26 May 2018 18:22:15 +0300, Mikhail V wrote: >> Here is a string assigned to name `s` using Python's current syntax: >> >> s = "some\ncharacters\0abc\x01\ndef\uFF0A\nhere" >> >> How do you represent that assignment using your syntax? > > Hope its not mandatory to decipher your random exam

Re: Enums: making a single enum

2018-05-26 Thread Steven D'Aprano
On Sat, 26 May 2018 23:54:51 +1000, Chris Angelico wrote: > Seems pretty non-controversial, which means it's almost guaranteed to > reach 100+ posts debating what the name should be. Including: * 27 posts declaring that using such singleton symbols is completely un-Pythonic and is sure to doom

Re: Raw string statement (proposal)

2018-05-26 Thread Mikhail V
On Sat, May 26, 2018 at 10:55 AM, Steven D'Aprano wrote: > On Sat, 26 May 2018 08:09:51 +0300, Mikhail V wrote: > >> On Fri, May 25, 2018 at 1:15 PM, bartc wrote: > [...] >>> One problem here is how to deal with embedded non-printable characters: >>> CR, LF and TAB might become part of the normal

Re: Re: The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

2018-05-26 Thread Paul St George
Thank you. You are very right. The show() method is intended for debugging purposes and is useful for that, but what method should I be using and is PIL the best imaging library for my purposes? I do not want to manipulate images, I only want to show images (full screen) on an external display.

Re: List replication operator

2018-05-26 Thread Peter Otten
Steven D'Aprano wrote: > On Fri, 25 May 2018 09:28:01 +0200, Peter Otten wrote: > >> Yet another arcanum to learn for beginners with little return. If you >> cannot refrain from tinkering with the language at least concentrate on >> the features with broad application. Thank you. > > Broader tha

Re: Enums: making a single enum

2018-05-26 Thread Chris Angelico
On Sat, May 26, 2018 at 6:50 PM, Steven D'Aprano wrote: > On Sat, 26 May 2018 18:14:08 +1000, Chris Angelico wrote: > >> On Sat, May 26, 2018 at 6:00 PM, Steven D'Aprano >> wrote: >>> Actually I don't really need all the features of Enums, I might just >>> define my own class: >>> >>> >>> class M

Re: why do I get syntax error on if : break

2018-05-26 Thread Grant Edwards
On 2018-05-25, asa32s...@gmail.com wrote: > here is the code, i keep getting an error, "break outside loop". You get the "break outside loop" error because you're using the break statement when you are not inside a loop. > if it is false just exit function You use the 'return' statement to exi

Re: Enums: making a single enum

2018-05-26 Thread Peter Otten
Steven D'Aprano wrote: > Am I silly for wanting to make a single enum? > > I have a three-state flag, True, False or Maybe. Is is confusing or bad > practice to make a single enum for the Maybe case? > > > from enum import Enum > class State(Enum): > Maybe = 2 > > Maybe = State.Maybe > del

Re: Some Issues on Tagging Text

2018-05-26 Thread subhabangalore
On Saturday, May 26, 2018 at 3:54:37 AM UTC+5:30, Cameron Simpson wrote: > On 25May2018 04:23, Subhabrata Banerjee wrote: > >On Friday, May 25, 2018 at 3:59:57 AM UTC+5:30, Cameron Simpson wrote: > >> On 24May2018 03:13, wrote: > >> >I have a text as, > >> > > >> >"Hawaii volcano generates toxic g

Re: Enums: making a single enum

2018-05-26 Thread Marko Rauhamaa
Ian Kelly : > On Fri, May 25, 2018 at 11:00 PM, Chris Angelico wrote: >> # Tri-state logic >> Maybe = object() > > The enum has a nice __str__ though. I use strings for enums: class X: HERE = "HERE" THERE = "THERE" EVERYWHERE = "EVERYWHERE" def __init__(self):

Re: Enums: making a single enum

2018-05-26 Thread Serhiy Storchaka
26.05.18 08:07, Ian Kelly пише: On Fri, May 25, 2018 at 11:00 PM, Chris Angelico wrote: On Sat, May 26, 2018 at 2:46 PM, Steven D'Aprano wrote: Am I silly for wanting to make a single enum? I have a three-state flag, True, False or Maybe. Is is confusing or bad practice to make a single enum

Re: Computations on pandas dataframes

2018-05-26 Thread Peter Otten
junkaccoun...@outlook.com wrote: > Hi, > > Python newbie here. I need help with the following two tasks I need to > accomplish using Python: > > > > Creating a matrix of rolling variances > > I have a pandas data frame of six columns, I would like to iteratively > comp

Re: Why cannot I use __slots__ and weakrefs together?

2018-05-26 Thread Gregory Ewing
Steven D'Aprano wrote: TypeError: cannot create weak reference to 'Eggs' object Why does weakref hate my Eggs class? Classes with __slots__ aren't automatically given a __weakref__ slot, to save memory I suppose. But you can give it one explicitly: >>> class Eggs: ... __slots__ = ['spanish

Re: Why cannot I use __slots__ and weakrefs together?

2018-05-26 Thread Christian Heimes
On 2018-05-26 11:17, Steven D'Aprano wrote: > Here is my code: > > > > cut here %< > > import weakref > d = weakref.WeakValueDictionary() > > class Spam: > pass > > class Eggs: > __slots__ = ['spanish_inquisition'] > > d['a'] = Spam() # Okay. > d['b'] = Eggs() # Nobody wi

Why cannot I use __slots__ and weakrefs together?

2018-05-26 Thread Steven D'Aprano
Here is my code: cut here %< import weakref d = weakref.WeakValueDictionary() class Spam: pass class Eggs: __slots__ = ['spanish_inquisition'] d['a'] = Spam() # Okay. d['b'] = Eggs() # Nobody will expect what happens next! cut here %< and the result I get is:

Re: Enums: making a single enum

2018-05-26 Thread Steven D'Aprano
On Sat, 26 May 2018 18:14:08 +1000, Chris Angelico wrote: > On Sat, May 26, 2018 at 6:00 PM, Steven D'Aprano > wrote: >> Actually I don't really need all the features of Enums, I might just >> define my own class: >> >> >> class Maybe: >> def __repr__(self): >> return "Maybe" >> >>

Re: Enums: making a single enum

2018-05-26 Thread Chris Angelico
On Sat, May 26, 2018 at 6:00 PM, Steven D'Aprano wrote: > Actually I don't really need all the features of Enums, I might just > define my own class: > > > class Maybe: > def __repr__(self): > return "Maybe" > > Maybe = Maybe() > > > > I wish there was a simpler way to define symbols

Re: Enums: making a single enum

2018-05-26 Thread Steven D'Aprano
On Fri, 25 May 2018 23:07:47 -0600, Ian Kelly wrote: > On Fri, May 25, 2018 at 11:00 PM, Chris Angelico > wrote: >> On Sat, May 26, 2018 at 2:46 PM, Steven D'Aprano >> wrote: [...] >>> Is there a better way of handling a three-state flag like this? >>> >>> >> Does it need to have a value of 2? I

Re: Raw string statement (proposal)

2018-05-26 Thread Steven D'Aprano
On Sat, 26 May 2018 08:09:51 +0300, Mikhail V wrote: > On Fri, May 25, 2018 at 1:15 PM, bartc wrote: [...] >> One problem here is how to deal with embedded non-printable characters: >> CR, LF and TAB might become part of the normal source text, but how >> about anything else? Or would you only al