[Tutor] grrrr!

Christopher Spears cspears2002 at yahoo.com
Thu Feb 12 19:08:22 EST 2004

I'm writing some code that examines a directory and
creates two lists.  One is a list of all the files in
the directory excluding other directories and links
along with the size of the files.  The result should
look something like this:
[[['openunit4.pyw', 48L], ['printlongestline.pyw',

I have suceeded in making this work.  The next list
should just contain the largest file in the directory
and look like this:

[[huge_file, 247L]]

Here is the code:

def get_size(n,dir):
    import os
    files_size = []
    biggest = []
    files = os.listdir(dir)
    files = filter(lambda x:not os.path.isdir(x) and  
            not os.path.islink(x),files) 

    for f in range(len(files)):
        files_size = files_size +

    for x in range(len(files_size)):
        s = files_size[x][1]
        for b in range(len(files_size)):
            if s > files_size[b][1]:
                biggest = biggest + [files_size[x]]

    print files_size
    print biggest

I think I need some sort of second condition in the if
statement, but I have problems comparing s to
biggest[0][1].  I always get an index out of range

Suggestions, anyone?


More information about the Tutor mailing list