在脚本中写入变量的语法错误

时间:2018-10-05 23:01:09

标签: python linux

dump.pbd='pdb' + pdbFile + '_' + 'res' + residMin + '_' residMax + '.pdb'
the program keep giving me syntax error when I run it.

import re
import sys
import os
import time
from sys import argv
import xmltodict

if len(sys.argv) < 3:
    message = '\n Get protein file in the form of pdf file from pdb website. \n\n Usage: '+sys.argv[0] + ' [4-letter PDBid] [resid range] \n' + ' Example: ' + sys.argv[0] + '  2rh1 53-71\n' + ' Output File: pdb2rh1_res53-71.pdb'
    print (message)
    exit()
pdbID=sys.argv[1]
residRange=sys.argv[2]
residData=residRange.split('-')
residMin=int(residData[0])
residMax=int(residData[1])
twoletter=pdbID[1:3]
xmlfile=pdbID + '.xml'
pdbgzfile=pdbID + '.pdb.gz'
pdbFile=pdbID+'.pdb'
dump.pbd='pdb' + pdbFile + '_' + 'res' + residMin + '_' residMax + '.pdb'
wgetcom='wget https://files.rcsb.org/view/'+pdbFile+' -O '+pdbFile
print(wgetcom)
os.system(wgetcom)

f = open (pdbFile,'r')
k = 0
rc = 0
data = f.readlines()
g = open (dump.pdb, 'w')
for linedata in data:
    line=linedata.strip()
    words = line.split()
    if(words[0] == 'ATOM'):
        k=k+1
        words[5]=int(line[22:26].strip())
        if(words[5] in range(residMin,residMax+1)):
            g.write(linedata)
            for i in words:
                if(i=='CA'):
                    rc = rc+1
print(rc)

该代码无法正常工作,因为它给了我第22行的语法错误,其中指出dump.pbd ='pdb'+ pdbFile +''+'res'+ residMin +'' residMax +'.pdb'。所以你能帮我吗?

非常感谢您!

1 个答案:

答案 0 :(得分:1)

您已经忘记添加+符号。

此行应有效:dump.pbd='pdb' + pdbFile + '' + 'res' + residMin + '' + residMax + '.pdb'

+'_'之间必须有一个residMax符号,因为这是Python串联字符串语法。