2012年2月24日星期五
python+pyqt4脚本转exe程序
python+pyqt4脚本转exe程序
转换工具:Py2exe
运行平台:Windows
下面按步骤说明将一个Python脚本转换成exe程序的过程。
1. 安装Py2exe
2. 进入hello.py的目录,编写安装脚本setup.py。其内容如下:
1. 精简版+图标 pyqt4打包
#setup_pyqt.py
#with logo.ico and all the files bundled in one exe
name1=raw_input("Enter the name of py file: ")
from distutils.core import setup
import py2exe
setup(zipfile=None,
windows=[{"script" : name1, 'icon_resources':[(1, 'logo.ico')]}],
options={"py2exe" : {"includes" : ["sip"]},"py2exe": { "bundle_files": 1,"includes" : ["sip"] }})
2. 精简版:打包 python 脚本 成 带图标的exe 程序,无小文件生成
#setup_python.py
#with logo.ico and all the files bundled in one exe
name1=raw_input("Name of py file: ")
from distutils.core import setup
import py2exe
import sys
includes = ["encodings", "encodings.*"]
sys.argv.append("py2exe")
options = {"py2exe": { "bundle_files": 1,"includes" : ["sip"] } }
setup(options = options,
zipfile=None,
console = [{"script":name1, 'icon_resources':[(1, 'logo.ico')]}])
3. 打开DOS并切换其工作目录为当前目录,按如下方式在DOS中运行setup_pyqt.py, setup_python.py:
python setup_pyqt.py py2exe
python setup_python.py py2exe
2011年12月30日星期五
ID To Namelist
ID To Namelist
import os
import time, sys
from Bio import SeqIO
filename=raw_input("Pls enter the name of the output txt file of Blastall.exe: ")
Approach=raw_input("Pls enter the the approach of your Datebase: ")
# Timing start
start=time.time()
wrerr = sys.stderr.write
# Create a file named 'Results' in current dir
if os.path.exists('Results'):
for root, dirs, files in os.walk('Results'):
for name in files:
os.remove(os.path.join(root,name))
else:
os.mkdir('Results')
f=open(filename,'r')
f1=open('Results//ID_datebase.txt','w')
a={}
b=[]
# Search every dirs and files at F:\python missions\YY\Datebase
for root,dirs,files in os.walk(Approach):
for file in files:
for record in SeqIO.parse(os.path.join(root, file), 'fasta'):
b.append(record.id)
a[os.path.join(root, file).split('\\')[-2]+'-'+os.path.join(root, file).split('\\')[-1]]=b
b=[]
# Output ID_datebase
f1.write('Namelist'+'\t'+'Corresponding ID'+'\n')
for key in sorted(a.keys()):
f1.write(str(key)+'\t'+str(a[key])+'\n')
# Name the IDs
num=0
for line in f:
num+=1
for key in a.keys():
if line.split('\t')[1].strip() in str(a[key]):
f2=open('Results\\'+key+'.txt','a')
f2.write(str(line).strip()+'\t'+key+'\t'+'\n')
if num%100000==0:
print str(num)+" sequences have been processed!"
end=time.time()
wrerr("OK, All Work Finished in %3.2f secs\n" % (end-start))
raw_input("Press <Enter> to close this window: ")
2011年11月10日星期四
用Python的split输出excel文件
Here’s an example of some data where the dates not formatted well for easy import into Excel:
The first column has the day and month separated by a space. The second column is year-day, which we’ll ignore. The third column has the time. The data we’re interested in is in the 9th column (temperature). The goal is to have a simple Excel file where the first column is date, and the second column is temperature.
|
利用list(set())和sorted处理列表或字典
1.利用list(set(a))来删除列表a或者字典中重复的元素。
2.利用sorted 来排序字典a。排序原则:将列表b中元素按照其在字典a中对应值的大小来排序。Reference: http://wiki.python.org/moin/HowTo/Sorting/
>>> a={'a': '3', 'c': '2', 'e': '1', 'd': '0'}
>>> b=['a','e']
>>> sorted(b,key=a.__getitem__)
['e', 'a']
特殊地:
对字典a的 健值列表(a.keys()) 按其对应值的大小进行排序,结果输出到列表中
>>> a={'a':'3','c':'2','d':'0','e':'1'}
>>> sorted(a.keys(),key=a.__getitem__)
['d', 'e', 'c', 'a']
>>> a=['2','2','4','3','4','0','1','1']
>>> list(set(a))
['1', '0', '3', '2', '4']
2.利用sorted 来排序字典a。排序原则:将列表b中元素按照其在字典a中对应值的大小来排序。Reference: http://wiki.python.org/moin/HowTo/Sorting/
>>> a={'a': '3', 'c': '2', 'e': '1', 'd': '0'}
>>> b=['a','e']
>>> sorted(b,key=a.__getitem__)
['e', 'a']
特殊地:
对字典a的 健值列表(a.keys()) 按其对应值的大小进行排序,结果输出到列表中
>>> a={'a':'3','c':'2','d':'0','e':'1'}
>>> sorted(a.keys(),key=a.__getitem__)
['d', 'e', 'c', 'a']
订阅:
博文 (Atom)