Python Forum
Correct syntax for a variable inside a quotes: MP4Box command
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Correct syntax for a variable inside a quotes: MP4Box command
#1
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 :(
Reply
#2
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'"
Reply
#3
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 !
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable definitions inside loop / could be better? gugarciap 2 438 Jan-09-2024, 11:11 PM
Last Post: deanhystad
  How to create a variable only for use inside the scope of a while loop? Radical 10 1,711 Nov-07-2023, 09:49 AM
Last Post: buran
  Need help on how to include single quotes on data of variable string hani_hms 5 2,028 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  How to write a part of powershell command as a variable? ilknurg 2 1,120 Jul-26-2022, 11:31 AM
Last Post: ilknurg
  Os command output in variable shows wrong value paulo79 2 1,509 Apr-09-2022, 03:48 PM
Last Post: ndc85430
  Cursor Variable inside Another Cursor . CX_ORacle paulo79 1 1,518 Apr-09-2022, 10:24 AM
Last Post: ibreeden
  How to use a variable in linux command in python code? ilknurg 2 1,601 Mar-14-2022, 07:21 AM
Last Post: ndc85430
  Why does absence of print command outputs quotes in function? Mark17 2 1,381 Jan-04-2022, 07:08 PM
Last Post: ndc85430
  Command output to Variable ironclaw 1 1,784 Aug-26-2021, 06:55 PM
Last Post: bowlofred
  Two types of single quotes Led_Zeppelin 2 1,910 Mar-15-2021, 07:55 PM
Last Post: BashBedlam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020