From c565266416f69f7d1e93ae9e2157b9e1c25b9258 Mon Sep 17 00:00:00 2001 From: Steven Black Date: Sun, 13 Mar 2016 11:59:25 -0400 Subject: [PATCH] Making it work in Python3. --- updateHostsFile.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/updateHostsFile.py b/updateHostsFile.py index 15de680e8..cff6fe561 100644 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -292,9 +292,12 @@ def removeDupsAndExcl(mergeFile): os.makedirs(outputPath) # Another mode is required to read and write the file in Python 3 - finalFile = open(os.path.join(outputPath, 'hosts'), 'r+') - mergeFile.seek(0) # reset file pointer + if Python3: + finalFile = open(os.path.join(outputPath, 'hosts'), 'w+b') + else: + finalFile = open(os.path.join(outputPath, 'hosts'), 'w+') + mergeFile.seek(0) # reset file pointer hostnames = set() hostnames.add("localhost") hostnames.add("localhost.localdomain")