私はこのスクリプトをタプルの内容を取得し、for
ループを使用して取得しようとしています(私はコードをどこに置くべきか分かりません)。コマンド内のタプル。この例では、私はfind
をコマンドとして使用しました。エグゼキュータがsp1
またはsp2
を使用するオプションによって、使用されるタプルの量が決まります。タプルをコマンドに挿入するために使用
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')は、そのスコープ内のビルトインの名前を上書きするためです。 http://stackoverflow.com/a/2418007/1248974 – davedwards
あなたの問題は何ですか? – martineau