Aug-24-2022, 06:29 AM
Hi,
Just a thought, not a problem:
Say I have a prog that starts with 12 imports like shutil, datetime, warnings, pandas, a class of my own...etc
Some of these imports are only needed once:
eg. pandas is only used to read the contents of a spreadsheet right at the start, then no more.
Question1: is it good practice (from a memory point of view or ...) to do the import inside the def ...() where it is needed?
Question2: with question1 in mind, could there be a different answer idepending on what import it is.
Maybe pandas yes but math no, because it is already part of python.
?
Or is this much ado about nothing.
thx,
Paul
Just a thought, not a problem:
Say I have a prog that starts with 12 imports like shutil, datetime, warnings, pandas, a class of my own...etc
Some of these imports are only needed once:
eg. pandas is only used to read the contents of a spreadsheet right at the start, then no more.
Question1: is it good practice (from a memory point of view or ...) to do the import inside the def ...() where it is needed?
Question2: with question1 in mind, could there be a different answer idepending on what import it is.
Maybe pandas yes but math no, because it is already part of python.
?
Or is this much ado about nothing.
thx,
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.