Suppose from index.py
with CGI, I have post file foo.fasta
to display file. I want to change foo.fasta
's file extension to be foo.aln
in display file. How can I do it?
When changing the extension, you're basically just renaming the file and changing the extension. In order to do that, you need to split the filename by '. ' and replace the last entry by the new extension you want.
Use rename() method of an OS module rename() method to rename a file in a folder. Pass both the old name and a new name to the os. rename(old_name, new_name) function to rename a file.
An elegant way using pathlib.Path:
from pathlib import Path p = Path('mysequence.fasta') p.rename(p.with_suffix('.aln'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With