Does sys.modules have any particular order?

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

+3


source to share


2 answers


Sys.modules is dict

; dict

, being hash tables, are of undefined order.

See this question: How to determine if one module was loaded before or after another



UPDATE: As of 3.7 the dictionaries are ordered. From my experiments, the order in which you import things seems to match the order in which they appear in sys.modules.

+4


source


sys.modules is a dictionary, so it is unordered by default. The order in which the modules are printed is random.

in: type(sys.modules)
out: <type 'dict'>

      



Hope it helps!

+1


source







All Articles