Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5172
  • 博文数量: 2
  • 博客积分: 20
  • 博客等级: 民兵
  • 技术积分: 30
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-11 16:23
文章分类

全部博文(2)

文章存档

2013年(2)

我的朋友

分类: Python/Ruby

2013-10-11 11:55:15

把学到的都整理到zutil.py里吧

  1. #!/bin/env python
  2. #coding:utf8
  3. # filename: zutil.py
  4. # description: util for myself
  5. # createtime: 2013/10/11
  6. # last modify: 2013/10/11

  7. # open file
  8. import random
  9. import sys
  10. def readfile(filename):
  11.     f = open(filename)
  12.     # f = open(filename, 'a') #append
  13.     # f = open(filename, 'w') # write
  14.     f.write(str(random.randint(0,9)) + '\n')
  15.     f.flush()
  16.     f.close()

  17. def redirectoutput():
  18.     sys.stdout = open("stdout.txt", 'w')

  1. #!/bin/env python
  2. #coding:utf8
  3. # filename: zutil.py
  4. # description: util for myself
  5. # createtime: 2013/10/11
  6. # last modify: 2013/10/11

  7. # open file
  8. import random
  9. import sys
  10. def readfile(filename):
  11.     f = open(filename)
  12.     # f = open(filename, 'a') #append
  13.     # f = open(filename, 'w') # write
  14.     f.write(str(random.randint(0,9)) + '\n')
  15.     f.flush()
  16.     f.close()

  17. def redirectoutput():
  18.     sys.stdout = open("stdout.txt", 'w')

import hashlib
import os
# from a[.py] import something
def getFileMd5(filename):
    myhash = hashlib.md5()
   if not os.path.isfile(filename):
       return
   f = open(filename)
   while True:
      b = f.read(8096)
      if not b:
          break
      myhash.update(b)
   return myhash.hexdigest()
   # return myhash.hexdigest().upper()

# file size
#  os.path.getsize(filename)



经验:
1.  在python里,函数的默认值是在函数定义的时候实例化的,而不是在调用的时候

阅读(163) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:被收购后的mysql 编译安装

给主人留下些什么吧!~~