3

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 ?

asked Sep 10, 2013 at 15:07

1 Answer 1

11

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.

answered Sep 10, 2013 at 15:09
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Martijn. I `ve missed the fact, that other_module import code can be changed without my knowledge and it will break my some_module code respectively.

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.