I am trying to pass a command line arguments to AWS lambda as a event json.
I have a list out of the command line args like:
['engine', '-e', '100', '-w', '4']
When I pass this list I want to it get passed as:
'engine', '-e', '100', '-w', '4'
I am trying to use it like this:
listcommd = ['engine', '-e', '100', '-w', '4']
command = ["--bucket", "mybucket", f"{listcommand}"]
I want the end result to look like:
command = ["--bucket", "mybucket", 'engine', '-e', '100', '-w', '4']
but it is looking like:
command = ["--bucket", "mybucket", "['engine', '-e', '100', '-w', '4']"]
Lists support concatenation. Just do this:
command = ["--bucket", "mybucket"] + listcommand
Related
I have a global list and it seems that it doesn't update the list in the file it is declared. I have seen several question similar to my issue which I can use to fix my issue. But I was trying to understand why it does not work in my case.
HelloWorld.py
import TestFile
store_val = ["10", "20"]
def main():
store_val.append("30")
print store_val
TestFile.list_val()
if __name__ == '__main__':
main()
TestFile.py
import HelloWorld
def list_val():
HelloWorld.store_val.append("40")
print "Store Value : ", HelloWorld.store_val
HelloWorld.store_val.append("60")
print "Updated Value : ", HelloWorld.store_val
The problem that I see is that I am able to append a value to the list in TestFile.py but can't seem to add a value to the list in HelloWorld.py even though it is declared there. What is the best way to rectify this issue so that I can append the value from HelloWorld.py
Result of running HelloWorld
['10', '20', '30']
Store Value : ['10', '20', '40']
Updated Value : ['10', '20', '40', '60']
Should be this way instead . In your case only the store_val list and main function gets imported from HelloWorld in TestFile.py but the main function is not run in TestFile.py
HelloWorld.py
import TestFile
store_val = ["10", "20"]
def main(n=1):
store_val.append("30")
print store_val
if n>0:
TestFile.list_val(n)
if __name__ == '__main__':
main()
TestFile.py
import HelloWorld
def list_val(n):
if (n>=0):
HelloWorld.main(n-1)
HelloWorld.store_val.append("40")
print "Store Value : ", HelloWorld.store_val
HelloWorld.store_val.append("60")
print "Updated Value : ", HelloWorld.store_val
if __name__ == '__main__':
list_val()
Run Code:
python HelloWorld.py
['10', '20', '30']
['10', '20', '30']
Store Value : ['10', '20', '30', '40']
Updated Value : ['10', '20', '30', '40', '60']
I'm trying to pass a parameter that enables verbose logging with syslog. Passing -v to the application definitely works as expected. So I am trying to add this option to a json config file.
Here is what I have in the json config:
"rtl": {
"freq": 144.390,
"ppm": -3,
"gain": 44.5,
"debug": true,
"offset_tuning": false,
"device_index": 0,
},
Here is what I have in the code. Note: All the other parts work except when I add the -v statement.
if self.config['source'] == 'rtl':
proc_src = subprocess.Popen(
['rtl_fm', '-f', str(int(self.config['rtl']['freq'] * 1e6)), '-s', '22050',
'-v', str(self.config['rtl'].get('debug', 'true')), '-v'],,
'-p', str(self.config['rtl']['ppm']), '-g', str(self.config['rtl']['gain']),
'-E', 'offset' if self.config['rtl'].get('offset_tuning', False) else 'none',
'-d', str(self.config['rtl'].get('device_index', 0)), '-'],
stdout=subprocess.PIPE, stderr=open('/dev/null')
)
Here is the error I get:
SyntaxError: ('invalid syntax', ('/usr/local/lib/python2.7/dist-packages/pymultimonaprs/multimon.py', 37, 62, "\t\t\t\t\t'-v', str(self.config['rtl'].get('debug', 'true')), '-v'],\n"))
It seems like tabs are getting thrown into the -d statement. I'm fairly new to python and just struggling with this. Any ideas?
Two commas:
'-v', str(self.config['rtl'].get('debug', 'true')), '-v'],,
^^
proc_src = subprocess.Popen(
['rtl_fm',
'-f', str(int(self.config['rtl']['freq'] * 1e6)),
'-s', '22050',
'-v', str(self.config['rtl'].get('debug', 'true')),
'-v', #?
'-p', str(self.config['rtl']['ppm']),
'-g', str(self.config['rtl']['gain']),
'-E', 'offset'
if self.config['rtl'].get('offset_tuning', False) else 'none',
'-d', str(self.config['rtl'].get('device_index', 0)), '-'
],
stdout=subprocess.PIPE, stderr=open('/dev/null'))
I have checked similar error message questions but have not found anything that quite fits my situation. I am trying to time align a .wav file with a .lab file using HTK, Prosodylab-aligner, and SoX.
Here is my input (using Prosodylab-aligner):
./align.py /path/to/files
All that comes up is this line of code:
Command 'sox' returned non-zero exit status 2
I looked up what this code means and apparently it means there is a command or keyword missing
I believe that the problem is in the align.py file but I am not sure where exactly.
Here is the area of the file that references SoX.
def _check_aud(self, wav_list, train=False):
"""
Check audio files, mixing down to mono and downsampling if
necessary. Writes copy_scp and the training or testing SCP files
"""
copy_scp = open(self.copy_scp, 'a')
check_scp = open(self.train_scp if train else self.test_scp, 'w')
i = 0
if self.has_sox:
for wav in wav_list:
head = os.path.splitext(os.path.split(wav)[1])[0]
mfc = os.path.join(self.aud_dir, head + '.mfc')
w = wave.open(wav, 'r')
pids = [] # pids
if (w.getframerate() != self.sr) or (w.getnchannels() > 1):
new_wav = os.path.join(self.aud_dir, head + '.wav')
pids.append(Popen(['sox', '-G', wav, '-b', '16',
new_wav, 'remix', '-',
'rate', str(self.sr),
'dither', '-s'], stderr=PIPE))
wav = new_wav
for pid in pids: # do a join
retcode = pid.wait()
if retcode != 0:
raise CalledProcessError(retcode, 'sox')
print >> copy_scp, '"{0}" "{1}"'.format(wav, mfc)
print >> check_scp, '"{0}"'.format(mfc)
w.close()
else:
for wav in wav_list:
head = os.path.splitext(wav)[0]
mfc = os.path.join(self.aud_dir, head + '.mfc')
w = wave.open(wav, 'r')
if (w.getframerate() != self.sr) or (w.getnchannels() != 1):
error('File {0} needs resampled but Sox not found ', w)
print >> copy_scp, '"{0}" "{1}"'.format(wav, mfc)
print >> check_scp, '"{0}"'.format(mfc)
w.close()
copy_scp.close()
check_scp.close()
Factor out the sox command line in the pids.append(Popen(...)) call into a variable like cmd, and print that before running it.
That should give you a command line that you can reproduce the problem with, possibly see a more descpriptive error message, and maybe narrow the problem down by tweaking the arguments.
# ...
new_wav = os.path.join(self.aud_dir, head + '.wav')
cmd = ['sox', '-G', wav, '-b', '16',
new_wav, 'remix', '-', 'rate',
str(self.sr), 'dither', '-s']
print "About to execute command:\n%s" % ' '.join(cmd)
pids.append(Popen(cmd, stderr=PIPE))
wav = new_wav
# ...
argument_list = ['name=Jon', 'id=100' ]
output = subprocess.check_output(
['/usr/bin/python', 'test.py', argument_list ], stderr=subprocess.STDOUT)
In simple terms, I am trying to invoke a script using subprocess called test.py; I want to pass arguments to test.py through a list. Importatnt - List can be of any size.
Things I tried ,
output = subprocess.check_output(
['/usr/bin/python', 'test.py', ", ".join(argument_list) ], stderr=subprocess.STDOUT)
and
output = subprocess.check_output(
['/usr/bin/python', 'test.py', '%s' % argument_list ], stderr=subprocess.STDOUT)
Neither works because in subprocess.checkoutput should be (' ', ' ' ,' ') etc....
Is there a better way to do this ?
You can make a new list by adding lists together:
output = subprocess.check_output(['/usr/bin/python', 'test.py'] + argument_list, stderr=subprocess.STDOUT)
This will run test.py with argument_list as it's command-line parameters.
need to replace filename in subprocess command i.e. filename
filename = '\'D\:/imagesequence/thumbnail.jpg\''
task = '\"movie= ' + filename + '[watermark]; [in][watermark] overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/3 [out]\"'
c = subprocess.check_call(["ffmpeg", "-i", "D:/imagesequence/background222.jpg", "-vf", task, "D:/imagesequence/fwtm108.jpg"],shell=True)
this gives error
# Error: CalledProcessError: Command '['ffmpeg', '-i', 'D:/imagesequence/background222.jpg', '-vf', '"movie= \'D\\:/imagesequence/thumbnail.jpg\'[watermark];[in][watermark] overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/3 [out]"', 'D:/imagesequence/fwtm107.jpg']' returned non-zero exit status 1 #
when put altogether it works well
c = subprocess.check_call(["ffmpeg", "-i", "D:/imagesequence/background222.jpg", "-vf", "movie= 'D\:/imagesequence/thumbnail.jpg'[watermark]; [in][watermark] overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/3 [out]", "D:/imagesequence/fwtm101.jpg"],shell=True)
even this works
task = "movie= 'D\:/imagesequence/thumbnail.jpg'[watermark]; [in][watermark] overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/3 [out]"
c = subprocess.check_call(["ffmpeg", "-i", "D:/imagesequence/background222.jpg", "-vf", task, "D:/imagesequence/fwtm102.jpg"],shell=True)
any different view. I am not able to see it.
q = "D\:/imagesequence/thumbnail.jpg"
task = "movie= '%s'[watermark]; [in][watermark] overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/3 [out]" % q
c = subprocess.check_call(["ffmpeg", "-i", "D:/imagesequence/background222.jpg", "-vf", task, "D:/imagesequence/fwtm106.jpg"],shell=True)
this worked. thank you to
http://comments.gmane.org/gmane.comp.python.tutor/65858