The issue arose accidentally today in class when "False" was passed to a "filename" parameter. The program didn't give an error and appeared to hang. It took a while to find the root cause. open() accepts a filename string, a path-like object, or an integer file descriptor.
-
-
Prikaži ovu nitHvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi
-
-
-
Two years ago, it has been reported as a bug, but closed as "not a bug": https://bugs.python.org/issue32965
-
Yes. I imagine that people routinely encounter this issue every now and then. Likely, it can't be fixed without introducing special cases or breaking existing code. If file descriptors were actually needed, the API should have made them keyword arguments or somesuch.
- Još 3 druga odgovora
Novi razgovor -
-
-
oi, that's ugly. But yeah, since False is 0 and open()'s first arg can be an integer file handle, then it would open stdin and read from the user until EOF, putting the results in "s". But throwing a TypeError or a GoodGriefDontDoThat exception might be a wiser course of action.
-
It throws an exception in Python 2. Reads stdin in Python 3.
- Još 2 druga odgovora
Novi razgovor -
-
-
Maybe in Python 5 we can make it so that booleans aren't integers
-
Pythons upcasting is pretty consistent but seems to be often forgotten: Bools can be evaluated as Integers, Integers can be evaluated as Floats, Floats can be evaluated as Complex.
Kraj razgovora
Novi razgovor -
-
-
Yes, it makes me sad.
-
is it open() accepting an int that makes you sad? Bool being a sub-type of int? stdin being an implicit resource? The unexpected effect of those in combination? other?
- Još 3 druga odgovora
Novi razgovor -
-
-
echo 'hello' | python -c 'print(open(False).read())'
- Još 1 odgovor
Novi razgovor -
Čini se da učitavanje traje već neko vrijeme.
Twitter je možda preopterećen ili ima kratkotrajnih poteškoća u radu. Pokušajte ponovno ili potražite dodatne informacije u odjeljku Status Twittera.