On 2023-05-21 at 06:11:02 +1200,
dn via Python-list <python-list@python.org> 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:
> > 
> > ------------------------------------------------------------
> > import hashlib
> > hash = hashlib.sha256(b'word')
> > hash = hash.hexdigest()
> > ------------------------------------------------------------
> > import enum
> > class Number(enum.Enum):
> >          One: int = 1
> >          Two: int = 2
> >          Three: int = 3
> > num = Number.One
> > num = num.value
> > ------------------------------------------------------------
> > 
> > Now to be fair, in the two situations above, I could just access the method 
> > right as I declare the object, however, sometimes when passing values into 
> > functions, it's a lot messier to do that.

Can you give an example, preferably one from an actual program, that
shows the mess?  Is it More Messierâ„¢ than the difference between the
following examples?

    # example 1
    hash = hashlib.sha256(b'word')
    f(hash.hexdigest())         # call f with hash's hexdigest

    # example 2
    hash = hashlib.sha256(b'word')
    hash = hash.hexdigest()     # extract hash's hexdigest
    f(hash)                     # call f with hash's hexdigest

Can you also show what your code would look like with a .= operator?

> > So what I'm suggesting is something like this:
> > 
> > ------------------------------------------------------------
> > import hashlib
> > hash = hashlib.sha256(b'word')
> > hash.=hexdigest()
> > ------------------------------------------------------------
> > import enum
> > class Number(enum.Enum):
> >          One: int = 1
> >          Two: int = 2
> >          Three: int = 3
> > num = Number.One
> > num.=value
> > ------------------------------------------------------------
> 
> A custom-class wrapper?
> Even, a decorator-able function?
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to