python常用
1 print(os.path.basename(__file__)) #a.py 2 print(os.path.dirname(os.path.abspath(__file__))) #/tmp 3 print(os.path.abspath(os.path.dirname(__file__))) #同上 4 print(os.path.abspath(__file__)) #/tmp/a.py 5 import argparse 6 from configobj import ConfigObj 7 parser=argparse.ArgumentParser() 8 parser.add_argument("-s","--src",default='src.conf',help="--src=src.conf",type=str) 9 parser.add_argument("-d","--dest",default='dest.conf',help="--src=dest.conf",type=str) 10 args=parser.parse_args() 11 BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 12 sys.path.append(BASE_DIR) 13 from conf import settings 14 15 1、click模块 16 http://click.pocoo.org/5/quickstart/#screencast-and-examples 17 2、awesome python 18 https://github.com/vinta/awesome-python#devops-tools 19 3、python requests 20 http://www.python-requests.org/en/master/ 21 4、写监控端口模块 22 5、> /dev/null 2>&1 #去掉日志 23 6、time.strftime("%d/%h/%Y:%H:%M",time.localtime()) 24 7、sed -n "/21\/Jul\/2016:12:39/,/21\/Jul\/2016:12:44/p" access_www.log