I am using aprgeparse
in my program where to create an argument which allows the user to delete a file from a amazon s3 bucket. I create it in this way:
parser.add_argument("-r", "--remove",type = str, help= "Delete a file (enter full path to file)" , default = '' )
I then check if the file is available, if yes i delete it:
if args.remove:
b = Bucket(conn,default_bucket)
k = Key(b)
if b.get_key(args.remove):
b.delete_key(args.remove)
print ( ' {0} Has been removed'.format(args.remove.split("/")[-1]) )
else:
print ( " No files named '{0}' found ".format(args.remove.split("/")[-1] ) )
print ( ' Please check the bucket path or file name. Use -l command to list files')
I wanted to know if there is way I can prompt the user if he really intends the user to delete the file which is usually the case for deleting files (every program does it). Something like this
>python myprog.py -r foo.txt
>Are your sure [Y/N] : Y
>File deleted