How to check if a python module has been imported?

How do I check if I imported a module somewhere in the code?

     if not has_imported("sys"):
         print 'you have not imported sys'

The reason that i would like to check if i already imported a module is because i have a module that i don't want to import because sometimes it messes up my program.

Test for the module name in the sys.modules dictionary:

    import sys

    modulename = 'datetime'
    if modulename not in sys.modules:
        print 'You have not imported the {} module'.format(modulename)

From the documenation:

This is a dictionary that maps module names to modules which have already been loaded.

From: stackoverflow.com/q/30483246