From 71ee9ed0541632bfe87663883de00ebc4acc0e71 Mon Sep 17 00:00:00 2001 From: Tisham Dhar Date: Fri, 8 Sep 2017 11:35:19 +0930 Subject: [PATCH 1/2] Add caveat for parsing files from disk The file parsing does not note encoding caveats. Included this for people using files with unicode encoding. A kludge for now till proper from_file method is introduced. --- docs/usage_guide.rst | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/usage_guide.rst b/docs/usage_guide.rst index adaebe2a..6c75a518 100644 --- a/docs/usage_guide.rst +++ b/docs/usage_guide.rst @@ -93,7 +93,7 @@ Example how to build a simple KML file from the Python interpreter. -Read a KML File +Read a KML File/String --------------- You can create a KML object by reading a KML file as a string @@ -102,7 +102,14 @@ You can create a KML object by reading a KML file as a string # Start by importing the kml module >>> from fastkml import kml - + + #Read file into string and convert to UTF-8 + >>> with open(kml_file, 'r') as myfile: + ... data=myfile.read().replace('\n', '') + >>> doc = data.encode('utf-8') + + # OR + # Setup the string which contains the KML file we want to read >>> doc = """ ... From 20dc024c8f843559658d5b17fe88571e6246ec92 Mon Sep 17 00:00:00 2001 From: Tisham Dhar Date: Wed, 4 Oct 2017 11:45:51 +1030 Subject: [PATCH 2/2] Encode in open --- docs/usage_guide.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/usage_guide.rst b/docs/usage_guide.rst index 6c75a518..e7d0699a 100644 --- a/docs/usage_guide.rst +++ b/docs/usage_guide.rst @@ -103,10 +103,9 @@ You can create a KML object by reading a KML file as a string # Start by importing the kml module >>> from fastkml import kml - #Read file into string and convert to UTF-8 - >>> with open(kml_file, 'r') as myfile: - ... data=myfile.read().replace('\n', '') - >>> doc = data.encode('utf-8') + #Read file into string and convert to UTF-8 (Python3 style) + >>> with open(kml_file, 'rt', encoding="utf-8") as myfile: + ... doc=myfile.read() # OR