Ian Kelly wrote:
If you want your output to behave that way, then all you have to do is
specify that with an explicit encode step.
ok
If we want we change default for whatever we want, but without this
default change Python should not change his behavior depending on
output. yeah I prefer
2011/6/14 Sérgio Monteiro Basto sergi...@sapo.pt:
And see, I can send ascii and utf-8 to utf-8 output and never have problems,
but if I send ascii and utf-8 to ascii files sometimes got encode errors.
If something fits inside 7-bit ASCII, it is by definition valid UTF-8.
This is not a
Le 09/06/2011 04:18, Sérgio Monteiro Basto a écrit :
hi,
cat test.py
#!/usr/bin/env python
#-*- coding: utf-8 -*-
u = u'moçambique'
print u.encode(utf-8)
print u
chmod +x test.py
../test.py
moçambique
moçambique
The following tries to encode before to print. If you pass an already
Ben Finney wrote:
What should it decode to, then?
UTF-8, as in tty
But when you explicitly redirect to a file, it's not going to a TTY.
It's going to a file whose encoding isn't known unless you specify it.
ok after thinking about this, this problem exist because Python want be
smart
2011/6/10 Sérgio Monteiro Basto sergi...@sapo.pt:
ok after thinking about this, this problem exist because Python want be
smart with ttys, which is in my point of view is wrong, should not encode to
utf-8, because tty is in utf-8. Python should always encode to the same
thing. If the default
2011/6/11 Sérgio Monteiro Basto sergi...@sapo.pt:
ok after thinking about this, this problem exist because Python want be
smart with ttys
The *anomaly* (not problem) exists because Python has a way of being
told a target encoding. If two parties agree on an encoding, they can
send characters to
Benjamin Kaplan wrote:
2011/6/8 Sérgio Monteiro Basto sergi...@sapo.pt:
hi,
cat test.py
#!/usr/bin/env python
#-*- coding: utf-8 -*-
u = u'moçambique'
print u.encode(utf-8)
print u
chmod +x test.py
./test.py
moçambique
moçambique
./test.py output.txt
Traceback (most recent call
Ben Finney wrote:
Sérgio Monteiro Basto sergi...@sapo.pt writes:
./test.py
moçambique
moçambique
In this case your terminal is reporting its encoding to Python, and it's
capable of taking the UTF-8 data that you send to it in both cases.
./test.py output.txt
Traceback (most recent
On Thu, 09 Jun 2011 22:14:17 +0100, Sérgio Monteiro Basto wrote:
Exactly the opposite , if python don't know the encoding should not try
decode to ASCII.
What should it decode to, then?
You can't write characters to a stream, only bytes.
I want python don't care about encoding terminal and
Sérgio Monteiro Basto sergi...@sapo.pt writes:
Ben Finney wrote:
In this case your shell has no preference for the encoding (since
you're redirecting output to a file).
How I say to python that I want that write in utf-8 to files ?
You already did:
In the first print statement you
On 6/9/2011 5:46 PM, Nobody wrote:
On Thu, 09 Jun 2011 22:14:17 +0100, Sérgio Monteiro Basto wrote:
Exactly the opposite , if python don't know the encoding should not try
decode to ASCII.
What should it decode to, then?
You can't write characters to a stream, only bytes.
I want python
Sérgio Monteiro Basto sergi...@sapo.pt wrote in message
news:4df137a7$0$30580$a729d...@news.telepac.pt...
How I change sys.stdout.encoding always to UTF-8 ? at least have a
consistent sys.stdout.encoding
There is an environment variable that can force Python I/O to be a specfic
encoding:
Nobody wrote:
Exactly the opposite , if python don't know the encoding should not try
decode to ASCII.
What should it decode to, then?
UTF-8, as in tty, how I change this default ?
You can't write characters to a stream, only bytes.
ok got the point .
Thanks,
--
Mark Tolonen wrote:
Sérgio Monteiro Basto sergi...@sapo.pt wrote in message
news:4df137a7$0$30580$a729d...@news.telepac.pt...
How I change sys.stdout.encoding always to UTF-8 ? at least have a
consistent sys.stdout.encoding
There is an environment variable that can force Python I/O to
Sérgio Monteiro Basto sergi...@sapo.pt writes:
Nobody wrote:
Exactly the opposite , if python don't know the encoding should not
try decode to ASCII.
Are you advocating that Python should refuse to write characters unless
the encoding is specified? I could sympathise with that, but
Ben Finney wrote:
Exactly the opposite , if python don't know the encoding should not
try decode to ASCII.
Are you advocating that Python should refuse to write characters unless
the encoding is specified? I could sympathise with that, but currently
that's not what Python does; instead
Le 09/06/2011 04:18, Sérgio Monteiro Basto a écrit :
hi,
cat test.py
#!/usr/bin/env python
#-*- coding: utf-8 -*-
u = u'moçambique'
print u.encode(utf-8)
print u
chmod +x test.py
../test.py
moçambique
moçambique
The following tries to encode before to print. If you pass an already
Le 09/06/2011 04:18, Sérgio Monteiro Basto a écrit :
hi,
cat test.py
#!/usr/bin/env python
#-*- coding: utf-8 -*-
u = u'moçambique'
print u.encode(utf-8)
print u
chmod +x test.py
../test.py
moçambique
moçambique
The following tries to encode before to print. If you pass an already
hi,
cat test.py
#!/usr/bin/env python
#-*- coding: utf-8 -*-
u = u'moçambique'
print u.encode(utf-8)
print u
chmod +x test.py
./test.py
moçambique
moçambique
./test.py output.txt
Traceback (most recent call last):
File ./test.py, line 5, in module
print u
UnicodeEncodeError: 'ascii'
Sérgio Monteiro Basto sergi...@sapo.pt writes:
./test.py
moçambique
moçambique
In this case your terminal is reporting its encoding to Python, and it's
capable of taking the UTF-8 data that you send to it in both cases.
./test.py output.txt
Traceback (most recent call last):
File
2011/6/8 Sérgio Monteiro Basto sergi...@sapo.pt:
hi,
cat test.py
#!/usr/bin/env python
#-*- coding: utf-8 -*-
u = u'moçambique'
print u.encode(utf-8)
print u
chmod +x test.py
./test.py
moçambique
moçambique
./test.py output.txt
Traceback (most recent call last):
File ./test.py,
21 matches
Mail list logo