python with open change file name code example
Example 1: python rename file
import os
os.rename('guru99.txt','career.guru99.txt')
Example 2: how to rename files python
import os
os.rename(r'C:\Users\Ron\Desktop\Test\Products.txt',r'C:\Users\Ron\Desktop\Test\Shipped Products.txt')
Example 3: with open python print file name
>>> f = open('/tmp/generic.png','r')
>>> f.name
'/tmp/generic.png'
>>> import os
>>> os.path.basename(f.name)
'generic.png'