In the absence of judgment file api:
os i.e. operating system (OS), Python os module encapsulates the common file and directory operations.
os.path module is used to obtain the attributes of the file, exists is "present" means, so that the name implies, os.path.exists () is to determine whether the file exists in parentheses mean, can be a file path within the parentheses.
For chestnut:
User.py a file to exist in the current directory
Enter the code:
OS Import
path os.path.exists = ( 'user.py')
Print (path)
output:
True
Process Finished with Exit code 0
if not, return is FALSE.
Original link: https: //blog.csdn.net/u012424313/article/details/82216092
Delete files api:
if os.path.exists(dest_file):
os.remove(dest_file)
Reference: https://www.runoob.com/python/os-remove.html