» May 8th, 2009, category: Django, Python , Perm Link...

The Battery Included Programming Language

Python is battery included programming language. It means, Python itself has a set of standard library. Enhancement or additional library is allow when there is no such library available in Python or you need improve version.

Python Module

Python module is container for Python code. We can include Python class, function, declaration and pack into the directory. Inside directory, we have an empty Python file names init.py to tell Python interpreter that this directory is python module and can be use import statement to load the module into the interpreter environment.

Python Path

Python path is a the directory path where Python loads the Python module. There is default path so that Python interpreter, when launch, will have a standard library and site-package library available for you. The current directory where we run the Python interpreter is always added in to Python path. The function sys.path contains all Python path.

Development against multiple version Python module

In real life, when developer release the software. There always has a set of version you can use. Some can use with your environment or code base, some can't.This will lead the problem of multiple Python library version in the environment.

Using custom Python path to store the custom Python library

For my solution, I have my own lib directory locate inside of my Python's project. I install my custom Python library version in that and use the concept of module load ordering in case of there are multiple module name available because Python will the first module from the list of the path in sys.apth

Multiple Django Version in development environment

There will have a lot of the time you will need to switch over Django version. For me, I always try to use the trunk version. For my company, we need to use the release version.

The idea is, put (or symbolic link) the Django version you want to develop against in the lib library and have a code that load the django form that location instead of at site-packages. We need to do switching at the beginning point of execution. For development environment, the manage.py is the the first code to be executed so I place the path switching in the it. see code below,

#!/usr/bin/env python

import sys
import os

DIR = os.path.dirname(__file__)
LIB_DIR = os.path.join(DIR, 'lib')

sys.path.insert(0,LIB_DIR)

from django.core.management import execute_manager
try:
    import settings # Assumed to be in the same directory.
except ImportError:
    import sys
    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
    sys.exit(1)

if __name__ == "__main__":
    execute_manager(settings)

Multiple Django Version in WSGI environment

For WSGI, the first execution is at the wsgi handler, for me I have wsgi_handler.py like this,

import sys
import os

DIR = os.path.dirname(__file__)
PROJECT_DIR = os.path.join(DIR, '..')
LIB_DIR = os.path.join(DIR, 'lib')

sys.path.append(DIR)
sys.path.append(PROJECT_DIR)
sys.path.insert(0,LIB_DIR)

os.environ['DJANGO_SETTINGS_MODULE'] = 'm.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

That 's all. Happy coding :)

Comments

# Kasinos deutsch Jul 3rd, 2009

Here, you tell the war command that it should include an extra java library to the generated WAR file, because it can't know which java libraries are you using inside your project. In the typical cases, you must at least specify the JDBC driver you are using to connect to the database, which will depend on the configured database backend.

# Bonus dei giochi del casinĂ² Oct 24th, 2009

i really appreciate your work to this site.So thanks for it.keep on doing this kind of good work further also.

# alternative medicines Dec 20th, 2009

Can i know more about battery programming language

# ppo plans Jan 26th, 2010

nice information...thanks! Python run on Windows, Linux/Unix, Mac OS X, and has been ported to the Java and .NET virtual machines.

Post your comment.

captcha