1
私はPythonでUnix find
コマンドを使用しようとしており、pwd
を入力することができないので、`pwd`
もうまくいきませんでした。UNIXを使用して `pwd`を見つけよう
import commands
import os
f = raw_input('Enter name of the file: ')
fh = open(f, 'r')
prevdir = os.getcwd()
files = fh.readlines()
for line in files:
os.chdir(line)
print commands.getoutput('find `pwd` -name "*.txt"')
# print commands.getoutput('find \`pwd\` -name "*.txt"')
あなたcommands.getoutputラインは私のために動作します。あなたはPythonシェルで試しましたか? – trans1st0r
他の人たちが示唆しているように、あなたがやろうとしていることをPythonで行う方法はほとんどありません。 'os.listdir'、' os.walk'、 'glob'モジュールなどですが、もしあなたがこのアプローチにコミットしていれば、' commands.getoutput( 'find "%s" -name "* .txt "'%os.getcwd())'。あなたが 'getoutput'に渡して、それが何をしているかを知っている文字列を' print'してください。 – jedwards
あなたが儀式です、それはPythonのshell.Iでの作業はtcshの中でこのプログラムを実行していません。それに関係があるかどうかは分かりません。 – Deep