8

Just wondering if importing more functions from other scripts slows down a script in general?

Some background:

I have two scripts, one that runs much faster than the other, one has an extra import statement at the top and extra function at the bottom, but its the stuff in the middle, thats the same between scripts that is running slower.

user124123
  • 1,482
  • 4
  • 28
  • 50

1 Answers1

13

More information about your case, Import_Statement_Overhead:

Import statements can be executed just about anywhere. It's often useful to place them inside functions to restrict their visibility and/or reduce initial startup time. Although Python's interpreter is optimized to not import the same module multiple times, repeatedly executing an import statement can seriously affect performance in some circumstances.

Hooked
  • 77,871
  • 38
  • 181
  • 253
badc0re
  • 3,003
  • 4
  • 29
  • 45
  • 3
    I hope you don't mind, I've edited your answer to include the relevant information from your link. A single link tells us _nothing_, and who knows if it will be here tomorrow? – Hooked Aug 27 '13 at 13:33
  • 1
    Yes thank you, i will put more info when i am sharing links next time. – badc0re Aug 27 '13 at 13:34
  • 2
    Your answer was correct (+1), but it might help to look over http://meta.stackoverflow.com/help/how-to-answer for next time. – Hooked Aug 27 '13 at 13:38