Specifically, are they in order of first imported to last? Or some other order? Undefined order?
asked Jan 1, 2015 at 19:02
Schilcote
2,4041 gold badge21 silver badges39 bronze badges
2 Answers 2
Sys.modules is a dict; dicts, being hash-tables, have undefined ordering.
See this question: How to determine if one module has been loaded before or after another
EDIT: As of 3.7, dictionaries are ordered. From my experiments, the order in which you import stuff does seem to match the order in which they appear in sys.modules.
answered Jan 1, 2015 at 19:09
Schilcote
2,4041 gold badge21 silver badges39 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
sys.modules is a dictionary, so it is unordered by default. The order in which modules are printed out is random.
in: type(sys.modules)
out: <type 'dict'>
Hope that helps!
Daniel Pryden
61.3k16 gold badges102 silver badges137 bronze badges
answered Jan 1, 2015 at 19:09
Nick Bailey
3,1922 gold badges14 silver badges13 bronze badges
Comments
lang-py
sys.modulesis a dictionary, so has no guaranteed order.