3

Specifically, are they in order of first imported to last? Or some other order? Undefined order?

asked Jan 1, 2015 at 19:02
2
  • 4
    sys.modules is a dictionary, so has no guaranteed order. Commented Jan 1, 2015 at 19:05
  • This also depends on the import hooks that may be used. Commented Jan 1, 2015 at 19:07

2 Answers 2

4

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
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.