FAQ
Hi all,
to obtain a file list from a dir you can use:
import os, sys
try:
. sExtension=sys.argv[1]
. sPath=sys.argv[2]
except:
. sExtension=""
. sPath='.'
lF=os.listdir(sPath)
# to remove from the list also the names of backup files
lF=filter(lambda lF: '~' not in lF and sExtension in lF,lF)

Running this small script you obtain the file list (based on a given
extension)
from a dir (sPath).
My question is: is there another better way? or can we use the
sys.stdin to capture
the stdout of a shell command?
Examples of single line shell commands could be:
ls -1 *.py (for the filenames only) or
find ~/ -name '*.py' (to get path+filename of all my root dir)

Unluckily, to capture the stdout I have to redirect it to a file...
I hoped that this could work ...
lF=sys.stdin.readline(os.system("ls -1 *.py"))
Bye.

Search Discussions

  • Thomas Guettler at May 26, 2005 at 2:05 pm
    Am Thu, 26 May 2005 06:31:40 -0700 schrieb qwweeeit:

    Hi,
    ls -1 *.py (for the filenames only) or
    This can be done with the module "glob" of the standard library.

    HTH,
    Thomas
  • Fredrik Lundh at May 26, 2005 at 5:49 pm

    qwweeeit at yahoo.it wrote:

    Unluckily, to capture the stdout I have to redirect it to a file...
    I hoped that this could work ...
    lF=sys.stdin.readline(os.system("ls -1 *.py"))
    hint: look up "os.popen" and "subprocess" in the library reference.

    </F>

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMay 26, '05 at 1:31p
activeMay 26, '05 at 5:49p
posts3
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase