I'm trying to get this script to take the contents of the tuple and cycle through using a for loop (I'm not sure where to put it in my code) and put the contents of the tuple in a command. For this example I've used find as the command. Depending on which option the executor uses sp1 or sp2 will determine how much of the tuple will be used.
import sys, subprocess, os, string
cmd = '/bin/find '
tuple = ('apple', 'banana', 'cat', 'dog')
sp1 = tuple[0:1]
sp2 = tuple[2:3]
def find():
find_cmd = subprocess.Popen(cmd + " * -name {}".format(type)),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
output, err = find_cmd.communicate()
find = output
find_temp = []
find_temp = string.split(find)
if find_temp[0] == ' ':
print("Found nothing")
else:
print("Found {}".format(find_temp))
type_input = input("Are you looking for fruit or animals? ")
if type_input == "fruit":
type = sp1
elif type_input == "animals":
type = sp2
print("syntax error")
exit()
find()
tuple) because they will override the name of the built-in in that scope. stackoverflow.com/a/2418007/1248974