Python Project

来源:互联网 发布:期货套利交易软件 编辑:程序博客网 时间:2024/06/06 06:38

* PYTHON 趋向于将功能相近的对象放进一个MODULE(文件)里,不用担心对象会太大,因为如果对象太大了,那它可能是做的事性太多了

   需要被重构、分解。

 

* 开发辅助工具是PYTHON的一个强项。如构建工具、统计工具等等,只要有需求,它一定办得到,因为这些应用对安全和性能要求不高,反

   而对开发的简洁性有很高的乞求。

 

* 只把会发生意外的那一小部分放进try里,把try成功后的操作放进else里,try失败后的操作放进except里,把不管成功或失败都需要的操作

   放进finally里(为什么不写在try-catch块后呢?因为这个try-catch块代表一个风险操作集合的语意)

 

* PYTHON中可以简化操作的内置语法有:for/else(如果for集合为空则执行else语句)

 

Python 是Google的3个官方语言之一,在Google的应用开发中大量应用,不过,更多的是应用在开发辅助工具上:

 

 * The Google build system.All of Google's corporate code is checked into a repository and the dependency and building of this           code is managed by python.Greg mentioned that to create code.google.com took about 100 lines of python code.  But since it          has so many dependencies,the build system generated a 3 megabyte 

 

 * Packaging.  Google has an internal packaging format like RPM.  These packages are created using python.

 

 * Binary Data Pusher.  This is the area where Alex Martelli is working, on optimizing pushing bits between thousands of servers

 

 * Production servers.  All monitoring, restarting and data collection functionality is done with python

 

 * Reporting.  Logs are analyzed and reports are generated using Python.

 

 * A few services including code.google.com and google groups.  Most other front ends are in C++ (google.com) and Java (gmail).        All web services are built on top of a highly optimizing http server wrapped with SWIG.

 

##########################################################


Python doesn't force you into Java's nasty one-class-per-file style. In fact, it's not even considered good style to put each class in a separate file unless they are huge. (If they are huge, you probably have to do refactoring anyway.) Instead, you should group similar classes and functions in modules. For example, if you are writing a GUI calculator, your package layout might look like this:

/amazingcalc
   /
__init__.py # This makes it a Python package and importable.
   
/evaluate.py # Contains the code to actually do calculations.
   
/main.py # Starts the application
   
/ui.py # Contains the code to make a pretty interface

 

They'll probably end up fairly large – Teifion Dec 24 '08 at 17:43
@Teifion: Large? If a class is "large" (i.e., many hundreds of lines of code), it's probably doing too much. 
Good practice is to decompose such a large class into something easier to understand. Unrelated to using many
files. – S.Lott Dec 24 '08 at 22:28
Ben Blank: One public class per file is what you do when you've got a very complex language and a very slow compiler. If you simplify your language, you get faster compilers and you don't need that administrative hack
I've always felt that one-class-per-file was a misfeature of the Java language. A well-intentioned one, perhaps, but still.

PYTHON is a language for creativity

原创粉丝点击