user6037143
user6037143

Reputation: 566

Calling a standard library from imported module

Is it a good idea to use a standard library function from an imported module? For example, I write a xyz.py module and within xyz.py, I've this statetment import json

I have another script where I import xyz. In this script I need to make use of json functions. I can for sure import json in my script but json lib was already imported when I import xyz. So can I use xyz.json() or is it a bad practice?

Upvotes: 0

Views: 71

Answers (1)

Dewald Abrie
Dewald Abrie

Reputation: 1482

You should use import json again to explicitly declare the dependency. Python will optimize the way it loads the modules so you don't have to be concerned with inefficiency.

If you later don't need xyz.py anymore and you drop that import, then you still want import json to be there without having to re-analyze your dependencies.

Upvotes: 2

Related Questions