[libvirt] [RFC PATCH v2 7/8] python3: Open files in text instead of binary mode

Andrea Bolognani abologna at redhat.com
Thu Mar 15 16:11:09 UTC 2018


We use text operations on the contents after reading them.

Signed-off-by: Andrea Bolognani <abologna at redhat.com>
---
This seems reasonable and works correctly AFAICT, but I'm
not 100% confident it's the right way to address the issue.

 src/esx/esx_vi_generator.py        | 4 ++--
 src/hyperv/hyperv_wmi_generator.py | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/esx/esx_vi_generator.py b/src/esx/esx_vi_generator.py
index 2f3c88812d..6ce017d794 100755
--- a/src/esx/esx_vi_generator.py
+++ b/src/esx/esx_vi_generator.py
@@ -1327,7 +1327,7 @@ def open_and_print(filename):
     else:
         print("  GEN      " + filename)
 
-    return open(filename, "wb")
+    return open(filename, "wt")
 
 
 
@@ -1435,7 +1435,7 @@ block = None
 
 
 # parse input file
-for line in file(input_filename, "rb").readlines():
+for line in open(input_filename, "rt").readlines():
     number += 1
 
     if "#" in line:
diff --git a/src/hyperv/hyperv_wmi_generator.py b/src/hyperv/hyperv_wmi_generator.py
index 1cf16a7836..7dc11ba905 100755
--- a/src/hyperv/hyperv_wmi_generator.py
+++ b/src/hyperv/hyperv_wmi_generator.py
@@ -396,7 +396,7 @@ def open_and_print(filename):
     else:
         print("  GEN      " + filename)
 
-    return open(filename, "wb")
+    return open(filename, "wt")
 
 
 
@@ -468,7 +468,7 @@ def main():
     number = 0
     block = None
 
-    for line in file(input_filename, "rb").readlines():
+    for line in open(input_filename, "rt").readlines():
         number += 1
 
         if "#" in line:
-- 
2.14.3




More information about the libvir-list mailing list