The date
command, and basically every other command intended for interactive command-line use, terminates its output with a newline.
If that is not what you need, trimming the final newline from the output of a subprocess call is a very common thing to do (and in the shell, the hardcoded default behavior of process substitutions with `backticks`
and the modern $(command)
syntax).
But you don't need a subprocess to create a date string -- Python has extensive (albeit slightly clunky) support for this in its standard library, out of the box. See e.g. here.
import time
filename = time.strftime('security%Y.%m.%d_%H.%M.%S.jpg')
or, adapted into your first example snippet,
args = ['fswebcam','--no-banner','-r',' 960x720',
time.strftime('filename%Y.%m.%d_%H.%M.%S.jpg')]
Because both slashes and (to a lesser extent, but still) colons are problematic characters to have in file names, I have replaced them with dots. For purely aesthetic reasons, I also changed the comma to an underscore (doubtful; underscores are ugly, too).
I also switched the generated file names to use a standard datestamp naming convention with a full-digit year first, so that file listings and glob loops produce the files in correct date order.
Probably the code should be further tweaked to contain a proper ISO 8601 date in the file name; then if you want to parse and reformat it for human consumption separately, you are free to do that. But avoid custom date formats when there are standard formats which can be both read and written by existing code, as well as unambiguously understood by humans.