- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to change file extension in Python?
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. You can do this using the os.rename method.
>>> import os >>> my_file = 'my_file.txt' >>> base = os.path.splitext(my_file) >>> os.rename(my_file, base + '.bin')
This will rename my_file.txt to my_file.bin
- How to extract file extension using Python?
- Change the file extension in the text column in MySQL?
- Perl File Extension
- How to change file permissions in Python?
- How to write Python regular expression to match with file extension?
- How to get the file extension using PowerShell?
- Get file extension name in Java
- How to get file extension of file as a result of MySQL query?
- How to change the permission of a file using Python?
- How to change the mode of a file using Python?
- How to change the owner of a file using Python?
- Create temporary file with specified extension suffix in Java
- Package extension utility in Python
- C# program to get the extension of a file in C#
- How to raise Python exception from a C extension?