Dr. Dobb's Python-URL! - weekly Python news and links (Dec 30)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cameron Laird

    #1

    Dr. Dobb's Python-URL! - weekly Python news and links (Dec 30)

    QOTW: "I found the discussion of unicode, in any python book I have,
    insufficient." -- Thomas Heller

    "If you develop on a Mac, ... Objective-C could come in handy. . . .
    PyObjC makes mixing the two languages dead easy and more convenient than
    indoor plumbing." -- Robert Kern


    Among other activities, the PSF aggregates donors with dollars
    destined to do good Python works, and developers expert in
    obscure corners of Pythonia.



    Yippee! The martellibot promises to explain Unicode for Pythoneers.


    The glorious SciPy project supports *multiple* worthwhile Wikis.


    Good style in Python does not generally include "in-place"
    operations on lists. Several cleaner idioms are possible.


    Assume you're comfortable with tuples' semantics, immutability,
    and so on. Do you correctly understand the basics of their
    syntax, though? This is another opportunity to think about
    Unicode, by the way.


    Robert Kern, Paul Rubin, Mike Meyer, Alex Martelli, and others
    provide disproportionat ely high-quality advice (and tangents!)
    on the subject of languages which complement Python.



    =============== =============== =============== =============== ============
    Everything Python-related you want is probably one or two clicks away in
    these pages:

    Python.org's Python Language Website is the traditional
    center of Pythonia
    The official home of the Python Programming Language

    Notice especially the master FAQ
    The official home of the Python Programming Language


    PythonWare complements the digest you're reading with the
    marvelous daily python url
    Archived chronological index of historical news updates, core milestones, and technical commentaries from the Python development universe.

    Mygale is a news-gathering webcrawler that specializes in (new)
    World-Wide Web articles related to Python.

    While cosmetically similar, Mygale and the Daily Python-URL
    are utterly different in their technologies and generally in
    their results.

    comp.lang.pytho n.announce announces new Python software. Be
    sure to scan this newsgroup weekly.


    Brett Cannon continues the marvelous tradition established by
    Andrew Kuchling and Michael Hudson of intelligently summarizing
    action on the python-dev mailing list once every other week.
    The official home of the Python Programming Language


    The Python Package Index catalogues packages.
    The Python Package Index (PyPI) is a repository of software for the Python programming language.


    The somewhat older Vaults of Parnassus ambitiously collects references
    to all sorts of Python resources.


    Much of Python's real work takes place on Special-Interest Group
    mailing lists


    The Python Business Forum "further[s] the interests of companies
    that base their business on ... Python."
    Explore Sydney's vibrant art scene from street art in laneways to independent galleries, pop-up shows, and creative workshops inspiring tech professionals and creatives alike.


    Python Success Stories--from air-traffic control to on-line
    match-making--can inspire you or decision-makers to whom you're
    subject with a vision of what the language makes practical.


    The Python Software Foundation (PSF) has replaced the Python
    Consortium as an independent nexus of activity. It has official
    responsibility for Python's development and maintenance.

    Among the ways you can support PSF is with a donation.
    The official home of the Python Programming Language


    Kurt B. Kaiser publishes a weekly report on faults and patches.


    Cetus collects Python hyperlinks.
    Keunggulan utama MEGASLOTO terletak pada penerapan RTP gacor yang akurat dan konsisten. Data RTP membantu pemain menentukan strategi bermain dengan lebih terarah, terutama bagi yang memulai dengan modal kecil. Sistem ini mendukung kemenangan bertahap, menjadikan target menang besar lebih realistis dan tidak sekadar mengandalkan keberuntungan. Member baru pun diuntungkan karena permainan tidak terasa berat di awal. Dengan ritme yang stabil, pemain dapat mengelola modal secara efisien dan meningkatkan peluang hasil maksimal dalam jangka menengah hingga panjang.


    Python FAQTS
    http://python.faqts.com/

    The Cookbook is a collaborative effort to capture useful and
    interesting recipes.


    Among several Python-oriented RSS/RDF feeds available are



    For more, see

    The old Python "To-Do List" now lives principally in a
    SourceForge reincarnation.
    http://sourceforge.net/tracker/?atid...70&func=browse


    The online Python Journal is posted at pythonjournal.c ognizor.com.
    editor@pythonjo urnal.com and editor@pythonjo urnal.cognizor. com
    welcome submission of material that helps people's understanding
    of Python use, and offer Web presentation of your work.

    deli.cio.us presents an intriguing approach to reference commentary.
    It already aggregates quite a bit of Python intelligence.


    *Py: the Journal of the Python Language*
    Pyzine, le magazine indépendant : des articles fouillés, vérifiés et utiles sur la tech, la culture, les voyages et l'art de vivre.


    Archive probing tricks of the trade:



    Previous - (U)se the (R)esource, (L)uke! - messages are listed here:

    http://purl.org/thecliff/python/url.html (dormant)
    or
    http://groups.google.c om/groups?oi=djq&a s_q=+Python-URL!&as_ugroup= comp.lang.pytho n


    Suggestions/corrections for next week's posting are always welcome.
    E-mail to <Python-URL@phaseit.net > should get through.

    To receive a new issue of this posting in e-mail each Monday morning
    (approximately) , ask <claird@phaseit .net> to subscribe. Mention
    "Python-URL!".


    -- The Python-URL! Team--

    Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and
    sponsor the "Python-URL!" project.


  • Alex Martelli

    #2
    Re: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 30)

    Cameron Laird <python-url@phaseit.net > wrote:
    ...[color=blue]
    > Yippee! The martellibot promises to explain Unicode for Pythoneers.
    > http://groups-beta.google.com/group/...15a5a05c206712[/color]

    Uh -- _did_ I? Eeep... I guess I did... mostly, I was pointing to
    Holger Krekel's very nice recipe (not sure he posted it to the site as
    well as submitting it for the printed edition, but, lobby _HIM_ about
    that;-).


    Alex

    Comment

    • holger krekel

      #3
      Re: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 30)

      On Fri, Dec 31, 2004 at 19:18 +0100, Alex Martelli wrote:[color=blue]
      > Cameron Laird <python-url@phaseit.net > wrote:
      > ...[color=green]
      > > Yippee! The martellibot promises to explain Unicode for Pythoneers.
      > > http://groups-beta.google.com/group/...15a5a05c206712[/color]
      >
      > Uh -- _did_ I? Eeep... I guess I did... mostly, I was pointing to
      > Holger Krekel's very nice recipe (not sure he posted it to the site as
      > well as submitting it for the printed edition, but, lobby _HIM_ about
      > that;-).[/color]

      FWIW, i added the recipe back to the online cookbook. It's not perfectly
      formatted but still useful, i hope.



      cheers,

      holger

      P.S: happy new year.

      Comment

      • michele.simionato@gmail.com

        #4
        Re: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 30)

        Holger:
        [color=blue]
        > FWIW, i added the recipe back to the online cookbook. It's not[/color]
        perfectly[color=blue]
        > formatted but still useful, i hope.[/color]
        [color=blue]
        > http://aspn.activestate.com/ASPN/Coo.../Recipe/361742[/color]

        Uhm... on my system I get:
        [color=blue][color=green][color=darkred]
        >>> german_ae = unicode('\xc3\x a4', 'utf8')
        >>> print german_ae # dunno if it will appear right on Google groups[/color][/color][/color]
        ä
        [color=blue][color=green][color=darkred]
        >>> german_ae.decod e('latin1')[/color][/color][/color]
        Traceback (most recent call last):
        File "<stdin>", line 1, in ?
        UnicodeEncodeEr ror: 'ascii' codec can't encode character u'\xe4' in
        position 0: ordinal not in range(128)
        ?? What's wrong?

        Michele Simionato

        Comment

        • Stephan Diehl

          #5
          Re: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 30)

          On Tue, 04 Jan 2005 05:43:32 -0800, michele.simiona to wrote:
          [color=blue]
          > Holger:
          >[color=green]
          >> FWIW, i added the recipe back to the online cookbook. It's not[/color]
          > perfectly[color=green]
          >> formatted but still useful, i hope.[/color]
          >[color=green]
          >> http://aspn.activestate.com/ASPN/Coo.../Recipe/361742[/color]
          >
          > Uhm... on my system I get:
          >[color=green][color=darkred]
          >>>> german_ae = unicode('\xc3\x a4', 'utf8')
          >>>> print german_ae # dunno if it will appear right on Google groups[/color][/color]
          > ä
          >[color=green][color=darkred]
          >>>> german_ae.decod e('latin1')[/color][/color]
          > Traceback (most recent call last):
          > File "<stdin>", line 1, in ?
          > UnicodeEncodeEr ror: 'ascii' codec can't encode character u'\xe4' in
          > position 0: ordinal not in range(128)
          > ?? What's wrong?[/color]

          I'd rather use german_ae.encod e('latin1')
          ^^^^^^

          which returns '\xe4'.[color=blue]
          >
          > Michele Simionato[/color]

          Comment

          • michele.simionato@gmail.com

            #6
            Re: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 30)

            Stephan:
            [color=blue]
            > I'd rather use german_ae.encod e('latin1')[/color]
            ^^^^^^[color=blue]
            > which returns '\xe4'.[/color]

            uhm ... then there is a misprint in the discussion of the recipe;
            BTW what's the difference between .encode and .decode ?
            (yes, I have been living in happy ASCII-land until now ... ;)
            I should probably ask for an unicode primer, I have found the
            one by Marc André Lemburg

            and I am reading it right now.


            Michele Simionato

            Comment

            • Aahz

              #7
              Unicode universe (was Re: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 30))

              In article <1104849206.111 461.70500@c13g2 000cwb.googlegr oups.com>,
              <michele.simion ato@gmail.com> wrote:[color=blue]
              >
              >BTW what's the difference between .encode and .decode ?
              >(yes, I have been living in happy ASCII-land until now ... ;)[/color]

              Here's the stark simple recipe: when you use Unicode, you *MUST* switch
              to a Unicode-centric view of the universe. Therefore you encode *FROM*
              Unicode and you decode *TO* Unicode. Period. It's similar to the way
              floating point contaminates ints.
              --
              Aahz (aahz@pythoncra ft.com) <*> http://www.pythoncraft.com/

              "19. A language that doesn't affect the way you think about programming,
              is not worth knowing." --Alan Perlis

              Comment

              • Skip Montanaro

                #8
                Re: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 30)


                michele> BTW what's the difference between .encode and .decode ?

                I started to answer, then got confused when I read the docstrings for
                unicode.encode and unicode.decode:
                [color=blue][color=green][color=darkred]
                >>> help(u"\xe4".de code)[/color][/color][/color]
                Help on built-in function decode:

                decode(...)
                S.decode([encoding[,errors]]) -> string or unicode

                Decodes S using the codec registered for encoding. encoding defaults
                to the default encoding. errors may be given to set a different error
                handling scheme. Default is 'strict' meaning that encoding errors raise
                a UnicodeDecodeEr ror. Other possible values are 'ignore' and 'replace'
                as well as any other name registerd with codecs.register _error that is
                able to handle UnicodeDecodeEr rors.
                [color=blue][color=green][color=darkred]
                >>> help(u"\xe4".en code)[/color][/color][/color]
                Help on built-in function encode:

                encode(...)
                S.encode([encoding[,errors]]) -> string or unicode

                Encodes S using the codec registered for encoding. encoding defaults
                to the default encoding. errors may be given to set a different error
                handling scheme. Default is 'strict' meaning that encoding errors raise
                a UnicodeEncodeEr ror. Other possible values are 'ignore', 'replace' and
                'xmlcharrefrepl ace' as well as any other name registered with
                codecs.register _error that can handle UnicodeEncodeEr rors.

                It probably makes sense to one who knows, but for the feeble-minded like
                myself, they seem about the same.

                I'd be happy to add a couple examples to the string methods section of the
                docs if someone will produce something simple that makes the distinction
                clear.

                Skip

                Comment

                • michele.simionato@gmail.com

                  #9
                  Re: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 30)

                  Yep, I did the same and got confused :-/

                  Michele

                  Comment

                  • Skip Montanaro

                    #10
                    Re: Unicode universe (was Re: Dr. Dobb's Python-URL! - weekly Pythonnews and links (Dec 30))

                    aahz> Here's the stark simple recipe: when you use Unicode, you *MUST*
                    aahz> switch to a Unicode-centric view of the universe. Therefore you
                    aahz> encode *FROM* Unicode and you decode *TO* Unicode. Period. It's
                    aahz> similar to the way floating point contaminates ints.

                    That's what I do in my code. Why do Unicode objects have a decode method
                    then?

                    Skip

                    Comment

                    • Thomas Heller

                      #11
                      Re: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 30)

                      Skip Montanaro <skip@pobox.com > writes:
                      [color=blue]
                      > michele> BTW what's the difference between .encode and .decode ?
                      >
                      > I started to answer, then got confused when I read the docstrings for
                      > unicode.encode and unicode.decode:
                      >[color=green][color=darkred]
                      > >>> help(u"\xe4".de code)[/color][/color]
                      > Help on built-in function decode:
                      >
                      > decode(...)
                      > S.decode([encoding[,errors]]) -> string or unicode
                      >
                      > Decodes S using the codec registered for encoding. encoding defaults
                      > to the default encoding. errors may be given to set a different error
                      > handling scheme. Default is 'strict' meaning that encoding errors raise
                      > a UnicodeDecodeEr ror. Other possible values are 'ignore' and 'replace'
                      > as well as any other name registerd with codecs.register _error that is
                      > able to handle UnicodeDecodeEr rors.
                      >[color=green][color=darkred]
                      > >>> help(u"\xe4".en code)[/color][/color]
                      > Help on built-in function encode:
                      >
                      > encode(...)
                      > S.encode([encoding[,errors]]) -> string or unicode
                      >
                      > Encodes S using the codec registered for encoding. encoding defaults
                      > to the default encoding. errors may be given to set a different error
                      > handling scheme. Default is 'strict' meaning that encoding errors raise
                      > a UnicodeEncodeEr ror. Other possible values are 'ignore', 'replace' and
                      > 'xmlcharrefrepl ace' as well as any other name registered with
                      > codecs.register _error that can handle UnicodeEncodeEr rors.
                      >
                      > It probably makes sense to one who knows, but for the feeble-minded like
                      > myself, they seem about the same.[/color]

                      It seems also the error messages aren't too helpful:
                      [color=blue][color=green][color=darkred]
                      >>> "ä".encode("lat in-1")[/color][/color][/color]
                      Traceback (most recent call last):
                      File "<stdin>", line 1, in ?
                      UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0x84 in position 0: ordinal not in range(128)[color=blue][color=green][color=darkred]
                      >>>[/color][/color][/color]

                      Hm, why does the 'encode' call complain about decoding?

                      Why do string objects have an encode method, and why do unicode objects
                      have a decode method, and what does this error message want to tell me:
                      [color=blue][color=green][color=darkred]
                      >>> u"ä".decode("la tin-1")[/color][/color][/color]
                      Traceback (most recent call last):
                      File "<stdin>", line 1, in ?
                      UnicodeEncodeEr ror: 'ascii' codec can't encode character u'\xe4' in position 0: ordinal not in range(128)[color=blue][color=green][color=darkred]
                      >>>[/color][/color][/color]

                      Thomas

                      Comment

                      • Max M

                        #12
                        Re: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 30)

                        michele.simiona to@gmail.com wrote:
                        [color=blue]
                        > uhm ... then there is a misprint in the discussion of the recipe;
                        > BTW what's the difference between .encode and .decode ?
                        > (yes, I have been living in happy ASCII-land until now ... ;)[/color]


                        # -*- coding: latin-1 -*-


                        # here i make a unicode string
                        unicode_file = u'Some danish characters æøå' #.encode('hex')
                        print type(unicode_fi le)
                        print repr(unicode_fi le)
                        print ''


                        # I can convert this unicode string to an ordinary string.
                        # because æøå are in the latin-1 charmap it can be understood as
                        # a latin-1 string
                        # the æøå characters even has the same value in both
                        latin1_file = unicode_file.en code('latin-1')
                        print type(latin1_fil e)
                        print repr(latin1_fil e)
                        print latin1_file
                        print ''


                        ## I can *not* convert it to ascii
                        #ascii_file = unicode_file.en code('ascii')
                        #print ''


                        # I can also convert it to utf-8
                        utf8_file = unicode_file.en code('utf-8')
                        print type(utf8_file)
                        print repr(utf8_file)
                        print utf8_file
                        print ''


                        #utf8_file is now an ordinary string. again it can help to think of it
                        as a file
                        #format.
                        #
                        #I can convert this file/string back to unicode again by using the
                        decode method.
                        #It tells python to decode this "file format" as utf-8 when it loads it
                        onto a
                        #unicode string. And we are back where we started


                        unicode_file = utf8_file.decod e('utf-8')
                        print type(unicode_fi le)
                        print repr(unicode_fi le)
                        print ''


                        # So basically you can encode a unicode string into a special
                        string/file format
                        # and you can decode a string from a special string/file format back
                        into unicode.


                        ############### ############### #####


                        <type 'unicode'>
                        u'Some danish characters \xe6\xf8\xe5'

                        <type 'str'>
                        'Some danish characters \xe6\xf8\xe5'
                        Some danish characters æøå

                        <type 'str'>
                        'Some danish characters \xc3\xa6\xc3\xb 8\xc3\xa5'
                        Some danish characters æøå

                        <type 'unicode'>
                        u'Some danish characters \xe6\xf8\xe5'





                        --

                        hilsen/regards Max M, Denmark


                        IT's Mad Science

                        Comment

                        • Max M

                          #13
                          Re: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 30)

                          Thomas Heller wrote:
                          [color=blue]
                          > It seems also the error messages aren't too helpful:
                          >[color=green][color=darkred]
                          >>>>"ä".encode( "latin-1")[/color][/color]
                          >
                          > Traceback (most recent call last):
                          > File "<stdin>", line 1, in ?
                          > UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0x84 in position 0: ordinal not in range(128)
                          >
                          > Hm, why does the 'encode' call complain about decoding?[/color]

                          Because it tries to print it out to your console and fail. While writing
                          to the console it tries to convert to ascii.

                          Beside, you should write:

                          u"ä".encode("la tin-1") to get a latin-1 encoded string.


                          --

                          hilsen/regards Max M, Denmark


                          IT's Mad Science

                          Comment

                          • Thomas Heller

                            #14
                            Re: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 30)

                            Max M <maxm@mxm.dk> writes:
                            [color=blue]
                            > Thomas Heller wrote:
                            >[color=green]
                            >> It seems also the error messages aren't too helpful:
                            >>[color=darkred]
                            >>>>>"ä".encode ("latin-1")[/color]
                            >> Traceback (most recent call last):
                            >> File "<stdin>", line 1, in ?
                            >> UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0x84 in position 0: ordinal not in range(128)
                            >> Hm, why does the 'encode' call complain about decoding?[/color]
                            >
                            > Because it tries to print it out to your console and fail. While
                            > writing to the console it tries to convert to ascii.[/color]

                            Wrong, same error without trying to print something:
                            [color=blue][color=green][color=darkred]
                            >>> x = "ä".encode("lat in-1")[/color][/color][/color]
                            Traceback (most recent call last):
                            File "<stdin>", line 1, in ?
                            UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0x84 in position 0: ordinal not in range(128)[color=blue][color=green][color=darkred]
                            >>>[/color][/color][/color]
                            [color=blue]
                            >
                            > Beside, you should write:
                            >
                            > u"ä".encode("la tin-1") to get a latin-1 encoded string.[/color]

                            I know, but the question was: why does a unicode string has a encode
                            method, and why does it complain about decoding (which has already been
                            answered in the meantime).

                            Thomas

                            Comment

                            • Walter Dörwald

                              #15
                              Re: Unicode universe (was Re: Dr. Dobb's Python-URL! - weekly Pythonnews and links (Dec 30))

                              Skip Montanaro wrote:[color=blue]
                              > aahz> Here's the stark simple recipe: when you use Unicode, you *MUST*
                              > aahz> switch to a Unicode-centric view of the universe. Therefore you
                              > aahz> encode *FROM* Unicode and you decode *TO* Unicode. Period. It's
                              > aahz> similar to the way floating point contaminates ints.
                              >
                              > That's what I do in my code. Why do Unicode objects have a decode method
                              > then?[/color]

                              Because MAL implemented it! >;->

                              It first encodes in the default encoding and then decodes the result
                              with the specified encoding, so if u is a unicode object
                              u.decode("utf-16")
                              is an abbreviation of
                              u.encode().deco de("utf-16")

                              In the same way str has an encode method, so
                              s.encode("utf-16")
                              is an abbreviation of
                              s.decode().enco de("utf-16")

                              Bye,
                              Walter Dörwald

                              Comment

                              Working...