I'm currently debugging a code and I've bumped into a "NameError: name 'file' is not defined" problem different from other entries, my problem is caused because the isinstance function doesn't understand the "file parameter"
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
the isinstance function wants two arguments that must be tuples. And as you can see "f" is defined. But "file" is not. I think there is an easy solution to this problem so if you can help it would be very helpful.
type(f) is io.TextIOWrapper(this only works for reading in text mode, in binary mode its io.BufferedRead)isinstancefunction, the error happens before that function is called, when the interpreter tries to resolve the name of the argument.filedeosn't exist. Was this code written for Python 2?os.path.isfile()from the 'os' module.