3 ms·
It's actually one alternative to Python 2/3 compatibility, working around the fact that print is a statement in 2, and just a function in 3. The more common wa
by eliben 11y ago
It's actually one alternative to Python 2/3 compatibility, working around the fact that print is a statement in 2, and just a function in 3.
The more common way is "from __future__ import print_function" of course, but I've seen code that does sys.stdout.write instead -- nothing wrong about that (especially if your code usually uses streams for stuff)
- matmann2001 11y agoI understand how one might use sys.stdout.write, but the reasons for doing so are kind of rare. When you're pressed for time to reverse the security protocols and escape, ensuring backwards/forwards compatibility seems like a low priority.
- eliben 11y agoFor sure. I was just giving a reasoning why such code makes sense at all; I wasn't trying to defend its usage in the given context :)