Which more Pythonic - self.__class__ or type(self)?

avi.e.gross at gmail.com avi.e.gross at gmail.com
Sat Mar 4 16:46:44 EST 2023


Alan,

I got divorced from the C++ crowd decades ago when I left Bell Labs. You are making me glad I did!

I do accept your suggestion that you can be idiomatic if you follow the common methods of whatever language you use. That will take you quite far as long as you are not a total slave to it.

But I note some idioms catch on and some are imposed and some become almost moot. I am not sure which aspects of C++ have changed drastically and may go re-study the modern version as I was a very early adoptee within AT&T and saw changes even back then. 

But I consider something like the half dozen or so major print variants in python and wonder how much longer some of them will be seen as worth using, let alone idiomatic. Something like an fstring may dominate for many purposes.

I know in R, that I used to use some convoluted methods to assemble output that I often now ignore once a "glue" package gave me something similar to fstring abilities where all kinds of variables and calculations can now be embedded withing a string to be dynamically evaluated in your current environment. Some of the documents I write now similarly embed parts of programs and also have an inline ability to evaluate small amounts of code in one of many languages  that inserts directly into the text as it is being typeset.

So I see moving targets where what was formerly at or near the state of the art, becomes passé. So much of my early work rapidly became trivial or irrelevant or never caught on or became lost in an environment I no longer used. To keep going forward often involves leaving things behind.

Some new features in Python will be interesting to watch. I mentioned the match statement. I was using a similar construct in a JVM language called SCALA ages ago.  There it was a sort of core part of the language and often replaced constructs normally used by other languages such as many simple or nested IF statements. I am sure someone will point out where they borrowed parts from or who did it better, but what I am saying is that I want to see if it becomes an exotic addition to Python in a way that loosely melds, or if it becomes the PYTHONIC way ...



-----Original Message-----
From: Alan Gauld <learn2program at gmail.com> 
Sent: Saturday, March 4, 2023 1:38 PM
To: avi.e.gross at gmail.com; python-list at python.org
Subject: Re: RE: Which more Pythonic - self.__class__ or type(self)?

On 04/03/2023 17:38, avi.e.gross at gmail.com wrote:
> 
> Of course each language has commonly used idioms 
> 

That's the point, the correct term is probably "idiomatic"
rather than "pythonic" but it is a defacto standard that
idiomatic Python has become known as Pythonic. I don't
think that's a problem. And at least we aren't in the C++
situation where almost everything that was idiomatic up
until 1999 is now deemed an anti-pattern and they have
standard library modules to try and guide you to use the
"correct" idioms!

But being Pythonic is still a much more loose term and
the community less stressed about it than their C++
cousins where it has almost reached a religious fervour!

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos





More information about the Python-list mailing list