1

Most of Programming Code i saw import keywords are only written in the Header of the file. Is it a good idea to do imports just before using executing Methods from a module?

Example import in Header:

import json

def importCache(): 
    import json
    json.load(open("text.txt"))

Example late import :

def importCache(): 
    import json
    json.load(open("text.txt"))

Is there an optimization process when loading all modules as a bunch?

user1767754
  • 21,126
  • 14
  • 125
  • 152

0 Answers0