我目前正在调试一个代码,遇到了一个“NameError:name'file'未定义”问题。与其他条目不同,我的问题是因为isinstance函数不理解“file参数”
def write_param_file(f, molfile, name, frag_id, base_confs, max_confs, amino_acid=None): #{{{
'''Writes a Molfile object to a file.
f may be a file name or file handle.
base_confs is the number of heavy-atom conformations generated by e.g. Omega
max_confs is the maximum number of conformations desired after adding proton rotation
The total number of confs may still be larger than max_confs,
but at least we'll skip -ex# extra sampling of proton chis.
'''
close_file = False
if not isinstance(f, file):
f = open(f, 'w')
close_file = True
isinstance函数需要两个必须是元组的参数。正如你所看到的,“f”是被定义的。但“文件”不是。我认为这个问题有一个简单的解决办法,所以如果你能帮上忙,那将非常有帮助
文件是Python2中的现有类型,但不是Python3中的现有类型。使用Python2运行此代码,或者使用下面链接中的信息对其进行调整
isinstance file python 2.7 and 3.5
相关问题 更多 >
编程相关推荐