Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #54883 > unrolled thread
| Started by | dream4soul@gmail.com |
|---|---|
| First post | 2013-09-27 06:54 -0700 |
| Last post | 2013-09-30 23:23 -0700 |
| Articles | 5 — 3 participants |
Back to article view | Back to comp.lang.python
what is wrong in my code?? (python 3.3) dream4soul@gmail.com - 2013-09-27 06:54 -0700
Re: what is wrong in my code?? (python 3.3) Denis McMahon <denismfmcmahon@gmail.com> - 2013-09-27 16:19 +0000
Re: what is wrong in my code?? (python 3.3) dream4soul@gmail.com - 2013-09-30 07:17 -0700
Re: what is wrong in my code?? (python 3.3) Piet van Oostrum <piet@vanoostrum.org> - 2013-09-30 14:00 -0400
Re: what is wrong in my code?? (python 3.3) dream4soul@gmail.com - 2013-09-30 23:23 -0700
| From | dream4soul@gmail.com |
|---|---|
| Date | 2013-09-27 06:54 -0700 |
| Subject | what is wrong in my code?? (python 3.3) |
| Message-ID | <c1d453ae-c79e-4fe9-ae3f-b1eb5780e347@googlegroups.com> |
#!c:/Python33/python.exe -u
import os, sys
print("Content-type: text/html; charset=utf-8\n\n")
print ('Hello, world!<hr>')
print('ранее предусматривалась смертная казнь.')
I see only first print, second it just question marks in my browser(code edited in notepad++ with UTF-8 encode).
what is wrong??
[toc] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2013-09-27 16:19 +0000 |
| Message-ID | <l24b71$j2k$3@dont-email.me> |
| In reply to | #54883 |
On Fri, 27 Sep 2013 06:54:48 -0700, dream4soul wrote:
> #!c:/Python33/python.exe -u
> import os, sys
> print("Content-type: text/html; charset=utf-8\n\n")
> print ('Hello, world!<hr>')
> print('ранее предусматривалась смертная казнь.')
> I see only first print, second it just question marks in my browser(code
> edited in notepad++ with UTF-8 encode). what is wrong??
Sounds like your browser is ignoring the charset. Can you force the
browser to utf-8?
What happens if you create a plain html file with the same content and
send it to your browser?
eg: test.html:
-----------------
Hello, world!<hr>
ранее предусматривалась смертная казнь.
-----------------
This really doesn't look like a python issue (again).
--
Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | dream4soul@gmail.com |
|---|---|
| Date | 2013-09-30 07:17 -0700 |
| Message-ID | <d7ea53a9-b909-4977-953a-3a3222499d3d@googlegroups.com> |
| In reply to | #54894 |
On Friday, September 27, 2013 7:19:45 PM UTC+3, Denis McMahon wrote:
> On Fri, 27 Sep 2013 06:54:48 -0700, dream4soul wrote:
>
>
>
> > #!c:/Python33/python.exe -u
>
> > import os, sys
>
> > print("Content-type: text/html; charset=utf-8\n\n")
>
> > print ('Hello, world!<hr>')
>
> > print('ранее предусматривалась смертная казнь.')
>
>
>
> > I see only first print, second it just question marks in my browser(code
>
> > edited in notepad++ with UTF-8 encode). what is wrong??
>
>
>
> Sounds like your browser is ignoring the charset. Can you force the
>
> browser to utf-8?
>
>
>
> What happens if you create a plain html file with the same content and
>
> send it to your browser?
>
>
>
> eg: test.html:
>
> -----------------
>
> Hello, world!<hr>
>
> ранее предусматривалась смертная казнь.
>
> -----------------
>
>
>
> This really doesn't look like a python issue (again).
>
>
>
> --
>
> Denis McMahon, denismfmcmahon@gmail.com
I rename file from test.py in test.txt and all works fine. So clearly problem it is not in file coding or browser. ANY IDEAS??
[toc] | [prev] | [next] | [standalone]
| From | Piet van Oostrum <piet@vanoostrum.org> |
|---|---|
| Date | 2013-09-30 14:00 -0400 |
| Message-ID | <m238om5gwh.fsf@cochabamba.vanoostrum.org> |
| In reply to | #55076 |
dream4soul@gmail.com writes:
> I rename file from test.py in test.txt and all works fine. So clearly problem it is not in file coding or browser. ANY IDEAS??
It looks like the encoding of stdout is not utf-8 in the CGI script. Check it with
import sys
print(sys.stdout.encoding)
If it's not utf-8, you must force your output to be utf-8, as that is what the browser expects, because of your Content-type.
You could use:
sys.stdout.buffer.write('ранее предусматривалась смертная казнь.'.encode('utf-8'))
Or to change stdout into utf-8 encoding:
import codecs
sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
[Note: I haven't tested this]
--
Piet van Oostrum <piet@vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
[toc] | [prev] | [next] | [standalone]
| From | dream4soul@gmail.com |
|---|---|
| Date | 2013-09-30 23:23 -0700 |
| Message-ID | <cbbf0864-a2f3-4fb7-94ce-e3a9e93d3a89@googlegroups.com> |
| In reply to | #55095 |
COOL!!!
> print(sys.stdout.encoding)
show cp1251
> sys.stdout.buffer.write('ранее предусматривалась смертная казнь.'.encode('utf-8'))
works fine!!!
>
> sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
>
this fix the print problem!!!
Big Thank Piet van Oostrum
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web