[Chicago] Fwd: Message from contact form: Code for recognizing UTF-8 encoded inputt

Jordan Bettis jordanb at hafd.org
Thu Apr 10 18:09:31 CEST 2014


This should work, although I didn't test it. ISO-8859-5 is Cyrillic. If
you want to work with Latin1 you'll have to change it to ISO-8859-1:


import os, sys, string, math, re, shutil, codecs

f= open('testfile.txt', 'w', encoding='utf-8')

inword = input("\nEnter the word to test:  ")
inword = inword.decode("iso-8859-5")

print("=========================\n")
if inword == "":
	print("\nYou just hit return; not a word\n")
else:
	print("\nYour word was "+inword+"\n")
	
f.write(inword)
f.close

endit = input("\nType enter to exit program")




On 04/09/2014 03:39 PM, Robert Dean wrote:
> Hello,
>  
> This is a very embarrassing "baby" Python question.  But a Python coding
> friend of mine in AZ won't be able for consulting until over a month from
> now. 
>  
> To summarize the garbled message below,  would appreciate knowing
> how to modify the attached testword1.py code so that it can both recognize
> input unicode characters  a n d  output them correctly in a UTF-8 encoded
> file.  As it stands:  n o  Cyrillic characters are recognized, only some
> Greek
> characters are, and Latin-1 accented characters are mostly (but not  a l l)
> recognized.
>  
> Bob Dean
>  Chicago
>  
> robertBdean at gmail.com <mailto:robertBdean at gmail.com>
>  
>   
> 
> ---------- Forwarded message ----------
> From: *Cezar Jenkins* <emperorcezar at gmail.com
> <mailto:emperorcezar at gmail.com>>
> Date: Wed, Apr 9, 2014 at 9:25 AM
> Subject: Re: Message from contact form: Code for recognizing UTF-8
> encoded inputt
> To: robertbdean at gmail.com <mailto:robertbdean at gmail.com>
> Cc: brianhray at gmail.com <mailto:brianhray at gmail.com>
> 
> 
> Hello,
> 
> The contact form only goes to a few Chipy organizers. To answer your
> question, you’ll probably want to post to our mailing list. You can find
> a link to it on our homepage.
> 
> Thanks!
> 
> -- 
> Cezar Jenkins
> @emperorcezar
> 
> From: donotreply at chipy.org <mailto:donotreply at chipy.org>
> donotreply at chipy.org <mailto:donotreply at chipy.org>
> Reply: robertbdean at gmail.com <mailto:robertbdean at gmail.com>
> robertbdean at gmail.com <mailto:robertbdean at gmail.com>
> Date: April 9, 2014 at 12:39:02 AM
> To: emperorcezar at gmail.com <mailto:emperorcezar at gmail.com>
> emperorcezar at gmail.com <mailto:emperorcezar at gmail.com>,
> brianhray at gmail.com <mailto:brianhray at gmail.com> brianhray at gmail.com
> <mailto:brianhray at gmail.com>
> Subject: Message from contact form: Code for recognizing UTF-8 encoded
> inputt
> 
>>
>> Message from the contact form
>> Sender: Robert Dean (robertbdean at gmail.com
>> <mailto:robertbdean at gmail.com>)
>> Category:
>> The message follows.
>> ================================================================================
>>
>> Hi,
>>
>> A friend of mine has been writing some Python code for me to
>> "massage" output files from a stat. program we're
>> maintaining. The issue is what lines to add to several Python programs
>> so that they blow don't up when encountering unicode characters.
>> I'm aware of the pieces of the required code to specify that an
>> input file is UTF-8 encoded. B u t , I'm not a Python programmer
>> myself. And my friend won't be available to help me until mid-May
>> at the soonest. Could someone contact about a solution? THANKS. Bob
>> Dean, Chicago
>> ================================================================================
>>
>>
>> -- 
>> message sent with envelope - a contact form app for Django
> 
> 
> 
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> https://mail.python.org/mailman/listinfo/chicago
> 



More information about the Chicago mailing list