Addition of a .= operator

Peter J. Holzer hjp-python at hjp.at
Sat May 20 16:15:24 EDT 2023


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()
> ------------------------------------------------------------
> num = num.value
> ------------------------------------------------------------
> 
> So what I'm suggesting is something like this:
> 
> ------------------------------------------------------------
> hash.=hexdigest()
> ------------------------------------------------------------
> num.=value
> ------------------------------------------------------------

I actually needed to read those twice to get their meaning. I think

hash .= hexdigest()
num .= value

would have been clearer (yes, I nag my colleagues about white-space,
too).

Do you have any examples (preferably from real code) where you don't
assign to a simple variable? I feel that
    x += 1
isn't much of an improvement over
    x = x + 1
but
    self.data[line+len(chars)-1] += after
is definitely an improvement over
    self.data[line+len(chars)-1] + self.data[line+len(chars)-1] + after

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp at hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/python-list/attachments/20230520/17dd6121/attachment.sig>


More information about the Python-list mailing list