file-extension

Open multiple files with the same extension in a folder

Open multiple files with the same extension in a folder Question: I want to open all files with the same extension (.dat) in the same directory. This is my current code: path = Path(".") # current directory extension = ".dat" file_with_extension = next(path.glob(f"*{extension}")) if file_with_extension: with open(file_with_extension, encoding=’utf-8′) as infile, open(‘462888.dat’, ‘w’, encoding=’utf-8′) as outfile: …

Total answers: 1

how to convert lmd file to csv? [Flow Cytometry data]

how to convert lmd file to csv? [Flow Cytometry data] Question: lmd file extension is often used for generating flow cytometry data. But this couldn’t be directly used for processing either in R or Python. Is there a way to somehow convert it to csv or some renowned format? Asked By: Sachin || Source Answers: …

Total answers: 3

Is there an idiomatic file extension for Jinja templates?

Is there an idiomatic file extension for Jinja templates? Question: I need to programatically distinguish between Jinja template files, other template files (such as ERB), and template-less plain text files. According to Jinja documentation: A Jinja template doesn’t need to have a specific extension: .html, .xml, or any other extension is just fine. But what …

Total answers: 8

Identify the file extension of a URL

Identify the file extension of a URL Question: I am looking to extract the file extension if it exists for web addresses (trying to identify which links are to a list of extensions which I do not want e.g. .jpg, .exe etc). So, I would want to extract from the following URL www.example.com/image.jpg the extension …

Total answers: 2

How to extract a file within a folder within a zip?

How to extract a file within a folder within a zip? Question: I need to extract a file called Preview.pdf from a folder called QuickLooks inside of a zip file. Right now my code looks a little like this: with ZipFile(newName, ‘r’) as newName: newName.extract(QuickLooksPreview.pdf) newName.close() (In this case, newName has been set equal to …

Total answers: 1

How can I check the extension of a file?

How can I check the extension of a file? Question: I’m working on a certain program where I need to do different things depending on the extension of the file. Could I just use this? if m == *.mp3 … elif m == *.flac … Asked By: wkoomson || Source Answers: Assuming m is a …

Total answers: 14

Changing file extension in Python

Changing file extension in Python Question: 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? Asked By: MysticCodes || Source Answers: os.path.splitext(), os.rename() for example: # renamee is the file getting renamed, pre …

Total answers: 9

Extracting extension from filename in Python

Extracting extension from filename in Python Question: Is there a function to extract the extension from a filename? Asked By: Alex || Source Answers: Use os.path.splitext: >>> import os >>> filename, file_extension = os.path.splitext(‘/path/to/somefile.ext’) >>> filename ‘/path/to/somefile’ >>> file_extension ‘.ext’ Unlike most manual string-splitting attempts, os.path.splitext will correctly treat /a/b.c/d as having no extension instead …

Total answers: 33