I’m relatively new to python and know very little syntax, but I’m willing to learn as much as possible. Simply put I want to use the save feature in PIL to save a .png with the file’s name being the current date and time. This may be complicated by the fact that I’m not using PIL directly, but through the Videocapture module, but i doubt it. this is my code that works
from VideoCapture import Device
cam = Device()
cam.saveSnapshot('C:\Users\Myname\Dropbox\Foldes\image.png', timestamp=3, boldfont=1, textpos='bc')
Its short, but it does what I need it to.
I realize Datetime will need to be imported, But I can’t get the data as the name without errors. yes i have tried the str() command. Any help will be greatly appreciated.
In strings in Python, backslashes have special meaning so you need to treat them differently. You can either use two of them instead of one…
…or you can put an
rbefore the string (as long as it doesn’t end with a backslash)To generate a string containing the current day in
YYYY-MM-DD-HH:MMformat, we can use the datetime module like this. To format the timestamp differently, consult the documentation here.As a shorter alternative, you could use the similar
timemodule instead:After this, you should just be able to do
to save the image with the datetime in the filename. (I have split the function call over two lines for readability, see this question for some explanation of how this works.)