sh:-c:第1行:意外标记附近的语法错误`;'

时间:2011-11-30 01:35:23

标签: python

我正在测试我的python脚本:

#!/usr/bin/python

import os,sys
import glob
import commands
import gzip
from itertools import islice

f1=gzip.open("/home/xug/scratch/test_trim.fastq","w")
LIST=[]
N = 4
with open("/home/xug/scratch/test.fastq", "r") as f:
    while True:
        line_group = list(islice(f, N))
        if not line_group:
            break
        l3=line_group[3].rstrip()
        l3_trim=commands.getoutput("sed 's/\(.\)B*$/\1/g'" + l3)
        #l3_to = subprocess.Popen(["sed 's/\(.\)B*$/\1/g'",l3],
                                  #stdout=subprocess.PIPE,bufsize=1)
        #l3_trim=l3_to.stdout
        if ( float(len(l3_trim))/float(len(l3)) > 0.70 ):
               LIST.append(line_group[0])
               LIST.append(line_group[1][:int(len(l3_trim))])
               LIST.append(line_group[2])
               LIST.append(l3_trim)

    output=f1.writelines(LIST)

但是我遇到了错误:

sh: -c: line 0: unexpected EOF while looking for matching ``'
sh: -c: line 1: syntax error: unexpected end of file
sh: -c: line 0: unexpected EOF while looking for matching ``'
sh: -c: line 1: syntax error: unexpected end of file
sh: -c: line 0: unexpected EOF while looking for matching ``'
sh: -c: line 1: syntax error: unexpected end of file
sh: -c: line 0: unexpected EOF while looking for matching ``'
sh: -c: line 1: syntax error: unexpected end of file
sh: -c: line 0: unexpected EOF while looking for matching ``'
sh: -c: line 1: syntax error: unexpected end of file
sh: -c: line 0: unexpected EOF while looking for matching ``'
sh: -c: line 1: syntax error: unexpected end of file

最终结束了while循环......

1 个答案:

答案 0 :(得分:2)

(继续上述评论)

要使用Python的内置B模块从字符串中删除尾随re,请尝试:

import re

l3_trim = re.sub(r"B*$", "", l3)