2

I'm trying to iterate over files in a directory using the following command in python 3.6:

for filename in os.listdir(my_dir)

My files are numbered incrementally, like out1, out2, ...,out10, out11, .... Unfortunately, iteration over the files using the above command results in out1, out10, out11 instead of out1, out2, out3, .... It might be correct from file system point of view, but semantically wrong.

How can we get the right output?

Tina J
  • 4,983
  • 13
  • 59
  • 125
  • @EugenePrimako I don't think this question is a duplicate of that but it definitely could help from the solutions of that answer. Maybe I misunderstand the use of duplicate on this site? – Cole Jul 05 '18 at 20:29
  • The questions are different. The other question is describing a slightly different sorting. – Tina J Jul 05 '18 at 20:31
  • @TinaJ: no, it does not. Applying the code in the answers *will* show your required result. – Jongware Jul 05 '18 at 20:36
  • @TinaJ I can't see the difference. Could you be specific? – Patrick Haugh Jul 05 '18 at 20:37
  • @Cole I got some insights from the other question and resolved the issue. Thanks. – Tina J Jul 05 '18 at 20:42

0 Answers0