Reputation: 5561
I need to import a function from a file which is in a folder whose name contains a special character, with the file itself also containing a special character. I cannot change the names to correct the issue. How does one perform the importation in such a situation?
Upvotes: 7
Views: 8705
Reputation: 208545
Yeah that is some horrible naming, but this should work for you:
Instrument_Control = __import__("Instrument-Control.audio$pecial")
audiospecial = getattr(Instrument_Control, "audio$pecial")
print audiospecial
# <module 'Instrument-Control.audio$pecial' from 'Instrument-Control/audio$pecial/__init__.py'>
audiospecial.example_func() # executes example_func() from audio$pecial
Upvotes: 7