随笔分类 -  Python

摘要:需求在server程序运行到一半或者要结束的时候希望它自动记录下当前server的状态,包括有多少个进程,每个占多少CPU,多少内存,系统还剩多少内存之类的。想法很简单,既然程序有python脚本,那么就通过python脚本开一个进程运行一些power shell的脚本,把结果写文件。PowerShell花了一天时间,啃了点文档,记录一些例子:获取帮助:get-helpget-help *get-helpget-help -detailed获取object的memberget-process | get-member获取进程列表然后输出用CPU时间最多的5个和最少的5个,并把结果写到 D:\a 阅读全文
posted @ 2012-11-26 10:09 大兵八世 阅读(8736) 评论(0) 推荐(1)
摘要:1. propertyclass C(): def SetIt(self): self.a = 1 def GetIt(self): return self.a content = property(SetIt, GetIt)c = C()c.content = 1print c.content # will print 12. idid(1) # this is a number..3. weakrefimport weakrefclass C(): def func(self): passc = C()c.func()p =... 阅读全文
posted @ 2012-03-22 16:38 大兵八世 阅读(657) 评论(0) 推荐(0)
摘要:Decorate是装饰的意思。如果你了解Decorator设计模式,那么就很好理解Python的Decorator。http://en.wikipedia.org/wiki/Python_syntax_and_semantics#DecoratorsDecorator是一个可调用的python object。Decorator可以用来修改funciton, method 或者类的定义。一个object被传进decotator,然后decorator修改这个object并且返回这个object,最后,这个返回的object绑定到原来的那个object的名字上。Decorator是一个语法糖(sy 阅读全文
posted @ 2012-03-07 03:40 大兵八世 阅读(652) 评论(0) 推荐(0)
摘要:with 关键字的意思就是一种try finally的快捷写法看下面的代码和注释就容易理解with WithWrapper() as ww: print ww # 应该打印 1. 它是WithWrapper().__enter__函数的返回值 print "with body" raise NameError("Error Raised") # 这里如果有异常, WithWrapper().__exit__函数的后三个参数就根据这个异常被赋值。否则三个参数的值都是Noneclass WithWrapper: def __enter__(self): pr 阅读全文
posted @ 2012-03-01 01:55 大兵八世 阅读(357) 评论(0) 推荐(0)