bwangel23
10/13/2016 - 1:38 AM

Python 杂记

Python 杂记

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
实现一个 property 属性
"""

class classProperty(property):
    def __get__(self, cls, owner):
        return self.fget.__get__(None, owner)()

class C(object):
    @classProperty
    @classmethod
    def m(cls):
        print("This is the method m")

C.m
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

"""
测试range和xrange使用内存的程序
"""

import gc, os, psutil

def test():
    x = 0
    for i in xrange(100000):
    # for i in range(100000):
        x += i

    return x

def main():
    print(test())
    gc.collect()

    p = psutil.Process(os.getpid())
    print(p.memory_full_info())

if __name__ == '__main__':
    main()