Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > pl.comp.programming > #29044

Re: python i stringi

Path csiph.com!feeder.erje.net!2.eu.feeder.erje.net!ecngs!feeder2.ecngs.de!81.171.118.63.MISMATCH!peer03.fr7!futter-mich.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-01.news.neostrada.pl!unt-spo-a-01.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail
From Roman Tyczka <noemail@because.no>
Subject Re: python i stringi
Newsgroups pl.comp.programming
User-Agent 40tude_Dialog/2.0.15.84
MIME-Version 1.0
Content-Type text/plain; charset="utf-8"
Content-Transfer-Encoding 8bit
Sender romek@tyczka.no.found
References <19jwk9uqtvyxa.dlg@tyczka.com> <c6b8c3a0-596d-445b-9951-5c16248b11b9@googlegroups.com> <zdk42d2gkady.dlg@tyczka.com> <aba1993f-ebae-4a5c-88d3-42b46e803a3a@googlegroups.com>
Date Thu, 6 Oct 2016 10:44:12 +0200
Message-ID <8uxdbqmk73pz.dlg@tyczka.com> (permalink)
Lines 44
Organization Telekomunikacja Polska
NNTP-Posting-Host nat.wave.com.pl
X-Trace 1475743452 unt-rea-a-02.news.neostrada.pl 15208 91.224.116.2:5380
X-Complaints-To abuse@news.neostrada.pl
X-Received-Bytes 2470
X-Received-Body-CRC 3153559511
Xref csiph.com pl.comp.programming:29044

Show key headers only | View raw


On Thu, 6 Oct 2016 01:32:07 -0700 (PDT), godek.maciek@gmail.com wrote:

> W dniu czwartek, 6 października 2016 10:19:26 UTC+2 użytkownik Roman Tyczka 
>>>>>>> ustr = u"Jeszcze dłuższy i bardzo długi string z ółęść oraz ;%$#@[ i innymi znakami 0099786764553 na końcu"
>>>>>>> type(ustr)
>>>> <type 'unicode'>
>>>>>>> hashlib.md5(ustr).hexdigest()
>>>> Traceback (most recent call last):
>>>>   File "<stdin>", line 1, in <module>
>>>> UnicodeEncodeError: 'ascii' codec can't encode character u'\u0142' in
>>>> position 9: ordinal not in range(128)
>>>> 
>>>> Jak wybrnąć i policzyć jednak tego hasha?
>>>> 
>>>> ps. python 2.7.9 na windows
>>> 
>>> może np. google python unicode to ascii
>> 
>> Po pierwsze nie da się konwertować unicode do ascii.
>> 
>> Poza tym ja nic nie chcę konwertować, chcę by był potraktowany jako
>> unicodowy właśnie, czyli de facto dwubajtowy znak.
> 
> to może google python unicode to bytes
> python bytes to string
> python md5 unicode

Jeśli chcesz mi utrzeć nosa tym googlem to ...hmmm, niepotrzebnie. Od
googla zacząłem. Ale ok, może grupa dyskusyjna służy tylko do kłótni o
pascala.
Tak czy owak problem rozwiązałem, nie konwertując do ascii czy tablicy
bajtów, ale poprawnie deklarując typ unicodowego stringa. I na taką
praktyczną radę liczyłem.

Dla potomnych:

ustr = u"Jeszcze dłuższy i bardzo długi string z ółęść oraz ;%$#@[ i innymi
znakami 0099786764553 na końcu".encode('utf-16le')

i ten mały indianin zrobił swoją robotę :-)

-- 
pozdrawiam
Roman Tyczka

Back to pl.comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

python i stringi Roman Tyczka <noemail@because.no> - 2016-10-06 09:46 +0200
  Re: python i stringi godek.maciek@gmail.com - 2016-10-06 01:10 -0700
    Re: python i stringi Roman Tyczka <noemail@because.no> - 2016-10-06 10:19 +0200
      Re: python i stringi godek.maciek@gmail.com - 2016-10-06 01:32 -0700
        Re: python i stringi Roman Tyczka <noemail@because.no> - 2016-10-06 10:44 +0200
          Re: python i stringi Piotr Chamera <piotr_chamera@poczta.onet.pl> - 2016-10-06 12:14 +0200
            Re: python i stringi Roman Tyczka <noemail@because.no> - 2016-10-06 12:32 +0200
              Re: python i stringi Piotr Chamera <piotr_chamera@poczta.onet.pl> - 2016-10-06 13:22 +0200
  Re: python i stringi Piotr Chamera <piotr_chamera@poczta.onet.pl> - 2016-10-06 10:57 +0200
    Re: python i stringi Roman Tyczka <noemail@because.no> - 2016-10-06 11:22 +0200
      Re: python i stringi Piotr Chamera <piotr_chamera@poczta.onet.pl> - 2016-10-06 11:50 +0200

csiph-web