By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

Unable to Save Screenshots with dynamic name using image.grab() in PIL library

P: 12
import sys
import time
import os
from PIL import ImageGrab

print("Enter time interval to take screenshot")
time_int = 3
print("Time interval entered is %(time)d" %{"time":time_int})
img = ImageGrab.grab()
localtime = time.asctime( time.localtime(time.time()) )
localtime = localtime.replace(" ","_")
environ = os.environ
Files_Dir = r'images'
save_path = r'C:\\results'
File_name = localtime+'.jpg'
print("Filename is %(File_name)s" %{"File_name":File_name})
File_path = os.path.join(save_path, Files_Dir, File_name)
directory = os.path.join(save_path, Files_Dir)
print("path where the image saved is %(path)s" %{"path":File_path})
if not os.path.exists(directory):
except OSError as exception:
if exception.errno!=errno.EEXIST:
raise, "JPEG")

OSError: [Errno 22] Invalid argument: 'C:\\results\\images\\Thu_Aug__4_15:40:33_
Aug 4 '16 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.