Python Forum

Full Version: Correct syntax for a variable inside a quotes: MP4Box command
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
New to the forum so hope I'm using the correct method here: -
I'm using an app to covert h264 video to mp4 = MP4Box.
Most of the tutorials deal with conversion inside the current folder so that the command is: -

command = "MP4Box -add example.h264 example.mp4" 
This works great
Now I've found out through my own experimentation you can do something like this

command = "MP4Box -add ''/var/www/html/LifeSaverHTML/eg,h264' '/var/www/html/LifeSaverHTML/eg.mp4'"
But what I really want to do is use a variable for the path. This is my function below:-
first = path
    last = "/examplevid.mp4"    
    fullpath = first + last
    tester = "/var/www/html/LifeSaverHTML/Details/19/examplevid.h264"
    command = "MP4Box -add '"%tester"'%tester '/var/www/html/LifeSaverHTML/Details/19/examplevid.mp4'"
I've tried all sorts of suggested methods with this: -
"tester"
"'+tester+'"
I can't even remember some of the suggestions I've tried.
Can someone please tell me the correct syntax? I've been at this for 2 hours now :(
Use string formatting and now should use f-string.
Example using your working command and put in variables.
>>> first = '/var/www/html/LifeSaverHTML/eg,h264'
>>> last = '/var/www/html/LifeSaverHTML/eg.mp4'
>>> command = f"MP4Box -add '{first}' '{last}'"
>>> print(command)
MP4Box -add '/var/www/html/LifeSaverHTML/eg,h264' '/var/www/html/LifeSaverHTML/eg.mp4'
>>> 
>>> #Assign to a variable the command is like this
>>> print(repr(command))
"MP4Box -add '/var/www/html/LifeSaverHTML/eg,h264' '/var/www/html/LifeSaverHTML/eg.mp4'"
Sorry I didn't explain myself correctly Snippsat.
What I wanted is something like this:-

path1 = /mypath/example.h264
path2 = /mypath/example.mp4

MP4Box -add path1 path2

Please excuse my extreme n00beeness I see it now Snippsat!
It's working thank you so much !