How to rename a file using Python?

0 votes
Hi, I have a text file which I want to convert into kml file.
Aug 2, 2019 in Python by Taj
• 1,060 points

1 answer to this question.

0 votes


We can use rename() method to rename a file or directory source 'src' (actual name) to destination 'dst'(new name).  And this method does not return any value.

Use the following syntax:

os.rename(src, dst)

In your case, you can use the following code:

import os
os.rename('abc.txt', 'xyz.kml')

answered Aug 2, 2019 by Shabnam
• 920 points

Related Questions In Python

0 votes
1 answer

How to download a file over HTTP using Python?

In Python 2, use urllib2 which comes ...READ MORE

answered Oct 18, 2018 in Python by SDeb
• 13,250 points
0 votes
1 answer

How to use read a WSDL file from the file system using Python suds?

Hi, good question. It is a very simple ...READ MORE

answered Jan 21, 2019 in Python by Nymeria
• 3,520 points
0 votes
1 answer

How to read data from a text file using Python?

Refer to the below example where the ...READ MORE

answered May 12, 2019 in Python by Sushma
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,180 views
0 votes
0 answers
+1 vote
1 answer

How to check if a string is in a file, using python?

Hi, Try the below given code: with open('myfile.txt') as ...READ MORE

answered Jul 4, 2019 in Python by Shabnam
• 920 points
0 votes
1 answer

How to add a new Python interpreter in PyCharm?

Refer to the below screenshots: Then set a ...READ MORE

answered May 30, 2019 in Python by Shabnam
• 920 points