You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
dstoeckel edited this page Mar 16, 2015
·
2 revisions
How to create temporary files?
BALL offers a method !File::createTemporaryFilename().
C++
#include<BALL/SYSTEM/file.h>
...
// allocate space for the temporary name
String filename1 = "";
String filename2 = "";
// create a fileanameFile::createTemporaryFilename(filename1);
// create a file for writing
File file1(filename1, std::ios::out);
...
file1.close();
// create another file for writing File::createTemporaryFilename(filename2);
File file2(filename2, std::ios::out);
...
file2.close();
// finally remove the filesFile::remove(filename1);
File::remove(filename2);
Note: All files have to be handled separately since otherwise the temporary filenames cannot be computed correctly.
Python
Python already offers a module tempfile to generate temporary files and directories. So lets use this :-)
importtempfileimportosfromBALLimport*# get a temporary file namefile,fname=tempfile.mkstemp()
os.close(file)
# use the name to create a BALL file. e.g. PDBFilefile=PDBFile(fname, File.MODE_OUT)
file.write(S)
file.close()
# don't forget to close and delete the filefile.close()
os.unlink(fname)