Sinisterly
unused imports - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Python (https://sinister.li/Forum-Python)
+--- Thread: unused imports (/Thread-unused-imports)



unused imports - J4W3S - 03-31-2013

So i'm making a random encounter generator for a game i am making (isn't a good game just so i can learn python). But anyway i have a lot of unused imports for some reason does this effect performance at all?

here is the code if it helps
Code:
import random number = random.randint(1,10) if number == 1: from encounters import _1 elif number == 2: from encounters import _2 elif number == 3: from encounters import _3 elif number == 4: from encounters import _4 elif number == 5: from encounters import _5 elif number == 6: from encounters import _6 elif number == 7: from encounters import _7 elif number == 8: from encounters import _8 elif number == 9: from encounters import _9 elif number == 10: from encounters import _10
All of the imports from encounters are showing as unused, i'm not sure if this is just because they are in an if statement.


unused imports - J4W3S - 03-31-2013

So i'm making a random encounter generator for a game i am making (isn't a good game just so i can learn python). But anyway i have a lot of unused imports for some reason does this effect performance at all?

here is the code if it helps
Code:
import random number = random.randint(1,10) if number == 1: from encounters import _1 elif number == 2: from encounters import _2 elif number == 3: from encounters import _3 elif number == 4: from encounters import _4 elif number == 5: from encounters import _5 elif number == 6: from encounters import _6 elif number == 7: from encounters import _7 elif number == 8: from encounters import _8 elif number == 9: from encounters import _9 elif number == 10: from encounters import _10
All of the imports from encounters are showing as unused, i'm not sure if this is just because they are in an if statement.


RE: unused imports - ArkPhaze - 03-31-2013

Quick answer: No. And the way you have it is actually better for performance. If you had them all at the very top, importing is quick, but it is not without expense. Here you would be importing individually, instead of all at once. It would be like going to a store and just buying all the ingredients you think you might need, instead of making sure that you only grab what you need... Which would be more expensive?


RE: unused imports - ArkPhaze - 03-31-2013

Quick answer: No. And the way you have it is actually better for performance. If you had them all at the very top, importing is quick, but it is not without expense. Here you would be importing individually, instead of all at once. It would be like going to a store and just buying all the ingredients you think you might need, instead of making sure that you only grab what you need... Which would be more expensive?


RE: unused imports - J4W3S - 03-31-2013

oh ok thanks Smile. I didn't think it would effect performance it's i just wanted to make sure because of all the warnings.


RE: unused imports - J4W3S - 03-31-2013

oh ok thanks Smile. I didn't think it would effect performance it's i just wanted to make sure because of all the warnings.


RE: unused imports - ArkPhaze - 03-31-2013

They can be ignored if you are getting warnings here, because you don't want to use them all I'm assuming.


RE: unused imports - ArkPhaze - 03-31-2013

They can be ignored if you are getting warnings here, because you don't want to use them all I'm assuming.