Ryan Forsythe wrote:
> Gary Wessle wrote:
>> Hi
>>
>> I am trying to print out the contents of a directory, sorted.
> ...
>> if I remove ".sort()" at the end of line 6 I get an unsorted list of
>> files, if I leave it I get None. who do I fix this?
>
> `blah.sort()` sorts in-place and returns None
Gary Wessle wrote:
> Hi
>
> I am trying to print out the contents of a directory, sorted.
...
> if I remove ".sort()" at the end of line 6 I get an unsorted list of
> files, if I leave it I get None. who do I fix this?
`blah.sort()` sorts in-place and returns None. You probably want
sorted(blah)
Hi
I am trying to print out the contents of a directory, sorted.
the code
1 import os, sys
2
3 if len(sys.argv) < 2:
4 sys.exit("please enter a suitable directory.")
5
6 print os.listdir(sys.argv[1]).sort()
**