Help needed with python unicode cgi-bin script

2007-12-09 Thread weheh
Dear web gods: After much, much, much struggle with unicode, many an hour reading all the examples online, coding them, testing them, ripping them apart and putting them back together, I am humbled. Therefore, I humble myself before you to seek guidance on a simple python unicode cgi-bin script

Re: Help needed with python unicode cgi-bin script

2007-12-10 Thread weheh
Thanks for the reply, Jack. I tried setting mode to binary but it had no affect. "Jack" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > You probably need to set stdout mode to binary. They are not by default on > Windows. > > > "weheh" <

Re: Help needed with python unicode cgi-bin script

2007-12-10 Thread weheh
Hi Martin, thanks for your response. My updates are interleaved with your response below: > What is the encoding of that file? Without a correct answer to that > question, you will not be able to achieve what you want. I don't know for sure the encoding of the file. I'm assuming it has no intrin

Re: Help needed with python unicode cgi-bin script

2007-12-11 Thread weheh
import sys if sys.platform == "win32": import os, msvcrt msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) "Jack" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Just want to make sure, how exactly are you doing that? > >> Thanks for the reply, Jack. I tried setting mode to

Re: Help needed with python unicode cgi-bin script

2007-12-11 Thread weheh
Hi John: Thanks for responding. >Look at your file using > print repr(open('c:/test/spanish.txt','rb').read()) >If you see 'a\xf1o' then use charset="windows-1252" I did this ... no change ... still see 'a\xf1o' >else if you see 'a\xc3\xb1o' then use charset="utf-8" else >Based on your

Re: Help needed with python unicode cgi-bin script

2007-12-11 Thread weheh
John & Martin, Thanks for your help and kind words of encouragement. Still, what you have suggested doesn't seem to work, unless I'm not understanding your directive to encode as 'windows-1252'. Here's my program in full: #!C:/Program Files/Python23/python.exe import cgi, cgitb import sys, code

Re: Help needed with python unicode cgi-bin script

2007-12-11 Thread weheh
> What does the browser say what the encoding of the page is? > > What browser are you using, and did you configure it to default to > UTF-8 for all pages? (which you should not have done) > Browser is both IE and Firefox. IE is defaulting to UTF8. If I force it to "Encoding > Western European (Wi

Re: Help needed with python unicode cgi-bin script

2007-12-11 Thread weheh
p.s. I modified the code to break things out more explicitly: #!C:/Program Files/Python23/python.exe import cgi, cgitb import sys, codecs import os,msvcrt cgitb.enable() print u"""Content-Type: text/html http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"; > http://www.w3.org/1999/xhtml";

Re: Help needed with python unicode cgi-bin script

2007-12-11 Thread weheh
John and Martin, Thanks for your help. However, I have identified the culprit to be with Apache and the command: AddDefaultCharset utf-8 which forces my browser to utf-8 encoding. It looks like your suggestions to change charset were incorrect. My example works equally well with charset=utf

Re: Help needed with python unicode cgi-bin script

2007-12-12 Thread weheh
Hi Duncan, thanks for the reply. >> > FWIW, the code you posted only ever attempted to set the character set > encoding using an html meta tag which is the wrong place to set it. The > encoding specified in the HTTP headers always takes precedence. This is > why > the default charset setting in Ap

How to get Python to default to UTF8

2007-12-21 Thread weheh
I'm developing a cgi-bin application that must be unicode sensitive. I'm striving for a UTF8 implementation. I'm running python 2.3 on a development machine (windows xp) and a server (windows xp server). Both environments are running Apache 2.2 with the same configuration file. The problem is t

Re: How to get Python to default to UTF8

2007-12-22 Thread weheh
your questions, in this example, I believe the exception was caused by trying to do a count of the number of times a string appears in an array. One of the strings was unicode and the other was encoded by Python by default. "Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message

Re: How to get Python to default to UTF8

2007-12-22 Thread weheh
Hi Fredrik, Thanks again for your feedback. I am much obliged. Indeed, I am forced to be exteremely rigorous about decoding on the way in and encoding on the way out everywhere in my program, just as you say. Your advice is excellent and concurs with other sources of unicode expertise. Followi

pyTTS says, '"SAPI" not supported'

2008-06-22 Thread weheh
I'm running Python 2.3 and calling pyTTS. I've had it working forever. Today, I ran out of disk space. After deleting some of my personal files, for no apparent reason, pyTTS no longer runs. For the statement tts = pyTTS.Create() I get the error message: ValueError: "SAPI" not

Re: binary number format ? format character %b or similar.

2008-06-22 Thread weheh
I don't know if you found this example: http://www.daniweb.com/code/snippet285.html -- > I'm was wanting to format a positive integer in binary, > and not finding it--to my surprise--I rolled my own version. > > Is this already in python, or have I missed it somewhere? > > I have Googled around