Skip to content

ISO 3166 Output UTF-8 Encoding #22

Closed
wants to merge 1 commit into from
+11 −11
View
22 iso_3166_codes/parse.py
@@ -1,11 +1,11 @@
#!/usr/bin/python
-# -*- coding: utf-8 -*-
# Released under the GPL v2 license
# https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
import lxml.etree, lxml.html
import re
+import codecs
url = "http://www.iso.org/iso/list-en1-semic-3.txt"
title = "ISO 3166 Country Codes"
@@ -20,26 +20,26 @@
#Read and throw out first line
input_file.readline()
-output_file = open( outp, "w")
+output_file = codecs.open( outp, "w", encoding="utf-8")
#Loop thru the remainder of the file, format each line
#and print it to the output file.
for line in input_file.readlines() :
- line = line.strip();
- pair = line.split( ';' );
+ line = line.strip()
+ pair = line.split( ';' )
if len( pair ) < 2 :
continue;
- output_file.write( "\t".join ( [ pair[ 1 ],
+ output_file.write( "\t".join ( [ pair[ 1 ],
"",
url,
- pair[ 0 ],
+ pair[0],
"",
"",
"",
- "" ] )
- );
- output_file.write( "\n" );
+ "" ] ).decode('latin-1')
+ )
+ output_file.write( "\n" )
-input_file.close();
-output_file.close();
+input_file.close()
+output_file.close()
Something went wrong with that request. Please try again.