473,713 Members | 2,763 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Jun 2 '06 #1
8 3347
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
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
>> 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
Bart,
I'm sorry, it's 2nd edtion.

Thanks.

mike
BartlebyScriven er 写道:
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

You might want to give this site a look:

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

Jun 2 '06 #6
In article <11************ *********@i39g2 000cwa.googlegr oups.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**@pythoncra ft.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
In article <11************ *********@i39g2 000cwa.googlegr oups.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**@pythoncra ft.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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2689
by: Ravi | last post by:
Hi, I did some googling, and found that there doesn't seem to be a pure python MySQL communication module. There is one for perl however, Net::MySQL. I was wondering if there was a specific reason why something similar hasn't been implemented in Python, a limitation of the language or libraries perhaps? I briefly scanned through the perl source for Net::MySQL, and there doesn't seem to be anything that couldn't be done in Python, but...
7
25579
by: beliavsky | last post by:
Ideally, one can use someone's C++ code by just looking at the header files (which should contain comments describing the functions in addition to function definitions), without access to the full source code. Can analogs of C++ header files be created for Python code? Python "header" files could list only the 'def' statements and docstrings of Python functions and classes, but that does not tell you what the functions return. One could...
7
3086
by: eric | last post by:
hello i'm confused by an example in the book "Effective C++ Third Edition" and would be grateful for some help. here's the code: class Person { public: Person(); virtual ~Person(); // see item 7 for why this is virtual ...
14
2178
by: Paddy3118 | last post by:
This month there was/is a 1000+ long thread called: "merits of Lisp vs Python" In comp.lang.lisp. If you followed even parts of the thread, AND previously used only one of the languages AND (and this is the crucial bit), were persuaded to have a more positive view of the other language; (deep breath, this is a long, as well as grammatically incorrect sentence), THEN WHY NOT POST ON WHAT ARGUMENTS PERSUADED YOU.
14
2123
by: Ivan Voras | last post by:
Hi, I'm looking for a construct that's similar to (Turbo) Pascal's "with" statement. I read about the Python's new "with" statement, but I was dissapointed to learn that it does something different (I still don't see how it's better than try..except..finally, but that's not my question). Is there something similar to what I want that's Pythonic enough? (If you're not familiar with Pascal, here's how it works:
11
9401
by: Wojciech Gryc | last post by:
Hi, I recently started using Python and am extremely happy with how productive it's made me, even as a new user. I'm hoping to continue using the language for my research, and have come across a bit of a stumbling block. I'm a seasoned Java programmer and quite a big fan of interfaces... i.e. The idea that if I make a number of distinct classes that implement interface X, I can pass them all as parameters to functions
41
2541
by: none | last post by:
Hello, IIRC, I once saw an explanation how Python doesn't have "variables" in the sense that, say, C does, and instead has bindings from names to objects. Does anyone have a link? Thanks, Ami
92
3947
by: ureuffyrtu955 | last post by:
Python is a good programming language, but "Python" is not a good name. First, python also means snake, Monty Python. If we search "python" in google, emule, many results are not programming resource. If we search PHP, all results are programming resource. Second, python also means snake, snake is not a good thing in western culture. Many people dislike any things relevant to snake. We must have high regard for the custom.
3
1361
by: Jean-Paul Calderone | last post by:
On Fri, 20 Jun 2008 09:31:57 -0700 (PDT), michalis.avraam@gmail.com wrote: http://mail.python.org/pipermail/python-list/2001-November/113994.html Jean-Paul
0
8701
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9168
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9068
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9009
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7942
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6621
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5943
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4715
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.