Python – How to Import a Module With Spaces in Its Name

Let’s say I have a module named “Excellent Module.py”

How would I import that into a script since:

import Excellent Module

doesn’t work?

Answer, use:

ExcellentModule = __import__('Excellent Module')

Thanks Farshid.

2 Responses to “Python – How to Import a Module With Spaces in Its Name”

  1. Bob Ippolito says:

    The real answer is: don’t create modules with spaces in their name.

    __import__ doesn’t do what you’d expect for packages.

  2. Yes, yes, Bob. I meant to say “assuming you have a really good reason for having spaces in the name”. ;-)