Are there something like "Effective Python"?

M

Mike Meng

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
 
?

=?iso-8859-1?q?Luis_M._Gonz=E1lez?=

Mike said:
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
 
R

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

Mike Meng

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

Thanks.

mike


BartlebyScrivener 写é“:
 
A

Aahz

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_
 
A

Aahz

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.)
 
G

gene tani

Mike said:
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/python-list/2006-January/318295.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top