mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-12-25 23:21:45 +03:00
81d68e6100
The print function in Python will convert printed arguments to text strings [1] and thus print() cannot be used with binary mode file objects. In Python 2 the write() method of BytesIO() takes as input *bytes* object which refers to *str* in Python 3. [2] The write() method of StringIO() takes *unicode* object. [3] Therefore, StringIO() object cannot be used with the print() function. In Python 3 the write() method of BytesIO() takes a *bytes* object (not *str*). [4] Therefore, the BytesIO() obj cannot be used with print(). However, the write() method of StringIO() in Python 3 takes a *str* as input.[5] Example of the issue: from __future__ import print_function import io a = io.BytesIO() b = io.StringIO() print("test", file=a) <- Fails for Python 3 print("test", file=b) <- Fails for Python 2 a.write('%s\n' % "test") <- Fails for Python 3 b.write('%s\n' % "test") <- Fails for Python 2 [1] https://docs.python.org/3.5/library/functions.html#print [2] https://docs.python.org/2/library/io.html#io.BufferedWriter.write [3] https://docs.python.org/2/library/io.html#io.TextIOBase.write [4] https://docs.python.org/3/library/io.html#io.BufferedWriter.write [5] https://docs.python.org/3/library/io.html#io.TextIOBase.write |
||
---|---|---|
.. | ||
capabilities-xml | ||
cli-test-xml | ||
clone-xml | ||
hostkeymap | ||
inject-data | ||
interface-xml | ||
nodedev-xml/devxml | ||
storage-xml | ||
uitests | ||
virtconv-files | ||
xmlconfig-xml | ||
xmlparse-xml | ||
__init__.py | ||
capabilities.py | ||
checkprops.py | ||
clitest.py | ||
clonetest.py | ||
hostkeymap.py | ||
interface.py | ||
magicuri | ||
misc.py | ||
nodedev.py | ||
osdict.py | ||
pycodestyle.cfg | ||
pylint.cfg | ||
storage.py | ||
test_inject.py | ||
test_urls.ini | ||
test_urls.py | ||
testdriver.xml | ||
uriparse.py | ||
utils.py | ||
virtconvtest.py | ||
xmlconfig.py | ||
xmlparse.py |