On 03/18/2015 12:09 PM, Zygmunt Krynicki wrote:
> Review: Needs Fixing
>
> Hey.
>
> Have a look at my comments below
I've changed most of these things. A few further comments and queries,
though....
>> +from api_utils import APIQuery, QueryError
>
> Please put imports in this order: stdlib, 3rd party, this
> app/library. Put a newline between each group
I think I've got this, but I'm really guessing at what's what. Is this
documented somewhere?
>> + num_of_make += 1 + grand_total += 1 +
>> print make.encode('utf-8') + ": " + str(num_of_make)
>
> This is a code smell, don't do this.
>
> Either move to all unicode strings internally or use all bytes and
> hope for the best. Why make needs this treatment now? I assume you
> get an unicode string from the API, correct?
The problem isn't with internal string handling; it's with what
happens when running the script with redirection when
".encode('utf-8')" is dropped:
$ ./get_ytd_makes.py {blah blah blah} > foo.txt
Traceback (most recent call last):
File "./get_ytd_makes.py", line 137, in <module>
sys.exit(main())
File "./get_ytd_makes.py", line 119, in main
print (make + ": " + str(num_of_make))
UnicodeEncodeError: 'ascii' codec can't encode characters in position
17-24: ordinal not in range(128)
It works fine when sending output to the console (or at least, an X
terminal), but when redirecting, it runs into this crash when a name
includes non-ASCII characters. (The trouble point for us is NEC, which
is encoded as "NEC Corporation (日本電気株式会社)"). I've Googled this
to death and using ".encode('utf-8')" is the only solution I've found
that works. (I've tried several ways of explicitly marking strings as
Unicode, and they all fail in one way or another.) If you have another
solution, I'm quite willing to try it.
- --
Rod Smith
Server and Cloud Certification Engineer
<email address hidden>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 03/18/2015 12:09 PM, Zygmunt Krynicki wrote:
> Review: Needs Fixing
>
> Hey.
>
> Have a look at my comments below
I've changed most of these things. A few further comments and queries,
though....
>> +from api_utils import APIQuery, QueryError
>
> Please put imports in this order: stdlib, 3rd party, this
> app/library. Put a newline between each group
I think I've got this, but I'm really guessing at what's what. Is this
documented somewhere?
>> + num_of_make += 1 + grand_total += 1 + 'utf-8' ) + ": " + str(num_of_make)
>> print make.encode(
>
> This is a code smell, don't do this.
>
> Either move to all unicode strings internally or use all bytes and
> hope for the best. Why make needs this treatment now? I assume you
> get an unicode string from the API, correct?
The problem isn't with internal string handling; it's with what
happens when running the script with redirection when
".encode('utf-8')" is dropped:
$ ./get_ytd_makes.py {blah blah blah} > foo.txt ytd_makes. py", line 137, in <module> exit(main( )) ytd_makes. py", line 119, in main
Traceback (most recent call last):
File "./get_
sys.
File "./get_
print (make + ": " + str(num_of_make))
UnicodeEncodeError: 'ascii' codec can't encode characters in position
17-24: ordinal not in range(128)
It works fine when sending output to the console (or at least, an X
terminal), but when redirecting, it runs into this crash when a name
includes non-ASCII characters. (The trouble point for us is NEC, which
is encoded as "NEC Corporation (日本電気株式会社)"). I've Googled this
to death and using ".encode('utf-8')" is the only solution I've found
that works. (I've tried several ways of explicitly marking strings as
Unicode, and they all fail in one way or another.) If you have another
solution, I'm quite willing to try it.
- --
Rod Smith
Server and Cloud Certification Engineer
<email address hidden>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQEcBAEBAgAGBQJ VCdlhAAoJEFgyRI +V0FjmunMH/ A+3z/c5e6L7WB3Q VHaezDZx 2jpdOiAxYQoGqK2 RNMGL+3DZDVTiDY bbqOwG/ 13sZ6bWUXg2p ys4HoiPskMjLYHS /4TUmOeJnWFMZ4y NY69Gzb08Y+ emzavPDe O99U1SwmU0YcTx6 8oOt2hPlywOYsHt gQP1TKoGWb/ iwrOUnVI QtNfPWUYvVlwFzd 096LnhloSa6ujS3 Yv7NUls6Va/ X+vS/mcs 6hCviOKNyEFcuKP /aJb/L5cd7uGjF7 mUSBxEZeuyF7AVy SMgROw=
jkvUeZjI3BPwKHI
JT1Hvl8yUllOLjy
KZVw2Uxi36bZXBi
qE7W3Ho3zkc17Li
60dWgE0Agnc+
=LSKD
-----END PGP SIGNATURE-----