Re: waling a directory with very many files

2009-06-21 Thread Tim Golden
rkl wrote: I might be a little late with my comment here. David Beazley in his PyCon'2008 presentation "Generator Tricks For Systems Programmers" had this very elegant example of handling an unlimited numbers of files: David Beazley's generator stuff is definitely worth recommending on. I thi

Re: waling a directory with very many files

2009-06-21 Thread rkl
On Jun 15, 2:35 am, tom wrote: > i can traverse adirectoryusing os.listdir() or os.walk(). but if > adirectoryhas a very large number of files, these methods produce very > large objects talking a lot of memory. > > in other languages one can avoid generating such an object by walking > adirector

Re: waling a directory with very many files

2009-06-17 Thread Asun Friere
On Jun 15, 6:35 am, Andre Engels wrote: > What kind of directories are those that just a list of files would > result in a "very large" object? I don't think I have ever seen > directories with more than a few thousand files... (a...@lucrezia:~/pit/lsa/act:5)$ ls -1 | wc -l 142607 There, you'

Re: waling a directory with very many files

2009-06-16 Thread Nick Craig-Wood
Nick Craig-Wood wrote: > Jean-Paul Calderone wrote: > > On Mon, 15 Jun 2009 09:29:33 -0500, Nick Craig-Wood > > wrote: > > >Hrvoje Niksic wrote: > > >> Nick Craig-Wood writes: > > >> > > >> > Here is a ctypes generator listdir for unix-like OSes. > > >> > > >> ctypes code scares me with i

Re: waling a directory with very many files

2009-06-16 Thread thebjorn
On Jun 15, 6:56 am, Steven D'Aprano wrote: > On Sun, 14 Jun 2009 22:35:50 +0200, Andre Engels wrote: > > On Sun, Jun 14, 2009 at 6:35 PM, tom wrote: > >> i can traverse a directory using os.listdir() or os.walk(). but if a > >> directory has a very large number of files, these methods produce very

Re: waling a directory with very many files

2009-06-16 Thread Hrvoje Niksic
Nick Craig-Wood writes: > It can be done properly with gccxml though which converts structures > into ctypes definitions. That sounds interesting. > That said the dirent struct is specified by POSIX so if you get the > correct types for all the individual members then it should be > correct eve

Re: waling a directory with very many files

2009-06-15 Thread Mike Kazantsev
On Mon, 15 Jun 2009 15:35:04 -0400 Terry Reedy wrote: > Christian Heimes wrote: > > Terry Reedy wrote: > >> You did not specify version. In Python3, os.walk has become a generater > >> function. So, to answer your question, use 3.1. > > > > I'm sorry to inform you that Python 3.x still returns

Re: waling a directory with very many files

2009-06-15 Thread Nick Craig-Wood
Jean-Paul Calderone wrote: > On Mon, 15 Jun 2009 09:29:33 -0500, Nick Craig-Wood > wrote: > >Hrvoje Niksic wrote: > >> Nick Craig-Wood writes: > >> > >> > Here is a ctypes generator listdir for unix-like OSes. > >> > >> ctypes code scares me with its duplication of the contents of system >

Re: waling a directory with very many files

2009-06-15 Thread Terry Reedy
Christian Heimes wrote: Terry Reedy wrote: You did not specify version. In Python3, os.walk has become a generater function. So, to answer your question, use 3.1. I'm sorry to inform you that Python 3.x still returns a list, not a generator. >>> type(os.walk('.')) However, it is a genera

Re: waling a directory with very many files

2009-06-15 Thread Jean-Paul Calderone
On Mon, 15 Jun 2009 09:29:33 -0500, Nick Craig-Wood wrote: Hrvoje Niksic wrote: Nick Craig-Wood writes: > Here is a ctypes generator listdir for unix-like OSes. ctypes code scares me with its duplication of the contents of system headers. I understand its use as a proof of concept, or f

Re: waling a directory with very many files

2009-06-15 Thread Nick Craig-Wood
Hrvoje Niksic wrote: > Nick Craig-Wood writes: > > > Here is a ctypes generator listdir for unix-like OSes. > > ctypes code scares me with its duplication of the contents of system > headers. I understand its use as a proof of concept, or for hacks one > needs right now, but can anyone ser

Re: waling a directory with very many files

