Permalink
Browse files

Changed coding of output file to utf-8

  • Loading branch information...
1 parent 13037f9 commit 82d0faebfebcbc340c54ca57a7aa3dae06e37011 @cjfarrar committed May 22, 2012
Showing with 11 additions and 11 deletions.
  1. +11 −11 iso_3166_codes/parse.py
View
@@ -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()

0 comments on commit 82d0fae

Please sign in to comment.