2011/6/14 Sérgio Monteiro Basto :
> 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 coincidence.
Those ho
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
2011/6/11 Sérgio Monteiro Basto :
> 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 each other. I
2011/6/10 Sérgio Monteiro Basto :
> 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 is ascii, shou
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
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
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
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
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
Sérgio Monteiro Basto 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 currently
that's
Mark Tolonen wrote:
>
> "Sérgio Monteiro Basto" 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
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,
--
http://mail.p
"Sérgio Monteiro Basto" 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:
PYTHONIOEN
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 don
Sérgio Monteiro Basto 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 specify t
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 a
Ben Finney wrote:
> Sérgio Monteiro Basto 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
Benjamin Kaplan wrote:
> 2011/6/8 Sérgio Monteiro Basto :
>> 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 (m
2011/6/8 Sérgio Monteiro Basto :
> 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
Sérgio Monteiro Basto 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 "./test.py", li
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
print u
UnicodeEncodeError: 'ascii' codec
21 matches
Mail list logo