2009-06-15 Thread Diez B. Roggisch
tom wrote: > i can traverse a directory using os.listdir() or os.walk(). but if a > directory has a very large number of files, these methods produce very > large objects talking a lot of memory. if we assume the number of files to be a million (which certainly qualifies as one of the larger dire

Re: waling a directory with very many files

2009-06-15 Thread Hrvoje Niksic
Nick Craig-Wood writes: > Here is a ctypes generator listdir for unix-like OSes. ctypes code scares me with its duplication of the contents of system headers. I understand its use as a proof of concept, or for hacks one needs right now, but can anyone seriously propose using this kind of code i

Re: waling a directory with very many files

2009-06-15 Thread Hrvoje Niksic
Terry Reedy writes: > You did not specify version. In Python3, os.walk has become a > generater function. So, to answer your question, use 3.1. os.walk has been a generator function all along, but that doesn't help OP because it still uses os.listdir internally. This means that it both create

Re: waling a directory with very many files

2009-06-15 Thread Nick Craig-Wood
tom wrote: > On Jun 14, 1:35 pm, Tim Golden wrote: > > > > If you're on Windows, you can use the win32file.FindFilesIterator > > function from the pywin32 package. (Which wraps the Win32 API > > FindFirstFile / FindNextFile pattern). > > thanks, tim. > > however, i'm not using windows. freeb

Re: waling a directory with very many files

2009-06-14 Thread Steven D'Aprano
On Sun, 14 Jun 2009 22:35:50 +0200, Andre Engels wrote: > On Sun, Jun 14, 2009 at 6:35 PM, tom wrote: >> i can traverse a directory using os.listdir() or os.walk(). but if a >> directory has a very large number of files, these methods produce very >> large objects talking a lot of memory. >> >> in

Re: waling a directory with very many files

2009-06-14 Thread Tim Chase
i can traverse a directory using os.listdir() or os.walk(). but if a directory has a very large number of files, these methods produce very large objects talking a lot of memory. in other languages one can avoid generating such an object by walking a directory as a liked list. for example, in c,

Re: waling a directory with very many files

2009-06-14 Thread Christian Heimes
Terry Reedy wrote: > You did not specify version. In Python3, os.walk has become a generater > function. So, to answer your question, use 3.1. I'm sorry to inform you that Python 3.x still returns a list, not a generator. ython 3.1rc1+ (py3k:73396, Jun 12 2009, 22:45:18) [GCC 4.3.3] on linux2

Re: waling a directory with very many files

2009-06-14 Thread MRAB
Christian Heimes wrote: tom schrieb: i can traverse a directory using os.listdir() or os.walk(). but if a directory has a very large number of files, these methods produce very large objects talking a lot of memory. in other languages one can avoid generating such an object by walking a directo

Re: waling a directory with very many files

2009-06-14 Thread Christian Heimes
Andre Engels wrote: > What kind of directories are those that just a list of files would > result in a "very large" object? I don't think I have ever seen > directories with more than a few thousand files... I've seen directories with several hundreds of thousand files. Depending on the file syste

Re: waling a directory with very many files

2009-06-14 Thread Terry Reedy
tom wrote: i can traverse a directory using os.listdir() or os.walk(). but if a directory has a very large number of files, these methods produce very large objects talking a lot of memory. in other languages one can avoid generating such an object by walking a directory as a liked list. for exa

Re: waling a directory with very many files

2009-06-14 Thread Christian Heimes
tom schrieb: > i can traverse a directory using os.listdir() or os.walk(). but if a > directory has a very large number of files, these methods produce very > large objects talking a lot of memory. > > in other languages one can avoid generating such an object by walking > a directory as a liked l

Re: waling a directory with very many files

2009-06-14 Thread Andre Engels
On Sun, Jun 14, 2009 at 6:35 PM, tom wrote: > i can traverse a directory using os.listdir() or os.walk(). but if a > directory has a very large number of files, these methods produce very > large objects talking a lot of memory. > > in other languages one can avoid generating such an object by walk

Re: waling a directory with very many files

2009-06-14 Thread Tim Golden
tom wrote: On Jun 14, 1:35 pm, Tim Golden wrote: If you're on Windows, you can use the win32file.FindFilesIterator function from the pywin32 package. (Which wraps the Win32 API FindFirstFile / FindNextFile pattern). thanks, tim. however, i'm not using windows. freebsd and os x. Presumably,

Re: waling a directory with very many files

2009-06-14 Thread tom
On Jun 14, 1:35 pm, Tim Golden wrote: > > If you're on Windows, you can use the win32file.FindFilesIterator > function from the pywin32 package. (Which wraps the Win32 API > FindFirstFile / FindNextFile pattern). thanks, tim. however, i'm not using windows. freebsd and os x. -- http://mail.pyth

Re: waling a directory with very many files

2009-06-14 Thread Tim Golden
tom wrote: i can traverse a directory using os.listdir() or os.walk(). but if a directory has a very large number of files, these methods produce very large objects talking a lot of memory. in other languages one can avoid generating such an object by walking a directory as a liked list. for exa