why sqrt is not a built-in function?

Chris Angelico rosuav at gmail.com
Fri Jan 15 16:20:50 EST 2021


On Sat, Jan 16, 2021 at 8:16 AM Michael F. Stemper <mstemper at gmail.com> wrote:
>
> On 15/01/2021 14.01, Stefan Ram wrote:
> > "Michael F. Stemper" <mstemper at gmail.com> writes:
>
> >>                               Of these, only EcmaScript has
> >> Math.sqrt() as part of the language, and that could be partly
> >> due to the fact that the language doesn't have any concept of
> >> "import" or "include".
> >
> >    You do not need to use the import statement in Python,
> >    but can also use the expression
> >
> > __import__( "math" ).sqrt( 4 )
>
> I had no idea that syntax existed, and find it completely at odds
> with The Zen of Python. I'm torn between forgetting that I ever saw
> it and using it for some evilly-obfuscated code.
>

Hehe, it's really nothing to do with the Zen; it's playing around with
internals, so you get whatever you get.

I recommend option #2. It is incredibly good fun. For added bonus
obscurity, don't import a module directly; import it from some
unrelated module, such as "from ast import sys" or "from base64 import
re".

ChrisA


More information about the Python-list mailing list