Re: Addition of a .= operator

2023-05-24 Thread Peter J. Holzer
On 2023-05-24 08:51:19 +1000, Chris Angelico wrote: > On Wed, 24 May 2023 at 08:48, Peter J. Holzer wrote: > > Yes, that probably wasn't the best example. I sort of deliberately > > avoided method chaining here to make my point that you don't have to > > invent a new variable name for every interm

Re: Addition of a .= operator

2023-05-23 Thread Rob Cliffe via Python-list
On 23/05/2023 22:03, Peter J. Holzer wrote: On 2023-05-21 20:30:45 +0100, Rob Cliffe via Python-list wrote: On 20/05/2023 18:54, Alex Jando wrote: So what I'm suggesting is something like this: hash = hashlib.sha256(b'word') hash.=

Re: Addition of a .= operator

2023-05-23 Thread Chris Angelico
On Wed, 24 May 2023 at 08:57, Rob Cliffe wrote: > > Do you mean "ASCII or UTF-8"? Because decoding as UTF-8 is fine with > > ASCII (it's a superset). You should always consistently get the same > > data type (bytes or text) based on the library you're using. > > > > ChrisA > OK, bad example. The

Re: Addition of a .= operator

2023-05-23 Thread Chris Angelico
On Wed, 24 May 2023 at 08:48, Peter J. Holzer wrote: > > On 2023-05-24 07:12:32 +1000, Chris Angelico wrote: > > On Wed, 24 May 2023 at 07:04, Peter J. Holzer wrote: > > > But I find it easier to read if I just reuse the same variable name: > > > > > > user = request.GET["user"] > > > use

Re: Addition of a .= operator

2023-05-23 Thread Peter J. Holzer
On 2023-05-24 07:12:32 +1000, Chris Angelico wrote: > On Wed, 24 May 2023 at 07:04, Peter J. Holzer wrote: > > But I find it easier to read if I just reuse the same variable name: > > > > user = request.GET["user"] > > user = str(user, encoding="utf-8") > > user = user.strip() > >

Re: Addition of a .= operator

2023-05-23 Thread Rob Cliffe via Python-list
This sort of code might be better as a single expression. For example: user = ( request.GET["user"] .decode("utf-8") .strip() .lower() ) user = orm.user.get(name=user) LOL.  And I thought I was the one with a (self-confessed) tendency to write too slick, dense, smart-alec

Re: Addition of a .= operator

2023-05-23 Thread Chris Angelico
On Wed, 24 May 2023 at 08:22, Rob Cliffe wrote: > > > > This sort of code might be better as a single expression. For example: > > > > user = ( > > request.GET["user"] > > .decode("utf-8") > > .strip() > > .lower() > > ) > > user = orm.user.get(name=user) > > > > > LOL. And I

Re: Addition of a .= operator

2023-05-23 Thread Chris Angelico
On Wed, 24 May 2023 at 07:04, Peter J. Holzer wrote: > But I find it easier to read if I just reuse the same variable name: > > user = request.GET["user"] > user = str(user, encoding="utf-8") > user = user.strip() > user = user.lower() > user = orm.user.get(name=user) > > Each

Re: Addition of a .= operator

2023-05-23 Thread Peter J. Holzer
On 2023-05-21 20:30:45 +0100, Rob Cliffe via Python-list wrote: > On 20/05/2023 18:54, Alex Jando wrote: > > So what I'm suggesting is something like this: > > > > > > hash = hashlib.sha256(b'word') > > hash.=hexdigest() > >

Re: Addition of a .= operator

2023-05-23 Thread Rob Cliffe via Python-list
On 20/05/2023 18:54, Alex Jando wrote: I have many times had situations where I had a variable of a certain type, all I cared about it was one of it's methods. For example: import hashlib hash = hashlib.sha256(b'word') hash = hash.

Re: Addition of a .= operator

2023-05-20 Thread Greg Ewing via Python-list
On 21/05/23 9:18 am, Richard Damon wrote: This just can't happen (as far as I can figure) for .= unless the object is defining something weird for the inplace version of the operation, Indeed. There are clear use cases for overriding +=, but it's hard to think of one for this. So it would just

Re: Addition of a .= operator

2023-05-20 Thread Greg Ewing via Python-list
On 21/05/23 5:54 am, Alex Jando wrote: hash.=hexdigest() That would be a very strange and unprecedented syntax that munges together an attribute lookup and a call. Keep in mind that a method call in Python is actually two separate things: y = x.m() is equivalent to f = x.m y = f() But it

Re: Addition of a .= operator

2023-05-20 Thread Richard Damon
On 5/20/23 4:15 PM, Peter J. Holzer wrote: On 2023-05-20 10:54:59 -0700, Alex Jando wrote: I have many times had situations where I had a variable of a certain type, all I cared about it was one of it's methods. For example: hash = h

Re: Addition of a .= operator

2023-05-20 Thread Peter J. Holzer
On 2023-05-20 10:54:59 -0700, Alex Jando wrote: > I have many times had situations where I had a variable of a certain > type, all I cared about it was one of it's methods. > > For example: > > > hash = hash.hexdigest() > --

RE: Addition of a .= operator

2023-05-20 Thread avi.e.gross
different circumstance? -Original Message- From: Python-list On Behalf Of 2qdxy4rzwzuui...@potatochowder.com Sent: Saturday, May 20, 2023 2:49 PM To: python-list@python.org Subject: Re: Addition of a .= operator On 2023-05-21 at 06:11:02 +1200, dn via Python-list wrote: > On 21

Re: Addition of a .= operator

2023-05-20 Thread 2QdxY4RzWzUUiLuE
On 2023-05-21 at 06:11:02 +1200, dn via Python-list wrote: > On 21/05/2023 05.54, Alex Jando wrote: > > I have many times had situations where I had a variable of a certain type, > > all I cared about it was one of it's methods. > > > > For example: > > > >

Re: Addition of a .= operator

2023-05-20 Thread dn via Python-list
On 21/05/2023 05.54, Alex Jando wrote: I have many times had situations where I had a variable of a certain type, all I cared about it was one of it's methods. For example: import hashlib hash = hashlib.sha256(b'word') hash = hash.he