Python Forum
import time conflict - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: import time conflict (/thread-5645.html)



import time conflict - Skaperen - Oct-15-2017

module time has a function named time.  some code does import time and calls that function like time.time().  other code does from time import time and calls that function like time().

this can lead to conflicts.

i have a module that needs to call time.sleep().  if i do an import in the module it could change what that code (the code importing my module) has for the (global) variable named time.  is there a nice resolution to this or do i need to do the import of time or time.sleep in the functions that need it?


RE: import time conflict - ichabod801 - Oct-15-2017

This should only be a problem if you import your module using from foo import *, which is why you try to avoid that.


RE: import time conflict - wavic - Oct-15-2017

Well, I don't use from module import *. I could from module import method but only for my own scripts. If I want someone else to use my script/module I will import the module and that's all. Sleep function could be rewritten but time.sleep not. Technically can but no one will do this. I think :D