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 in Python by Taj
• 1,040 points
23 views

1 answer to this question.

0 votes

Hi,

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 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,160 points
56 views
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 in Python by Nymeria
• 3,520 points
578 views
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 in Python by Sushma
43 views
+3 votes
7 answers

How can I rename a file in Python?

yes, you can use "os.rename" for that. ...READ MORE

answered Mar 31, 2018 in Python by DareDev
• 6,810 points
160 views
+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 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 282 views
+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 in Python by Shabnam
• 920 points
43 views
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 in Python by Shabnam
• 920 points
604 views