NameError:名称“文件”未定义为isinstance参数

2024-10-02 00:40:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在调试一个代码,遇到了一个“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”是被定义的。但“文件”不是。我认为这个问题有一个简单的解决办法,所以如果你能帮上忙,那将非常有帮助


Tags: ofthe函数namenumberbase参数is

热门问题