Populating Lists in Def using Python

Dipping around in python again and need to create a def that will populate a list(content) with the files that os.walk finds from within this directory and then I will re.search through each files looking for content. In learning Python, can someone point me in the right direction. This is what I have so far.

def list_files ( content=None ):
    if content is None:
        content = []
        for files in os.walk('var/www/html/data/customer/log', topdown=True):
            content.append(files)
            return content

Many thanks in advanced.

Basically os.walk returns a tuple (dirpath, dirnames, filenames). So, if you want the full path of every files, you have to join dirpath and filename:

content = []
for root, dirs, files in os.walk("/tmp", topdown=False):
    for name in files:
        content.append(os.path.join(root, name))

Emanuele

Note: if your directory doesn't have subdirs, you can also use os.listdir.

ok I got my function to work using:

def list_files():
    content = []
    for files in os.walk('var/www/html/data/customer/log'):
       content.extend(files)
    return content

next stupid question is how do I access one of the many files in the function? So the results of os.walk populates my list -- content [] with the files in the directory:

list_files()
print list_files()
['var/www/html/data/customer/log', [], ['file1', 'file2', 'file3', 'file4']]

so how would I access that information so I can add additional logic to my script? when I attempt to access anything in my list, I get the following error

content[3]

NameError: name 'content' is not defined

when not using a function I can access the elements a such:

In [66]: func = []

In [67]: func.extend( ("blah1","blah2" ) )

In [68]: print func
['blah1', 'blah2']
In [69]: print func[0]
blah1

In [70]: print func[1]
blah2

thnx for help