I have used biopython 1.72 to read from multiple aligned protein data files. I have extracted some required data from the files to other text files which are then used as input to next function. I need to know if I can create that text file to be a temporary file so that as the script ends the file is also destroyed.
Here is the example code I've used so far:
from Bio import SeqIO with open ("Example.aln" , 'r') as fo: ### Opening a file from user list1 = (fo.read().split("\n\n\n")) ### Splitting the file every 3 newline charc str1 = ''.join(list1) list2 = str1.split("\n\n") outfile = open ("sample.txt",'w') outfile.write("This is a text File displaying information about the given sequence file\n\n") outfile.write(list2) outfile.close() fo.close() ## Closing the file taken from user
A clustal format file is taken from user and some of the data is extracted to a text file named
'sample.txt'. This file is then used as an input to another function which opens this text file and performs something else.
What I am asking for is that if I can create this intermediate text file as a temporary file so that it is destroyed as the function exits.
I've tried using the python
tempfile Module for this , but it does not work the way I am looking for.
Can I get any help??