queston with glob!!

Sean 'Shaleh' Perry shaleh at valinux.com
Wed Apr 18 18:32:03 EDT 2001


On 18-Apr-2001 Tsang, Edward1 wrote:
> Thanks for your pointer, but after reading the doc. I do not undertstand
> what it means ..
> def func1():
>     import os.path, glob
>         
>     os.path.walk(currentDir,self.buildFileList,fileList)
>         
>     fileList = glob.glob(currentDir+os.sep+'*')
>     return fileList
> 
> def func2():
>     listDir = os.listdir('.')
>     
>     fileList = []
>     fileList = self.buildFileList(listDir,fileList)
> 
> Then I should expect fileList containing all the files with the full path
> names ...
> But I have got the following error:
>   

one of python's greatest features is that you can do everything in the
interactive interpreter.

import os
def printer(arg, dirname, names):
        for name in names:
                print os.path.join(dirname, name)

os.path.walk('/tmp', printer, None) # None is 'arg'

This will print the full name of every file in /tmp on my system:

/tmp/.X11-unix
/tmp/ssh-XXwRJMRM
/tmp/.X0-lock
/tmp/xfexec.547
/tmp/.ICE-unix
/tmp/shaleh
/tmp/xmms_shaleh.0
/tmp/texKgZaew
/tmp/root
/tmp/xfexec.598
/tmp/twirl
/tmp/mp3_list
/tmp/ksocket-shoon
/tmp/xfexec.660
/tmp/quit.blend
/tmp/texsNqTzm
/tmp/zman2i75HO
/tmp/xfexec.952
/tmp/jzip3ADB268412554AC
/tmp/jzip3ADB271B15654AC
/tmp/jzip3ADB279616E54AC
/tmp/jzip3ADB27B017254AC
/tmp/jzip3ADB29551A654AC
/tmp/fileWnhbnN
/tmp/file0oCaTs
/tmp/.X11-unix/X0
/tmp/ssh-XXwRJMRM/agent.454





More information about the Python-list mailing list