
Python
文章平均质量分 60
CPP_CHEN
这个作者很懒,什么都没留下…
展开
-
Python Patterns - An Optimization Anecdote
Python Patterns - An Optimization AnecdotePython Patterns - An Optimization AnecdoteThe other day, a friend asked me a seemingly simple question: what's the best way to convert a list of integ转载 2014-08-17 11:26:21 · 1149 阅读 · 0 评论 -
Logging
Python logging componentsLoggers expose the interface that application code directly uses.Handlers send the log records (created by loggers) to the appropriate destination.Filters provide a fine原创 2014-01-19 11:33:00 · 791 阅读 · 0 评论 -
Metaprogramming in Python
MetaprogrammingMetaprogramming is the ability for a program to reason about itself or to modify.Metaprogramming is the writing of computer programs that write or manipulate other programs (o转载 2014-01-27 21:41:23 · 1530 阅读 · 0 评论 -
Python Attributes and Methods
Python Attributes and MethodsShalabh ChaturvediCopyright © 2005-2009 Shalabh ChaturvediAll Rights Reserved.About This BookExplains the mechanics of object attribute转载 2013-12-10 12:00:10 · 1913 阅读 · 0 评论 -
Eggs and Egg Info
----------------------Eggs and their Formats----------------------A "Python egg" is a logical structure embodying the release of aspecific version of a Python project, comprising its code,转载 2014-01-05 16:47:02 · 2843 阅读 · 0 评论 -
Why so many Python web frameworks
Why so many Python web frameworks?When asked about the plethora of web frameworks for Python the answer is often that it is way too easy to put together one in Python. That certainly seems plaus转载 2014-01-05 11:11:02 · 1214 阅读 · 0 评论 -
context manager
1) The "with" statementwith expr [as VAR]: WITH-BLOCK"with" statement is something like "RAII" in C++, when "with" statement finishes, all resources will be cleaned automatically even there i原创 2013-12-20 12:12:09 · 1199 阅读 · 0 评论 -
Relative imports
For example, code in the A.B.C module can do:from . import D # Imports A.B.Dfrom .. import E # Imports A.Efrom ..F import G # Imports A.F.G原创 2013-12-20 11:05:54 · 1160 阅读 · 0 评论 -
Python idioms, 2 of n
1) Don't do trivial assignment in __init__ of the classDon't:class Foo(object): def __init__(self): self.attr1 = 0 self.attr2 = '' self.attr3 = [] self.at原创 2012-09-26 09:36:06 · 1351 阅读 · 0 评论 -
Python performance 1 of n
If you would like to improve the running performance of Python, try1) Use profile/cProfile to benchmark your program, find the possible hotspot, switch to correct data structure to solve problem etc原创 2012-09-25 22:43:34 · 518 阅读 · 0 评论 -
Python type and object relationship
1) Everything is object in Python, even types (what the hell, how can this happen ? See below bullet points)2) "class" and "type" are the same thing, they are "type objects". "Type objects" can be s原创 2013-06-25 12:15:17 · 1894 阅读 · 1 评论 -
Python Metaclass
Metaclass is class whichcreates other class (its instance is other class)Whenexecuting a class definition, the interpreter has to know the correct metaclass to use. It will lookfor a class attribute n原创 2013-06-28 15:15:45 · 863 阅读 · 0 评论 -
CherryPy architecture
High Level FrameworkApplication Level Framework原创 2014-02-22 22:31:35 · 912 阅读 · 0 评论 -
Python debuggers
1) pdb2) Winpdb3) pydev4) gdb python extentionReferences:https://code.google.com/p/winpdb/wiki/DebuggingTutorialhttp://stackoverflow.com/questions/132058/showing-the-stack-trace-from-a-r原创 2014-02-19 20:00:23 · 795 阅读 · 0 评论 -
Rich Comparison Methods
One of the nicest features of the Data Model is the ability to override the behavior of rich comparison operators:import functools@functools.total_orderingclass Generic(object): def __ini转载 2014-07-08 14:03:58 · 884 阅读 · 0 评论 -
Iterables, Iterators and Generators: Part 2
This is the second part of the talk I gave January 24, 2013 at the Ottawa Python Authors Group.Part One introduces Python iterables and iterators and generators. This part covers the advanced use转载 2014-06-10 16:13:22 · 1037 阅读 · 0 评论 -
Top 10 Mistakes that Python Programmers Make
About PythonPython is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic b转载 2014-05-24 17:48:01 · 957 阅读 · 0 评论 -
A collection of not-so-obvious Python stuff you should know
A collection of not-so-obvious Python stuff you should know!I am really looking forward to your comments and suggestions to improve andextend this little collection! Just send转载 2014-04-26 23:18:16 · 1564 阅读 · 0 评论 -
The Light and Dark sides of Python name binding
The Light and Dark sides of Python name bindingPosted on 2014-04-04, last modified 2014-04-09.What does bar.foo do? - An exploration of Python assignment, objects, attributes and descripto转载 2014-05-20 10:22:15 · 961 阅读 · 0 评论 -
OOP Concepts in Python 2.x - Part 1
OOP Concepts in Python 2.x - Part 1Published on: Mar 5th, 2014Tags: pythonPosted by Leonardo GiordaniAbstractObject-oriented programming (OOP) has been the leading programmin转载 2014-04-12 17:02:16 · 1334 阅读 · 0 评论 -
OOP Concepts in Python 2.x - Part 2
OOP Concepts in Python 2.x - Part 2Published on: Mar 10th, 2014Tags: pythonPosted by Leonardo GiordaniAbstractThis post continues the analysis of the Python OOP implementatio转载 2014-04-12 22:41:41 · 1073 阅读 · 0 评论 -
Default Parameter Values in Python
Default Parameter Values in PythonFredrik Lundh | July 17, 2008 | based on a comp.lang.python post(It happened to me in one of the first Python programs I ever wrote, and it took several yea转载 2014-03-23 22:53:06 · 1192 阅读 · 0 评论 -
Python descriptor
1) DefinitionAny new style class that implements at least one of those method is called a descriptor: __get__(self, object, type=None) -> value, __set__(self, obj, value) -> None, __delete__(self, o原创 2013-06-26 17:12:24 · 1271 阅读 · 0 评论 -
Benchmark of Python WSGI Servers
Benchmark of Python WSGI ServersNicholas Piël | March 15, 2010It has been a while since the Socket Benchmark of Asynchronous server. That benchmark looked specifically at the raw socket perfor转载 2014-05-01 22:48:33 · 2836 阅读 · 0 评论 -
Asynchronous Servers in Python
Asynchronous Servers in PythonNicholas Piël | December 22, 2009There has already been written a lot on the C10K problem and it is known that the only viable option to handle LOTS of concurre转载 2014-05-01 22:44:04 · 1130 阅读 · 0 评论 -
Python yield expression (generator)
When a function has a "yield" expression, it is called generator.The generator doesn't run until it is called with next(g) or g.next(). The first time to call the function which has "yield" expression原创 2013-02-25 09:49:18 · 841 阅读 · 0 评论 -
Python Types and Objects
Python Types and ObjectsShalabh ChaturvediCopyright © 2005-2009 Shalabh ChaturvediAll Rights Reserved.About This BookExplains Python new-style objects:what转载 2013-12-05 18:28:19 · 2697 阅读 · 0 评论 -
Python decorator
1) DefinitionDecorator is actually a function, or more strictly is a callable. It acts like the "decorator" design pattern in a sense.2) How to define a decorator and how to call the decora原创 2013-06-27 23:22:25 · 860 阅读 · 0 评论 -
The protocols - Python
iteration protocol: implement __iter__() methodsequence protocol ([]): implement __len__() and __getitem__() method with integer argument starting at 0iterator protocol: implement __next__() metho原创 2012-10-08 15:16:10 · 623 阅读 · 0 评论 -
cx_Oracle - ImportError: DLL load failed: The specific module could not be found
After installing python2.6 32 bit and cx_Oracle5.1.2-11g.win32-py2.6.msi on XP system, try "import cx_Oracle", it reports "ImportError: DLL load failed: The specific module could not be found"Root c原创 2013-10-03 15:58:55 · 4121 阅读 · 0 评论 -
Unable to acquire Oracle environment handle
cx_Oracle.connect throws "InterfaceError: Unable to acquire Oracle environment handle", it is the invalid "ORACLE_HOME" env variable which caused this problem in my case. After fix the ORACLE_HOME, ev原创 2013-07-19 18:54:26 · 4740 阅读 · 0 评论 -
The implementation of multiprocess.Queue
Note:1) When calling _buffer.popleft(), it doesn't hold any lock in QueueFeederThread.2) It uses semaphore/pipe for mulitiprocess resource management.3) Reader and Writer are holding different l原创 2013-02-24 15:39:16 · 796 阅读 · 0 评论 -
Solution to the failure of installing pywin32-218.win-amd64-py2.6.exe in Win7 64bit
During the installation of package downloaded from sourceforge.net, it reports the following error in its post installation process.With the following traceback:Traceback (most recent call原创 2013-01-18 14:42:10 · 4519 阅读 · 0 评论 -
ctypes free memory which is allocated by C
In Python, how to explicitly free the non-trivial memory (not int/char/ etc) returned by C module ?Say C interface is like as below:____________________struct Dummy{ int a; int b;原创 2012-10-27 23:29:03 · 1456 阅读 · 0 评论 -
C module with ctypes
Python ctypes module is very convenient for python to integrate C module.Win7 X64 examples:1) Call c dll library passing in arguments and return structure ptrC lib:------------------------原创 2012-10-24 16:06:37 · 797 阅读 · 0 评论 -
Python idioms, 1 of n
Pythonic way to solve problems .1) Sort character in a strings = 'hello'''.join(sorted(s))2) Sort listtable = [(1, 'john', 23), \ (2, 'tom', 13), \ (3, 'lucy', 25), \原创 2012-09-25 22:35:17 · 1372 阅读 · 0 评论 -
urllib in Python 3
urllib/urllib2 in Python 2 have been cleaned up and consolidated in Python 3.Request submodule diagram原创 2012-09-06 15:37:16 · 571 阅读 · 0 评论 -
Python cx_Oracle - import not a valid win32 app or ImportError: No module named cx_Oracle Found
The Python installed is 64 bit 3.2.3 version. The Oracle XE database is 10g, 32 bit on 64 bit Windows server 2008.When trying to install Python 64 bit cx_Oracle module , it reports "import not a v原创 2012-08-14 15:38:44 · 3018 阅读 · 0 评论 -
Local, global, free variables in Python
xx原创 2013-11-30 11:27:10 · 1532 阅读 · 0 评论 -
Dictionary access in Python the right way
Dictionary access in Python the right wayPosted by bluquar on 6 August 2013, 10:03 pmThe first step to writing good code is to read good code. The second step is to figure out what is wron转载 2013-08-12 11:31:06 · 918 阅读 · 0 评论