In win32 and linux platform, os modules has diffreent output order, is it a bug?

Benjamin Kaplan benjamin.kaplan at
Fri Mar 1 10:01:12 CET 2013

On Fri, Mar 1, 2013 at 12:43 AM, Honghe Wu <leopardsaga at> wrote:
> env: python 2.7.3
> 6 test files' name in a directory as below:
> 12ab  Abc  Eab  a1bc  acd  bc
> the following is test code:
> for root, dirs, files in os.walk(os.getcwd()):
>     print files
> the output in win32 platform is:
> ['12ab', 'a1bc', 'Abc', 'acd', 'bc', 'Eab']
> but in linux is:
> ['Eab', 'acd', 'a1bc', '12ab', 'bc', 'Abc' ]
> they are so different. a bug?
> --

The function doesn't specify a particular order, just that it will
hand you a list of files. It grabs those from the underlying file
system. It looks like Windows sorts it alphabetically and Linux just
does whatever (maybe sorted by creation time?). I don't think it's a
bug. If the order matters to you, sort it yourself.

More information about the Python-list mailing list