Python Project
* 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-c
相关文档:
作为一个初学shell的程序员来说,使用shell的一些命令调用,比如就写几行,做一些自动化的操作,简单又实用,但是涉及逻辑控制和
字符串处理时,看到那if/fi,case/esac……还有古离古怪的布尔判断……还有复杂而又名字很响而且很老资格的sed、awk……我就想,
在没有非要在shell中 ......
在paramiko中使用用户名和密码通过sftp传输文件,不使用key文件。
import getpass
import select
import socket
import traceback
import paramiko
def putfile():
#import interactive
# setup logging
paramiko.util.log_to_file('demo.log')
username = username
hostname = hostname
......
Python 3 输出重定向使用C/C++
By:gddsky
目标
希望将Python 3的输出重定向到自定义的输出目标。
核心
Python使用sys.stdout、sys.stderr做输出目标,只要我们替换这两个值就可以重定向到我们自定义目标。替换的值的规则在Python的文档中sys (module)的sys.stdout上面说明只要添加一个write函数就可以 ......
以下是一个通过minidom模块写文件的完整示例,是在最近做的项目Walle上面用到的,这个示例的目的是生成一个如下的格式的xml,文件格式为无BOM utf-8。
生成xml文件格式:
<?xml version="1.0" encoding="utf-8"?>
<coverages>
<coverage>
  ......
python 中minidom解析xml
2009年06月26日 星期五 08:40
下面只列出一些常用的方法属性,如果要查看更多的方法, 可以去看文件minidom如何实现的。
获得Document对象
法一:
import xml.dom.minidom as m_dom
doc1 = m_dom.getDOMImplementation().createDocument(None, "root1", None)
doc1.documentElement.toxml(e ......