On Wed, Dec 21, 2022 at 1:18 AM Steven D'Aprano <st...@pearwood.info> wrote:

> On Tue, Dec 20, 2022 at 11:55:49PM -0800, Jeremiah Paige wrote:
> >     @property
> >     def data(self):
> >         return f"{self}"
>
> By my testing, on Python 3.10, this is slightly faster still:
>
>     @property
>     def data(self):
>         return "".join((self,))
>

I think both of those will call self.__str__, which creates a recursion --
that's what I'm trying to avoid.

I'm sure there are ways to optimize this -- but only worth doing if it's
worth doing at all :-)

- CHB



That's about 14% faster than the f-string version.
>
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/CCZG6ALFEV3B67LENW5ZDJG5XSHKREG4/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
Christopher Barker, PhD (Chris)

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/QQWOF4R7QVN6ARSE4RHAQU5FWRT7AEUR/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to