python - 在 Python 中定义额外变量会导致错误
问题描述
我有这个代码片段:(我认为代码的其他部分并不重要。)
mol = editable_mol.GetMol()
neighbors = mol.GetAtomWithIdx(lastAtomIndex).GetNeighbors()
for nb_atom in neighbors:
atom_type, h_aro, h_alp, h_beta, h_gam = common.getAtomTypeAndHmnr(nb_atom)
if atom_type == 9:
common.setAtomTypeAndHmnr(nb_atom, 9, 0, 1, 0, 0)
Chem.EditableMol.ReplaceAtom(editable_mol, nb_atom.GetIdx(), nb_atom)
它运行完美。但是,如果我使用这样的变量editable_mol.GetMol()
代替:mol
neighbors = editable_mol.GetMol().GetAtomWithIdx(lastAtomIndex).GetNeighbors()
for nb_atom in neighbors:
atom_type, h_aro, h_alp, h_beta, h_gam = common.getAtomTypeAndHmnr(nb_atom)
if atom_type == 9:
common.setAtomTypeAndHmnr(nb_atom, 9, 0, 1, 0, 0)
Chem.EditableMol.ReplaceAtom(editable_mol, nb_atom.GetIdx(), nb_atom)
程序给出错误。这意味着我必须使用 mol 变量。但我不明白为什么我必须使用它。在 python 中定义额外变量是否会改变?我认为这两个代码是相同的。
程序给出了这个错误,但我认为这个错误与内容无关:
atom_type, h_aro, h_alp, h_beta, h_gam = common.getAtomTypeAndHmnr(nb_atom) 文件“C:\Users\phitech_halil\Documents\Tupras Projects\MolGenPython\phitech\common.py”,第 302 行,在 getAtomTypeAndHmnr return int(atom.GetProp (KEY_ATOM_TYPE)), int(atom.GetProp(KEY_H_AROMATIC)), int(atom.GetProp(KEY_H_ALPHA)), \ KeyError: 'atom_type'
唯一不同的是定义mol
变量,但程序给出了错误。我认为这个问题与editable_mol
对象或GetMol()
功能无关。有什么想法吗?
解决方案
推荐阅读
- python - Octave isnan:使用 oct2py 未定义错误
- php - PHP 替换图像 src 并从包含不同 html 标记的字符串中在图像标记中添加新属性
- r - ggadjustedcurves, fun="cumhaz" 不起作用
- powershell - Foreach 不处理每个项目,尝试将所有项目作为一行处理
- javascript - Javascript 通过引用传递以在以后在另一个文件中被覆盖
- ios - 仅允许从 UITextField 中选择和复制不起作用
- c# - 如何根据特定记录的数量以编程方式在 csv 文件中插入行
- javascript - 将返回组匹配的 Javascript RegEx.exec 转换为 Python
- java - 读入 WAV 文件并计算 RMS
- c# - 输入字符串的格式不正确。视觉工作室 2017