Wednesday, 11 February 2015

How do I run a bash command in python 3? topic






Hi I'm trying to learn how to use python. What I want to do it change some of my bash scripts into python 3 scripts as I learn python. I have a bash script that does apt-get update and want to now I would do that in python?

I installed python 3 with apt-get install idle3 to learn python3

found this but I think it is old
import subprocess

def bash_command(cmd):
subprocess.Popen(cmd, shell=True, executable='/bin/bash')

bash_command('a="Apples and oranges" && echo "${a/oranges/grapes}"')

I get this error message in idle3
SyntaxError: multiple statements found while compiling a single statement
with a red line after import subprocess






No comments:

Post a Comment