zoukankan      html  css  js  c++  java
  • python os 库

    >>>import os
    >>>os.getcwd()
    >>>os.chdir(’..’)
    
    >>>os.listdir(’/home/sb/bioinfo/seqs’)
    >>>os.path.isfile(’/home/sb’)
    >>>os.path.isdir(’/home/sb’)
    >>>os.remove(’/home/sb/bioinfo/seqs/ms115.ab1’)
    >>>os.rename(’/home/sb/seqs/readme.txt’,’/home/sb/Readme’)
    >>>os.mkdir(’/home/sb/processed-seqs’)
    >>>os.path.join(os.getcwd(),"images")
    >>>os.path.exists(os.path.join(os.getcwd(),"images")) #Checksifgiven path exists
    >>>os.path.split(’/home/sb/seqs/ms2333.ab1’)    #(’/home/sb/seqs’,’ms2333.ab1’)
    >>>os.path.splitext(’/home/sb/seqs/ms2333.ab1’) #(’/home/sb/seqs/ms2333’,’.ab1’)
    
    for x in os.listdir(mypath):
        if os.path.splitext(x)[1] == ’.fas’:
            fh = open(os.path.join(mypath,x),’U’)
    
    
    >>>import xml.etree.ElementTreeasET
    >>>tree=ET.parse("/home/sb/bioinfo/smallUniprot.xml")
    
    
    >>>import sys
    >>>sys.path
    >>>sys.path.append("/home/sb/MyPyModules")
    
    
    #正则表达
    >>>import re
    >>>mo=re.search("hello","Helloworld,helloPython!")
    >>>mo.group() #’hello’ group() returns the string matched by the REGEX
    >>>mo.span()  #(13,18) span() returns a tuple containing the(start,end)
                  #positions of the match
    >>>text.index("hello")
    
    >>>re.findall("[Hh]ello","Helloworld,helloPython,!") # findall
    >>>mos=re.finditer("[Hh]ello","Helloworld,helloPython,!")
    
    >>>rgx=re.compile("[Hh]ello")
    >>>rgx.findall("Helloworld,helloPython,!")
    >>>rgx.search("Helloworld,helloPython,!")
    >>>rgx.match("Helloworld,helloPython,!")
    >>>rgx.findall("Helloworld,helloPython,!")
    #sub(rpl,str[,count=0])
    >>>rgx.sub("",seq)
    >>>rgx.subn("",seq) #subn(rpl,str[,count=0]): 匹配次数
    tanhao2013@foxmail.com || http://weibo.com/buttonwood
  • 相关阅读:
    #Leetcode# 541. Reverse String II
    PAT 甲级 1030 Travel Plan
    PAT 甲级 1029 Median
    bzoj 2002 [Hnoi2010]Bounce 弹飞绵羊
    jzoj 4243. 【五校联考6day1】c
    2019.02.23【NOIP提高组】模拟 A 组 总结
    【GDOI2013模拟1】病毒传播
    【GDOI2013模拟1】最短路
    【GDOI2013模拟1】删数字
    数列分块入门 6 总结
  • 原文地址:https://www.cnblogs.com/buttonwood/p/2887381.html
Copyright © 2011-2022 走看看