概述
在写python脚本的时候可以套用模板+一些处理的语句例子更快的写好程序,因此想到来写这样的文章来与大家分享,有不足之处欢迎大家指出~
首先放上我最常用的几个模板:
模板一
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Date : 2020-03-13
# Author : Myshu
# Mail : myshu0601@qq.com
# Version : 1.0
from __future__ import print_function
import getopt
import sys
import time
try:
from Bio import AlignIO, SeqIO
except ImportError:
sys.stderr.write("Error! BioPython is not detected!n")
sys.exit(1)
def usage():
print ( 'Usage: n'
' -h | --help help n'
' -i input old bms.infon'
' -n input new bms.infon'
' -t tags file dirn'
' -o output final bms.infon'
'')
oldbms = ''
newbms = ''
tags_dir = ''
outputfile = ''
try:
opts, args = getopt.getopt(sys.argv[1:], "hi:n:t:o:", ["help"])
except getopt.GetoptError:
print ('getopt error!')
usage()
sys.exit(1)
for opt,arg in opts:
if opt in ('-h','--help'):
usage()
sys.exit(1)
elif opt in ('-i'):
oldbms = arg
elif opt in ('-n'):
newbms = arg
elif opt in ('-t'):
tags_dir = arg
elif opt in ('-o'):
outputfile = arg
# check the args
if oldbms=='':
print('ERROR: There must be a oldbms file!')
usage()
sys.exit(1)
if newbms=='':
print('ERROR: There must be a newbms file!')
usage()
sys.exit(1)
if tags_dir=='':
print('ERROR: There must be a tags_dir!')
usage()
sys.exit(1)
if outputfile=='':
print('ERROR: There must be a outputfile!')
usage()
sys.exit(1)
#------ def --------------------
# 打印当前时间的函数 2020-03-12 15:26:58
def PrintTime():
now = int(round(time.time() * 1000))
time_now = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(now / 1000))
# 设置输出字体为浅蓝色,调色可以参照链接:https://www.cnblogs.com/fangbei/p/python-print-color.html
time_now = "