Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do delete a PIL Image?

I am trying to replace an Image file using Python PIL.

im = Image.open(logo_dir+cat_string_im)

What function do I call to delete the original file?

im.delete() or im.replace() don't work.

like image 670
zenCoder Avatar asked Dec 25 '22 15:12

zenCoder


2 Answers

Probably the most straightforward way is to use os.remove() to delete the file. This is basic functionality, so it's not too likely that every module that works with files also includes facilities for file copying, moving, deletion, etc.

like image 76
MattDMo Avatar answered Dec 29 '22 10:12

MattDMo


You don't need PIL to delete the image. You can do it with

os.remove(path, *, dir_fd=None)

http://docs.python.org/3.3/library/os.html#os.remove

like image 34
dirn Avatar answered Dec 29 '22 12:12

dirn