|
From: | Jean Abou Samra |
Subject: | Re: errors when updating syntax |
Date: | Sun, 31 Jan 2021 00:34:45 +0100 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 |
Le 30/01/2021 à 23:49, James B. Wilkinson a écrit :
As a slightly related aside, can somebody point me to an explanation of the line of code that is cited in the error message?
sys.stdin = codecs.getreader('utf8')(sys.stdin.detach())
My Python skills don’t reach far far enough to grok that syntax. thanks
It forces the standard input stream to be
read in UTF-8 encoding. See
https://stackoverflow.com/a/4374457
I’ll bet we both did the same thing: Google that line of code. I had already found that same page on stackoverflow but the effect of that line of code is not what interests me. It’s a syntactic construct that I haven’t seen before, and it must have a name, and there must be an explanation of it in the Python docs. That’s what I’m trying to find.
thanks
Hello,
There is no particular synctactic construct
in this, just function and method calls. Maybe
you are confused by
a(b)(c)
That only means that the function a, when called
on the parameter b, returns an object which is in
turn a function (more generally, a callable), that
you can call with the argument c. It is thus equivalent
to
temp = a(b)
temp(c)
Best,
Jean
[Prev in Thread] | Current Thread | [Next in Thread] |