Daniel Gurianov
Daniel Gurianov

Reputation: 551

python : import some_module through other_module

Why people do

import os
import sys
print sys.version

If they can do

import os
print os.sys.version

Why double-import some basic modules(random, sys ... lot of those ), if you already know that same modules are imported by other modules you are already using? Are such calls somehow deprecated to use in python programming ?

Upvotes: 3

Views: 192

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1125058

Because you should not rely on the implementation details of another module. If the other module stops using sys, then your first module is now broken.

Importing merely creates a reference in the current namespace. You are not loading the module into memory twice when using the import, so importing a module in two different locations doesn't cost you anything.

Upvotes: 11

Related Questions