Python
Python Internet Access using Urllib.Request and urlopen()
What is urllib? urllib is a Python module that can be used for opening URLs. It defines functions and...
Python rename() file is a method used to rename a file or a directory in Python programming. The Python rename() file method can be declared by passing two arguments named src (Source) and dst (Destination).
This is the syntax for os.rename() method
os.rename(src, dst)
src: Source is the name of the file or directory. It should must already exist.
dst: Destination is the new name of the file or directory you want to change.
Example:
import os
os.rename('gtupapers.txt','career.gtupapers.txt') Let's look at example in detail
You can rename the original file, we have changed the file name from "gtupapers.txt" to "Career.gtupapers.txt."
Here is the complete code
import os
import shutil
from os import path
def main():
# make a duplicate of an existing file
if path.exists("gtupapers.txt"):
# get the path to the file in the current directory
src = path.realpath("gtupapers.txt");
# rename the original file
os.rename('gtupapers.txt','career.gtupapers.txt')
if __name__ == "__main__":
main()
What is urllib? urllib is a Python module that can be used for opening URLs. It defines functions and...
In order to log into Facebook using Python, you need to use Selenium (a web automation tool)....
Python map() applies a function on all the items of an iterator given as input. An iterator, for...
What is Python Enumerate? Python Enumerate() is a buit-in function available with the Python...
The formula to calculate average is done by calculating the sum of the numbers in the list divided by the...
Calendar module in Python has the calendar class that allows the calculations for various task...