Sorting a list
Aaron Ginn
aaron.ginn at motorola.com
Fri Jun 2 13:34:48 EDT 2000
I'm a python newbie, so please be kind! :)
I'm trying to sort a list. Fairly simple, but I'm not getting
at all what I expect. When I attempt to sort the list, the
return value is None, and I can't understand why at all.
Here's my code:
def get_files_in_directory( dir ):
# Returns a list of files in a directory.
print os.listdir(dir).sort()
print os.listdir(dir)
return os.listdir(dir).sort()
The directory 'dir' does exist. From the docs, os.listdir() should
return a list of files in a directory, and sort() should sort
them, but here's the output from the two print statements:
None
['tsmc18_5lm.03.drc', 'tsmc18_5lm.04.drc', 'tsmc18_5lm.05.drc',
'tsmc18_5lm.06.drc', 'tsmc18_5lm.07.drc', 'tsmc18_5lm.08.drc',
'tsmc18_5lm.10.drc', 'tsmc18_5lm.01.drc', 'tsmc18_5lm.02.drc',
'tsmc18_5lm.09.drc']
Why is sort returning an empty list?
Thanks,
Aaron
--
Aaron J. Ginn
Opinions mine, not Motorola's
More information about the Python-list
mailing list