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 1489
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
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
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...
|
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,...
|
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...
|
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...
|
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"
>>...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
| |