importing module with same name as file
Question: I want to import logging <https://docs.python.org/3/library/logging.html> into
a document named logging.py . When I try to import logging.handlers though, it
fails because I believe it's searching the document for a handlers function,
instead of importing from the module. How can I fix this so it will look for
the higher level logging instead of looking inside the file?


Answer: You can do it by removing current directory (first in sys.path) from python
path:

    
    
    import sys
    sys.path = sys.path[1:]
    import logging
    print dir(logging)
    

test:

    
    
    $ python logging.py 
    ['BASIC_FORMAT', 'BufferingFormatter', 'CRITICAL', 'DEBUG', 'ERROR',
     'FATAL', 'FileHandler', 'Filter', 'Filterer', 'Formatter', 'Handler',
     'INFO', 'LogRecord', 'Logger', 'LoggerAdapter', 'Manager', 'NOTSET', 
     'NullHandler', 'PlaceHolder', 'RootLogger', 'StreamHandler', 'WARN',
     'WARNING', '__all__', '__author__', '__builtins__', '__date__',
     '__doc__', '__file__', '__name__', '__package__', '__path__',
     '__status__', '__version__', '_acquireLock', '_addHandlerRef',
     '_checkLevel', '_defaultFormatter', '_handlerList', '_handlers',
     '_levelNames', '_lock', '_loggerClass', '_releaseLock',
     '_removeHandlerRef', '_showwarning', '_srcfile', '_startTime',
     '_unicode', '_warnings_showwarning', 'addLevelName', 'atexit',
     'basicConfig', 'cStringIO', 'captureWarnings', 'codecs', 'critical',
     'currentframe', 'debug', 'disable', 'error', 'exception', 'fatal',
     'getLevelName', 'getLogger', 'getLoggerClass', 'info', 'log',
     'logMultiprocessing', 'logProcesses', 'logThreads', 'makeLogRecord',
     'os', 'raiseExceptions', 'root', 'setLoggerClass', 'shutdown', 'sys',
     'thread', 'threading', 'time', 'traceback', 'warn', 'warning',
     'warnings', 'weakref']
    

