How python modifies the file name suffix
Most people do not understand the knowledge points of this article "python how to modify the file name suffix", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "python how to modify the file name suffix" article.
The specific steps are as follows:
1. First, open python and create a new python project
After the 2.python project is created, import the os module in the project using the import method
Import os
After the 3.os module is imported, define a file path in the project
File = "/ var/www/text.csv"
4. After the file path is defined, use the os.split () method to get the file name
Filename = os.split (file)
5. After the file name is obtained, you can use the os.splitext () method to get the file suffix
Fliesion = os.splitext (filename)
6. Finally, after getting the file suffix, you can use the os.rename () method to modify the file name suffix
Newname = portion [0] + ".txt"
Os.rename (filename,newname) / / modify the .csv suffix to .txt
The above is about the content of this article on "how to modify the suffix of the file name in python". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.