So, I was making a python program that renames A.txt to B.txt, but I wanted the program to skip and move on if there is file "B.txt" already in the folder. Meanwhile, if there is neither A or B in the folder, then there is something wrong so I want the program to show me error and stop.
So I wanted "if A exists then rename it, if neither A nor B exists then show me error and stop the program, if only B exists then move on to next line"
What I did is this.
import os os.rename('A.txt','Btxt')
But if there is no A.txt, the program stops and shows me error message. How can I code what I want?