Explicitly specify encoding when opening text files in Python code

This commit is contained in:
practicalswift 2018-06-12 17:49:20 +02:00 committed by Jack Grigg
parent 1b32acdd52
commit 0eef155a4a
4 changed files with 6 additions and 6 deletions

View File

@ -10,7 +10,7 @@ import sys
import unittest
def write_testcode(filename):
with open(filename, 'w') as f:
with open(filename, 'w', encoding="utf8") as f:
f.write('''
#include <stdio.h>
int main()

View File

@ -71,7 +71,7 @@ def get_blk_dt(blk_hdr):
def get_block_hashes(settings):
blkindex = []
f = open(settings['hashlist'], "r")
f = open(settings['hashlist'], "r", encoding="utf8")
for line in f:
line = line.rstrip()
blkindex.append(line)
@ -251,7 +251,7 @@ if __name__ == '__main__':
print("Usage: linearize-data.py CONFIG-FILE")
sys.exit(1)
f = open(sys.argv[1])
f = open(sys.argv[1], encoding="utf8")
for line in f:
# skip comment lines
m = re.search('^\s*#', line)

View File

@ -79,7 +79,7 @@ if __name__ == '__main__':
print("Usage: linearize-hashes.py CONFIG-FILE")
sys.exit(1)
f = open(sys.argv[1])
f = open(sys.argv[1], encoding="utf8")
for line in f:
# skip comment lines
m = re.search('^\s*#', line)

View File

@ -126,10 +126,10 @@ def main():
g.write(' * Each line contains a 16-byte IPv6 address and a port.\n')
g.write(' * IPv4 as well as onion addresses are wrapped inside a IPv6 address accordingly.\n')
g.write(' */\n')
with open(os.path.join(indir,'nodes_main.txt'),'r') as f:
with open(os.path.join(indir,'nodes_main.txt'),'r', encoding="utf8") as f:
process_nodes(g, f, 'pnSeed6_main', 8233)
g.write('\n')
with open(os.path.join(indir,'nodes_test.txt'),'r') as f:
with open(os.path.join(indir,'nodes_test.txt'),'r', encoding="utf8") as f:
process_nodes(g, f, 'pnSeed6_test', 18233)
g.write('#endif // BITCOIN_CHAINPARAMSSEEDS_H\n')