import os import imp # Initialize variables dirname = 'A-Za-z\xc4\xd6\xdc\xe4\xf6\xfc\xdf' basename = 'mymodule' filepath = os.path.join(dirname, basename + '.py') # Make a new directory with a non-ASCII name os.mkdir(dirname) # Create a new module in that directory with a single line of code in it src_code = "print('imported OK!')\n" f = open(filepath, mode="wt") f.write(src_code) f.close() # Import the newly created module file_object, file_path, description = imp.find_module(basename, [dirname]) mymodule = imp.load_module( basename, file_object, file_path, description )