By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,078 Members | 1,733 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,078 IT Pros & Developers. It's quick & easy.

Are there something like "Effective Python"?

P: n/a
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

Jun 2 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Mike Meng wrote:
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


http://wiki.python.org/moin/PythonSpeed/PerformanceTips

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

Jun 2 '06 #2

P: n/a
Ray
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:
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


Jun 2 '06 #3

P: n/a
>> I just finished reading Learning Python 3rd ed,

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

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

Jun 2 '06 #4

P: n/a
Bart,
I'm sorry, it's 2nd edtion.

Thanks.

mike
BartlebyScrivener 写道:
I just finished reading Learning Python 3rd ed,


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

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


Jun 2 '06 #5

P: n/a

You might want to give this site a look:

http://www.livewires.org.uk/python/

Jun 2 '06 #6

P: n/a
In article <11*********************@i39g2000cwa.googlegroups. com>,
Mike Meng <me******@gmail.com> wrote:

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++?


<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 (aa**@pythoncraft.com) <*> http://www.pythoncraft.com/

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

P: n/a
In article <11*********************@i39g2000cwa.googlegroups. com>,
Mike Meng <me******@gmail.com> wrote:

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?


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 (aa**@pythoncraft.com) <*> http://www.pythoncraft.com/

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

P: n/a

Mike Meng wrote:
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?


Here's some links to profiling tools

http://www.python.org/doc/current/lib/profile.html
http://www.onlamp.com/lpt/a/6376
http://www.vrplumber.com/programming/runsnakerun/
http://mail.python.org/pipermail/pyt...ry/318295.html

Jun 2 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.