Last active
October 22, 2015 07:35
-
-
Save litefeel/5ba498293cd166895595 to your computer and use it in GitHub Desktop.
python 脚本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# coding=utf-8 | |
import os.path | |
import sys | |
import shutil | |
""" | |
getpath.py [path] | |
命令行所在目录 | |
或 命令行所在目录与path的组合 | |
""" | |
def get_script_path(): | |
# __file__ 当前脚本完整文件名 | |
return os.path.dirname(__file__) | |
def getpath(): | |
dir = '.' | |
if len(sys.argv) == 2: | |
dir = sys.argv[1] | |
return os.path.abspath(dir) | |
def readfile(filename): | |
if not os.path.exists(filename): | |
return None | |
with open(filename) as f: | |
data = f.read() | |
f.close() | |
return data | |
def writefile(filename, data): | |
with open(filename, 'w') as f: | |
f.write(data) | |
f.close() | |
def appendfile(filename, data): | |
with open(filename, 'a') as f: | |
f.write(data) | |
f.write('\n') | |
f.close() | |
def md5file(filename): | |
with open(filename, 'rb') as f: | |
data = f.read() | |
f.close() | |
m = hashlib.md5() | |
m.update(data) | |
return m.hexdigest() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment