Are there something like "Effective Python"?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Meng

    #1

    Are there something like "Effective Python"?

    Hi all,
    I just finished reading Learning Python 3rd ed, and am doing my
    first Python application, which retrieves and process text and XML
    documents from Web. Python helped me to write the application in a few
    hours, I'm very happy with its productivity. But the performance is not
    satisfactory. I decide to optimized it in Python before trying C/C++
    extensions. But I don't know Python much and have no clu to tune my
    program. Also, I don't know what Pythonist's preferred styles. Are
    there any books/documents which play the similar role for Python as
    'Effective C++' does for C++?

    For example, one of my friends read my program and suggest me to
    move the re.compile() out of a for-loop, since the regular pattern is
    fixed, and re.compile() is slow. I want to find more such advice, where
    can I find them?

    Thank you.

    Mike

  • Luis M. González

    #2
    Re: Are there something like "Effect ive Python"?

    Mike Meng wrote:[color=blue]
    > Hi all,
    > I just finished reading Learning Python 3rd ed, and am doing my
    > first Python application, which retrieves and process text and XML
    > documents from Web. Python helped me to write the application in a few
    > hours, I'm very happy with its productivity. But the performance is not
    > satisfactory. I decide to optimized it in Python before trying C/C++
    > extensions. But I don't know Python much and have no clu to tune my
    > program. Also, I don't know what Pythonist's preferred styles. Are
    > there any books/documents which play the similar role for Python as
    > 'Effective C++' does for C++?
    >
    > For example, one of my friends read my program and suggest me to
    > move the re.compile() out of a for-loop, since the regular pattern is
    > fixed, and re.compile() is slow. I want to find more such advice, where
    > can I find them?
    >
    > Thank you.
    >
    > Mike[/color]



    Also, I suggest checking Psyco ( http://psyco.sourceforge.net/ ), which
    can easily improve your program's speed with no change in your code.

    Hope this helps...
    Luis

    Comment

    • Ray

      #3
      Re: Are there something like "Effect ive Python"?

      I think Aahz stated somewhere that he was workign on Effective Python.
      I'm not sure if it's an ongoing plan or it's been canned though?

      Mike Meng wrote:[color=blue]
      > Hi all,
      > I just finished reading Learning Python 3rd ed, and am doing my
      > first Python application, which retrieves and process text and XML
      > documents from Web. Python helped me to write the application in a few
      > hours, I'm very happy with its productivity. But the performance is not
      > satisfactory. I decide to optimized it in Python before trying C/C++
      > extensions. But I don't know Python much and have no clu to tune my
      > program. Also, I don't know what Pythonist's preferred styles. Are
      > there any books/documents which play the similar role for Python as
      > 'Effective C++' does for C++?
      >
      > For example, one of my friends read my program and suggest me to
      > move the re.compile() out of a for-loop, since the regular pattern is
      > fixed, and re.compile() is slow. I want to find more such advice, where
      > can I find them?
      >
      > Thank you.
      >
      > Mike[/color]

      Comment

      • BartlebyScrivener

        #4
        Re: Are there something like "Effect ive Python"?

        >> I just finished reading Learning Python 3rd ed,

        For real? I thought there was only a 2nd edition.

        http://www.oreilly.com/catalog/lpython2/

        Comment

        • Mike Meng

          #5
          Re: Are there something like "Effect ive Python"?

          Bart,
          I'm sorry, it's 2nd edtion.

          Thanks.

          mike


          BartlebyScriven er 写道:
          [color=blue][color=green][color=darkred]
          > >> I just finished reading Learning Python 3rd ed,[/color][/color]
          >
          > For real? I thought there was only a 2nd edition.
          >
          > http://www.oreilly.com/catalog/lpython2/[/color]

          Comment

          • Brian

            #6
            Re: Are there something like "Effect ive Python"?


            You might want to give this site a look:

            Package for use with the LiveWires Python Course. Contribute to livewires/python development by creating an account on GitHub.


            Comment

            • Aahz

              #7
              Re: Are there something like "Effect ive Python"?

              In article <1149224468.481 470.74580@i39g2 000cwa.googlegr oups.com>,
              Mike Meng <meng.yan@gmail .com> wrote:[color=blue]
              >
              > I just finished reading Learning Python 3rd ed, and am doing my
              >first Python application, which retrieves and process text and XML
              >documents from Web. Python helped me to write the application in a few
              >hours, I'm very happy with its productivity. But the performance is not
              >satisfactory . I decide to optimized it in Python before trying C/C++
              >extensions. But I don't know Python much and have no clu to tune my
              >program. Also, I don't know what Pythonist's preferred styles. Are
              >there any books/documents which play the similar role for Python as
              >'Effective C++' does for C++?[/color]

              <red face> That's my fault. I'm technically still under contract to
              write _Effective Python_, but it has proven much more difficult to write
              than I expected. (Not in the sense of difficulty finding material, but
              in sitting down and *writing*.) I actually brought in David Goodger as
              co-author and we still haven't been able to make progress. :-(

              Right now, I'm finishing up _Python for Dummies_ (which is mostly being
              written by Stef -- I provide the technical expertise and editing), and
              after a suitable resting time, we'll see if we can get back on track
              with _Effective Python_
              --
              Aahz (aahz@pythoncra ft.com) <*> http://www.pythoncraft.com/

              "I saw `cout' being shifted "Hello world" times to the left and stopped
              right there." --Steve Gonedes

              Comment

              • Aahz

                #8
                Re: Are there something like &quot;Effect ive Python&quot;?

                In article <1149224468.481 470.74580@i39g2 000cwa.googlegr oups.com>,
                Mike Meng <meng.yan@gmail .com> wrote:[color=blue]
                >
                > For example, one of my friends read my program and suggest me to
                >move the re.compile() out of a for-loop, since the regular pattern is
                >fixed, and re.compile() is slow. I want to find more such advice, where
                >can I find them?[/color]

                Actually, that's a good example of a false optimization, unless you're
                using a lot of different regexes in the loop or it's an extremely tight
                loop, because the re module already caches regexes. Still, if it's a
                constant string, a good programmer would probably hoist it out of the
                loop because you should hoist ALL constant assignments out of a loop.
                (It's not particularly related to re.compile() in this case.)
                --
                Aahz (aahz@pythoncra ft.com) <*> http://www.pythoncraft.com/

                "I saw `cout' being shifted "Hello world" times to the left and stopped
                right there." --Steve Gonedes

                Comment

                • gene tani

                  #9
                  Re: Are there something like &quot;Effect ive Python&quot;?


                  Mike Meng wrote:[color=blue]
                  > Hi all,
                  > I just finished reading Learning Python 3rd ed, and am doing my
                  > first Python application, which retrieves and process text and XML
                  > documents from Web. Python helped me to write the application in a few
                  > hours, I'm very happy with its productivity. But the performance is not
                  > satisfactory. I decide to optimized it in Python before trying C/C++
                  > extensions. But I don't know Python much and have no clu to tune my
                  > program. Also, I don't know what Pythonist's preferred styles. Are
                  > there any books/documents which play the similar role for Python as
                  > 'Effective C++' does for C++?
                  >
                  > For example, one of my friends read my program and suggest me to
                  > move the re.compile() out of a for-loop, since the regular pattern is
                  > fixed, and re.compile() is slow. I want to find more such advice, where
                  > can I find them?
                  >[/color]

                  Here's some links to profiling tools

                  The official home of the Python Programming Language

                  Now, next, and beyond: Tracking need-to-know trends at the intersection of business and technology




                  Comment

                  Working...