Hey,
I'm fairly new to using python, but I started in my computer science course and I really enjoy using it. I was wondering if I could use python to run a program in bash where the python script specifies options such as: - mencoder -dvd 1 -oac copy -ovc copy -o movie-rip.avi
Is there any way I can change the options through an interactive python program? Or is it just ridiculously complicated?
Thanks for the consideration.
4 1493 bartonc 6,596
Recognized Expert Expert
Hey,
I'm fairly new to using python, but I started in my computer science course and I really enjoy using it. I was wondering if I could use python to run a program in bash where the python script specifies options such as: - mencoder -dvd 1 -oac copy -ovc copy -o movie-rip.avi
Is there any way I can change the options through an interactive python program? Or is it just ridiculously complicated?
Thanks for the consideration.
Not complicated at all: - # unix command line :mencoder -dvd 1 -oac copy -ovc copy -o movie-rip.avi
-
# 1st make some lists
-
-
Cmd = 'mencoder'
-
CmdOptions = ('-dvd', '-oac', '-ovc', '-o')
-
ReadableOptions = ('use', 'meaingful', 'terms', 'output file name')
-
-
# a dictionary for the results of user interaction
-
optionsDict = {} # empty, for now
-
-
# the interactive function
-
def GetOptionFromUser(readableName):
-
return raw_input('Enter the value for %s: ' %(readableName))
-
-
# the "script"
-
for i, option in enumerate(ReadableOptions): # this is how we count iteration
-
optionsDict[CmdOptions[i]] = GetOptionFromUser(option)
-
-
-
# create the command string
-
cmdStr = "%s %s" %(Cmd, " ".join([("%s %s" %(key, optionsDict[key])) for key in CmdOptions]))
-
-
# then, call os.system(cmdStr), os.spawn(), etc. depending on your needs
-
# Here, just print the command line:
-
-
print cmdStr
-
output after typing in only the values:
mencoder -dvd 1 -oac copy -ovc copy -o movie-rip.avi
bartonc 6,596
Recognized Expert Expert
Not complicated at all: - # unix command line :mencoder -dvd 1 -oac copy -ovc copy -o movie-rip.avi
-
# 1st make some lists
-
-
Cmd = 'mencoder'
-
CmdOptions = ('-dvd', '-oac', '-ovc', '-o')
-
ReadableOptions = ('use', 'meaingful', 'terms', 'output file name')
-
-
# a dictionary for the results of user interaction
-
optionsDict = {} # empty, for now
-
-
# the interactive function
-
def GetOptionFromUser(readableName):
-
return raw_input('Enter the value for %s: ' %(readableName))
-
-
# the "script"
-
for i, option in enumerate(ReadableOptions): # this is how we count iteration
-
optionsDict[CmdOptions[i]] = GetOptionFromUser(option)
-
-
-
# create the command string
-
cmdStr = "%s %s" %(Cmd, " ".join([("%s %s" %(key, optionsDict[key])) for key in CmdOptions]))
-
-
# then, call os.system(cmdStr), os.spawn(), etc. depending on your needs
-
# Here, just print the command line:
-
-
print cmdStr
-
output after typing in only the values:
mencoder -dvd 1 -oac copy -ovc copy -o movie-rip.avi
Line 21 has a lot going on in it. Here is that line broken down into its constituent parts: -
-
optionList = [] # an empty list
-
for key in CmdOptions:
-
optionList.append("%s %s" %(key, optionsDict[key])
-
optionStr = " ".join(optionList)
-
cmdStr = "%s %s" %(Cmd, optionStr)
Thanks a lot guys. You really helped me out. I'll just chew through the code, figure out what it is that you did, and get it to work for me. lol
bartonc 6,596
Recognized Expert Expert
Thanks a lot guys. You really helped me out. I'll just chew through the code, figure out what it is that you did, and get it to work for me. lol
I just caught an error on line 3. Here's the correction: - #
-
optionList.append("%s %s" %(key, optionsDict[key])) # missing paren
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Jorgen Grahn |
last post by:
I couldn't think of a good solution, and it's hard to Google for...
I write python command-line programs under Win2k, and I use the bash shell
from Cygwin. I cannot use Cygwin's python package because of a binary
module which has to be compiled with Visual C 6.
My scripts start with a '#!/usr/bin/env python' shebang, as God intended.
...
|
by: Peter Otten |
last post by:
Is there a way to limit both width and height of a canvas text item?
My current workaround seems clumsy:
import Tkinter as tk
root = tk.Tk()
canvas = tk.Canvas(root, width=400, height=200, bg="white")
canvas.pack()
# simulate a clipped text item - never transparent :-(
s = "The long and winding road.."
|
by: Shalen chhabra |
last post by:
Hey,
Can anyone give me a snippet for running a python program over all the files
in the directory.
For ex: I have ten files in a directory and I want to run a python program
against all of these files, I wish to do the same using another python code
instead of running each of these files one by one, which would be cumbersome
giving the...
|
by: Mike |
last post by:
We have a large c++ program that runs under Windows NT Embedded to
control an instrument. That program has been written to run external
python scripts. The computer where this code runs does not and cannot
have a full python installation. It ONLY has the pythonNN.dll file
that comes with a full python installation.
For simple scripts...
|
by: Edg Bamyasi |
last post by:
This Is A Late Cross Post from comp.lang.python. It seems the mistery
is deeper then i expected.
What is the running time of conactination on character strings.
i.e.
>> joe="123"
>> joe+="99999999999999999"
| |
by: John Salerno |
last post by:
If I want to write my code in a separate text editor (I like UltraEdit)
but then press a single button to have that code run in the IDLE
environment, is that possible? I know that you can configure UE to run
external tools, but I can't figure out how to run IDLE this way, because
when I check on its properties to find it's file path, it is...
|
by: Heikki Toivonen |
last post by:
We have successfully used a script to run external programs for several
years. Now we upgraded our Python to 2.5, and are hitting a mysterious
error.
The expected output from the sample script (see below) with 2.4 looks
like this:
ret
else
********************
|
by: Ojas |
last post by:
Hi!,
I just out of curiosity want to know how top detect the client side
application under which the script is getting run. I mean to ask the
how to know whether the script is running under Command Prompt or
Browser or some other application?
Ojas.
|
by: Jimmy |
last post by:
Well, i know it may be a little non-python thing, however, I can think
of no place better to post this question :)
can anyone tell me, in python, how to obtain some information of a
running program?
paticularly, if i am playing some music in audacious or other media
player, how can i get the the name and some other info of current
playing...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |