You are not logged in.

#1 2015-08-09 18:32:43

j2lapoin
Banned
Registered: 2013-06-28
Posts: 102

an easy one for all python artist [SOLVED]

I want to be able to call a command from my python script. my problem seem to big with exporting variable to this one.

e.g:           i got a variable that give me the name of name of the package to install.   (pacman, for example)

                  from subprocess import call
                  call(["pacman -S commando[package-1]"])
                                                -----------------------------------> my variable

Thanks.

Last edited by j2lapoin (2015-08-09 21:13:33)

Offline

#2 2015-08-09 20:44:08

justasug
Member
Registered: 2014-08-03
Posts: 165

Re: an easy one for all python artist [SOLVED]

You should have asked this in the "Programming & Scripting" sub-forum.

Pass your command as a list with multiple items or split it up. Example:

call(["pacman", "-S", "your_package"])

or

call("pacman -S your_package".split())

Offline

#3 2015-08-09 21:12:41

j2lapoin
Banned
Registered: 2013-06-28
Posts: 102

Re: an easy one for all python artist [SOLVED]

That what i was looking for:
         

subprocess.call("sudo pacman -R " + commando[numo-1], shell=True)

It's now solved:
       Thank you. but I still have the famous getch() puzzle in mind. famous termios is nowhere.

Offline

#4 2015-08-09 21:15:53

baion baion
Member
From: Nicosia, Cyprus
Registered: 2009-06-13
Posts: 48

Re: an easy one for all python artist [SOLVED]

justasug wrote:

You should have asked this in the "Programming & Scripting" sub-forum.

Pass your command as a list with multiple items or split it up. Example:

call(["pacman", "-S", "your_package"])

or

call("pacman -S your_package".split())

I think that the OP wants to pass a variable name as an argument instead of a string of the package name. In this case the following can be used:

var1 = "your_package"
call(["pacman", "-S", var1])

Edit: By the time I posted the thread was solved sad.

Last edited by baion baion (2015-08-09 21:16:50)

Offline

#5 2015-08-09 21:39:00

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,092

Re: an easy one for all python artist [SOLVED]

j2lapoin wrote:

That what i was looking for:
         

subprocess.call("sudo pacman -R " + commando[numo-1], shell=True)

It's now solved:
       Thank you. but I still have the famous getch() puzzle in mind. famous termios is nowhere.


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

Board footer

Powered by FluxBB