Question: Say there is a folder, '/home/user/temp/a40bd22344'. The name is completely random and changes in every iteration. I need to be able to import this folder in Python using a fixed name, say 'project'. I know I can add this folder to sys.path to enable import lookup, but is there a way to replace 'a40bd22344' with 'project'?

Maybe some clever hacks in **init**.py?

Added: 

It needs to be global - that is, other scripts loading 'project' via the standard:

```
import project

```

Have to work properly, loading a40bd22344 instead.

Answer: 
Here's one way to do it, without touching sys.path, using the `imp` module in Python:

```
import imp

f, filename, desc = imp.find_module('a40bd22344', ['/home/user/temp/'])
project = imp.load_module('a40bd22344', f, filename, desc)

project.some_func()

```

Here is a link to some good documentation on the `imp` module:

* *[imp — Access the import internals](http://docs.python.org/library/imp.html)*
Sure, `project = __import__('a40bd22344')` after `sys.path` is set properly will just work.

Suppose you want to do it in a function taking the full path as an argument and setting the *global* import of `project` properly (as well as magically making `import project` work afterwards in other modules). Piece of cake:

```
def weirdimport(fullpath):
  global project

  import os
  import sys
  sys.path.append(os.path.dirname(fullpath))
  try:
      project = __import__(os.path.basename(fullpath))
      sys.modules['project'] = project
  finally:
      del sys.path[-1]

```

this also leaves sys.path as it found it.