Help with Python script

GEC: Discuss gaming, computers and electronics and venture into the bizarre world of STGODs.

Moderator: Thanas

Post Reply
User avatar
Dominus Atheos
Sith Marauder
Posts: 3904
Joined: 2005-09-15 09:41pm
Location: Portland, Oregon

Help with Python script

Post by Dominus Atheos »

I'm trying to make a simple script to rip dvds for me, but my experience isn't great enough to know how to do what I'm trying to do. I have this script:

Code: Select all

import os
a=raw_input("What is the name of the disk? ")
b=input("Which disk is this? ")
os.system("c:\dvddecrypter.exe /MODE isoread /SRC G: /dest e:\Misc\Dvd Rips\%variableA%\%variableA% Disk %variableB%.iso /split NONE /OVERWRITE YES /DIRECT * /start /CLOSE")
I want to change the switches/arguments that the script passes to dvd decrypter based on my answers to the first two inputs. So the script would ask me "What is the name of the disk?" and then I'd say "Battlestar Galactica Season 2" and then the script would ask me which disk it was and I'd answer "2". The script then calls dvd decrypter with certain arguments/switches based on those two variables and so tells it to save the ISO as "e:\Misc\Dvd Rips\Battlestar Galactica Season 2\Battlestar Galactica Season 2 Disk 2.iso"

So how do I insert those variables into just those 3 parts of the argument?
User avatar
Darth Paul
Sith Apprentice
Posts: 52
Joined: 2002-08-22 11:44pm
Location: Canada

Re: Help with Python script

Post by Darth Paul »

Simplest way if you only care about using the script on your own computer is to use basic string concatenation (using +) like the following. You're dvddecryptor program probably needs paths/filenames enclosed in their own quotes (so with spaces it is still considered one string) - take out the double-quotes if I'm wrong. A neat thing about python is that you can use single or double quotes to delimit a string so you don't need to escape-sequence the other type of quote. To get fancier and check your input etc, look up os.path in the python help.

Code: Select all

import os
diskName=raw_input("What is the name of the disk? ")
diskNum=input("Which disk is this? ")

cmdString = 'c:\\dvddecrpyter.exe /MODE isoread /SRC G: /dest "e:\\Misc\\Dvd Rips\\' + diskName + '\\' + diskName + '" Disk ' + diskNum + '.iso /split NONE /OVERWRITE YES /DIRECT * /start /CLOSE'

print cmdString
raw_input("If that looks ok, press enter :)")
os.system( cmdString )
which comes up with something like:
c:\dvddecrpyter.exe /MODE isoread /SRC G: /dest "e:\Misc\Dvd Rips\my disk\my disk" Disk Test.iso /split NONE /OVERWRITE YES /DIRECT * /start /CLOSE
User avatar
Dominus Atheos
Sith Marauder
Posts: 3904
Joined: 2005-09-15 09:41pm
Location: Portland, Oregon

Re: Help with Python script

Post by Dominus Atheos »

That works great, thanks a lot.
User avatar
The Yosemite Bear
Mostly Harmless Nutcase (Requiescat in Pace)
Posts: 35211
Joined: 2002-07-21 02:38am
Location: Dave's Not Here Man

Re: Help with Python script

Post by The Yosemite Bear »

why do I have the desire to post the dead parrot sketch in this?

oh yeah, puns.
Image

The scariest folk song lyrics are "My Boy Grew up to be just like me" from cats in the cradle by Harry Chapin
User avatar
Beowulf
The Patrician
Posts: 10621
Joined: 2002-07-04 01:18am
Location: 32ULV

Re: Help with Python script

Post by Beowulf »

I would have posted an answer myself, but it seemed like a much better idea for you to figure out for yourself how to use variables rather than to just hand you an answer. After all, give a man fire, and he's warm for a night. Set a man on fire, and he's warm for the rest of his life.
"preemptive killing of cops might not be such a bad idea from a personal saftey[sic] standpoint..." --Keevan Colton
"There's a word for bias you can't see: Yours." -- William Saletan
Post Reply