简体   繁体   English

我该如何处理此回溯名称错误? 这是我的第一个剧本

[英]How do i deal with this traceback name error? This is my first script

The error is as follows 错误如下

Traceback (most recent call last):
File "./unzipemall3.py", line 14, in <module>
   sformat = parentFormat('start')
File "./unzipemall3.py", line 9, in parentFormat
   parent = input(where + " Folder name (ex. Mol1-A) : ")
File "<string>", line 1, in <module>
NameError: name 'mol8' is not defined

!/usr/bin/env python !/ usr / bin / env python

from os import chdir from subprocess import Popen, PIPE 从操作系统导入chdir从子进程导入Popen,PIPE

def parentFormat(where): ## returns a list with the separator of '-' ## ex. def parentFormat(where):##返回带有'-'## ex分隔符的列表。 Mol1-A returns [Mol1, A] # input for most parent folder parent = raw_input(where + " Folder name (ex. Mol1-A) : ") return parent.split('-') Mol1-A返回[Mol1,A]#对大多数父文件夹的输入parent = raw_input(其中+“文件夹名称(例如Mol1-A):”)返回parent.split('-')

if ' main ' == name : 如果' main '== name

sformat = parentFormat('Start')
eformat = parentFormat('End')

cp_dir_prop = {'mol': cformat[0][:3], 'number': '5', 'letter': 'A'}
cp_files = ['vi.job', 'numjob', 'ortho.inp', 'job']
cp_dir = cp_dir_prop['mol'] + cp_dir_prop['number'] + "-" + cp_dir_prop['letter']
cp_dir = '/'.join([cp_dir, cp_dir]) + "-1"

try:
    for i in range(0, cutInt(eformat[0])):
        cformat[0] = sformat[0][:3] + str(cutInt(sformat[0]))

        for j in range(0, ord(eformat[1])-64):
            cformat[1] = chr(ord(sformat[1]) + j)

            # ex. mkdir Mol8-A/Mol8-A-1
            directory = '-'.join(cformat) + '/' + '-'.join(cformat + ['1'])
            Popen(['mkdir', directory])

            # ex. cp [files from Mol5-A-1] Mol8-A-1/
            for cp_file in cp_files:
                Popen(['cp', '/'.join([cp_dir, cp_file]), directory + '/'])

            # ex. tar -xf Mol8-A
            Popen(['tar', '-xf', '-'.join(cformat) + ".tgz"])

            # rm charmm-gui
            Popen(['rm', 'charmm-gui'])

            # ex. cd Mol8-A
            chdir('-'.join(cformat))

            # sed -i -e '0,/dimensions/s/dimensions/!dimensions.' -e '5s/.*/DIMENS CHSIZE 1000000/' -e '68s/.*/DYNA CPT leap start time 0.002 nstep 25000 -/' step5.1_production.inp
            sed = ['sed', '-i']
            sed.extend(['-e', '5s/.*/DIMENS CHSIZE 1000000/'])
            sed.extend(['-e', '68s/.*/DYNA CPT leap start time 0.002 nstep 25000 -/'])
            sed.extend(['-e', '0,/dimensions/s/dimensions/!dimensions'])
            sed.extend(['step5.1_production.inp'])
            Popen(sed)

            # sed -i -e '3s/nodes=4/nodes=1/' -e '37s:.*:mpirun ~/charmm.c36a4.20140107.newcali4.fixhcali.grange.b < ortho.inp   >charmm.out:' job5
            sed = ['sed', '-i']
            sed.extend(['-e', '3s/nodes=4/nodes=1/'])
            sed.extend(['-e', '37s:.*:mpirun ~/charmm.c36a4.20140107.newcali4.fixhcali.grange.b < ortho.inp   >charmm.out:'])
            sed.extend(['job5'])
            Popen(sed)

            # msub -q backfill job5
            Popen(['msub', '-q', 'backfill', 'job5'])

            # cd ..
            chdir('..')

except Exception as e:
    print (e)

I'm guessing you're using Python 2.7 or lower. 我猜您正在使用Python 2.7或更低版​​本。

parent = input(where + " Folder name (ex. Mol1-A) : ")

On this line, if the user types mol8 , the interpreter will look for the variable mol8 and try to assign it to parent . 在这一行上,如果用户键入mol8则解释器将查找变量mol8并尝试将其分配给parent But this won't work because the variable mol8 doesn't exist. 但这将不起作用,因为变量mol8不存在。 If you want parent to contain the string value "mol8" , use raw_input . 如果要让parent包含字符串值"mol8" ,请使用raw_input

parent = raw_input(where + " Folder name (ex. Mol1-A) : ")

Alternatively, upgrade to Python 3, where raw_input has been renamed to input . 或者,升级到Python 3,其中raw_input已重命名为input

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在第一个 Traceback 之前首先执行我的自定义错误消息? - How do I execute first my custom error message before the first Traceback? 我的代码有什么问题? 我该如何处理这个错误? - What is the issue with my code? How do I deal with this error? 如何在Python 3中解决创建SQL Lite数据库并为第一行名称和年龄打印十六进制的Traceback错误? - How to I resolve the Traceback error for creating SQL Lite database and printing a hex for first row name&age in python 3? 如何修复我的第一个 python 代码? 名称错误,class 名称未定义 - How do I fix my first python code? Name error, class name not defined 如何使用没有追溯错误的python脚本调试错误? - How to debug an error with python script with no traceback errors? django MultiValueDictKeyError 错误,我该如何处理 - django MultiValueDictKeyError error, how do I deal with it 为什么我会收到此回溯错误? - Why do i get this traceback error? 如何使用带有Matlab系统功能的Python处理“没有名为library_name的模块”错误? - How do I deal with 'no module named library_name' error using Python with Matlab's system function? 使用lightGBM时如何处理“不支持功能名称中的非ASCII字符”错误? - How to deal with "Do not support non-ASCII characters in feature name" error when I use lightGBM? 如何在没有回溯的情况下进行异常处理? - How do I do the exception without the traceback?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM