ASPN ActiveState Programmer Network  
ActiveState, a division of Sophos
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups
Submit Recipe
My Recipes

All Recipes
All Cookbooks


View by Category

Title: Unsupported sitecustomize.py sinze Python 2.5
Submitter: Dirk Holtwick (other recipes)
Last Updated: 2008/03/26
Version no: 1.0
Category: System

 

Not Rated yet


Description:

Since Python 2.5 the automatic import of the module "sitecustomize.py" in the directory of the main program is not supported any more (even if the documentation says that it is). Putting this little script named "sitecustomize.py" in the default Python path like in "site-packages" should solve this problem.

Source: Text Source

#!/usr/local/bin/python
# -*- coding: ISO-8859-1 -*-

import sys
import os
sys.path = [os.getcwd()] + sys.path
import sitecustomize
reload(sitecustomize)

Discussion:

Since Python 2.5 the current working directory seems to be added to sys.path somewhere latter after importing the file "site" (see Python documentation for detail). So the "sitecustomize.py" file is just found on the default path. So we add this small file, which adds the current working directory to the sys.path. Then we import sitecustomize again, but this will have no effect because we are already in it. So we reload the module and then it will use the new path to look for sitecustomie. A minor side effect is that sitecustomize will sometimes be loaded twice, but a deadlook seems not to happen.



Add comment

No comments.



Highest rated recipes:

1. A simple XML-RPC server

2. Web service accessible ...

3. Wrapping template engine ...

4. Assignment in expression

5. SOLVING THE METACLASS ...

6. Povray for python

7. Calling Windows API ...

8. Generic filter logic ...

9. Function Decorators by ...

10. MS SQL Server log monitor




Privacy Policy | Email Opt-out | Feedback | Syndication
© 2006 ActiveState Software Inc. All rights reserved.