程序获取 ls 目录列表打印项目的索引,然后要求选择一项,然后打印该项目,但我收到此错误:
./directory.py
from: can't read /var/mail/subprocess
./directory.py: línea 3: error sintáctico cerca del elemento inesperado `('
./directory.py: línea 3: `def listdir (path):'
这是我的代码
from subprocess import Popen, PIPE
def listdir (path):
p = Popen(['ls', path,'-t'] , shell=False, stdout=PIPE, close_fds=True)
return [path.rstrip('\n') for path in p.stdout.readlines()]
def find(f, seq):
for item in seq:
if f == item:
return item
def listshow(l,i):
for item in l:
print i, item
i = i + 1
dirlist = listdir("/home/juan/")
val = 0
listshow(dirlist, val)
while True:
try:
line = raw_input()
except EOFError:
if not line: break
print dirlist[line]