Thursday, December 4, 2008

Understanding Python

ABSTRACT

The Python language, while object-oriented, is fundamentally different from both C++ and Java. The dynamic and introspective nature of Python allow for language mechanics unlike that of static languages. This talk aims to enlighten programmers new to Python about these fundamentals, the language mechanics that flow from them and how to effectively put those to use. Among the topics covered are duck-typing, interfaces, descriptors, decorators, metaclasses, reference-counting and the cyclic-garbage collector, the divide between C/C++ data and Python objects and the CPython implementation in general.

This talk is part of the Advanced Topics in Programming Languages series. The goal of this series is to encourage all of the people at Google who know and love programming languages to share their knowledge. If you would like information on upcoming talks, or to schedule a talk of your own, contact information is available on the wiki page:

A Starter Language

Are you a newcomer to programming? Python is an ideal first language. It originated in a 1980s project to design a language for beginners. Its maintainers have always shown a willingness to "do things right." The Python world understands that phrase to mean they make the language logical, simple, and inviting, even at the occasional expense of conflict with industry traditions.

Python insiders don't just talk about "outreach" to non-programmers. The Python community supports an active "Programming for Everybody" Special Interest Group. Python founder Guido van Rossum's current principal project, funded by the Department of Defense's Advanced Research Project Agency, is on the same topic.

The Python features newcomers most applaud include:

*

Its availability: There's no charge for using Python, and essentially identical versions are available for Windows, MacOS, Linux, BeOS, other Unixes, and many other operating systems.
*

Its interactivity: Once installed, a Python user can immediately interpret his work. Type a line of source code, and Python processes it as soon as you hit "Enter." That short feedback loop is especially important for beginning programmers.
*

Its simplicity: Guess what

current = 2000
start = 1990
elapsed = current - start
print elapsed

does. You're right -- and you've just read your first Python program. Python minimizes unpleasant surprises and "trickiness."
*

Its power: Python developers typically report they are able to develop applications in a half to a tenth the amount of time it takes them to do the same work in such languages as C. While "power" and "expressivity" seem to have unquantifiably subjective components, experts generally agree that Python has as much or more of these good things as other languages.

Scalability

Scalability is nerdspeak for "travels well and doesn't let me down." While Python is great for beginners, it also fills the needs of expert users. Other languages popular in educational settings have been scorned by working developers as too slow, incapable of connecting to existing resources, or too inflexible. Few complain about Python in these regards. Python stretches all the way from beginners' one-liners to some of the largest and most demanding computer programs. Python is in use, for example, as part of very complex supercomputer analyses of metal fractures.

We need to be careful about several key concepts in understanding Python's capabilities "on the high end." The metal structure application just mentioned uses Python in crucial ways; in fact, insiders have said that the project simply wouldn't have succeeded without Python. However, most large Python-coded programs, including this one, have a majority of their source written in such other languages as FORTRAN, Java, C, and C++.

Each of these other languages is superior in certain aspects: speed, scientific calculation, graphics manipulation. Each also has characteristic weaknesses. The search for the one true language to use for complex projects is a mistake. The more rational approach is to find the right mix of languages and "glue" them together with Python. You will end up with more efficient, error-free, and maintainable code by using Python to combine the best of each of these.

Because it plays nicely with other languages, Python doesn't create dead-ends. While this idea is hard to make precise, experienced programmers recognize it. Programs begun in Python have good lives; they don't hit limits in speed or algorithmic sophistication which cause them to stagnate. They grow with your needs and your abilities. I almost always feel safe in choosing Python for a project. Even when information turns up during the life of the project that was unknown at the beginning, I have confidence that Python's flexibility will accommodate new needs and constraints.

For technical reasons, also, Python's "object-oriented" syntax has proven to be excellent for teamwork. Experience has shown that engineers working in different areas, and even the same programmers returning to old programs, read unfamiliar Python source code comfortably. This is Python's greatest strength in my own work. As a highly-expressive, object-oriented, well-structured, interoperable language, it promotes the success of large complex projects in a way no other language does.

Wednesday, December 3, 2008

Ajax :Best way to extract data from database in Web Applications

Ajax Best way to extract data from database in Web Applications
Step1. create the ajax.js file with the function called ajax where the ActiveXObject for the diff data can be called

<--!document.write("
");

function Ajax()
{

this.toString = function() { return "Ajax"; }
this.http = new HTTP();

this.makeRequest = function(_method, _url, _callbackMethod)
{
this.request = (window.XMLHttpRequest)? new XMLHttpRequest(): new ActiveXObject("MSXML2.XMLHTTP");
this.request.onreadystatechange = _callbackMethod;
this.request.open(_method, _url, true);
this.request.send(_url);
}

this.checkReadyState = function(_id, _1, _2, _3)
{
switch(this.request.readyState)
{
case 1:
document.getElementById(_id).innerHTML = _1;
break;
case 2:
document.getElementById(_id).innerHTML = _2;
break;
case 3:
document.getElementById(_id).innerHTML = _3;
break;
case 4:
document.getElementById(_id).innerHTML = "";
return this.http.status(this.request.status);
}
}
}

Step2 create the HTTP.js file with the function http along with the error messages and standard methods like this

function HTTP()
{
this.toString = function() { return "HTTP"; }

this.status = function(_status)
{
var s = _status.toString().split("");
switch(s[0])
{
case "1":
return this.getInformationalStatus(_status);
break;
case "2":
return this.getSuccessfulStatus(_status);
break;
case "3":
return this.getRedirectionStatus(_status);
break;
case "4":
return this.getClientErrorStatus(_status);
break;
case "5":
return this.getServerErrorStatus(_status);
break;
}
}

this.getInformationalStatus = function(_status)
{
// Informational 1xx
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.1
switch(_status)
{
case 100:
return "Continue";
break;
case 101:
return "Switching Protocols";
break;
}
}

this.getSuccessfulStatus = function(_status)
{
// Successful 2xx
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2
switch(_status)
{
case 200:
return "OK";
break;
case 201:
return "Created";
break;
case 202:
return "Accepted";
break;
case 203:
return "Non-Authoritative Information";
break;
case 204:
return "No Content";
break;
case 205:
return "Reset Content";
break;
case 206:
return "Partial Content";
break;
}
}

this.getRedirectionStatus = function(_status)
{
// Redirection 3xx
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3
switch(_status)
{
case 300:
return "Multiple Choices";
break;
case 301:
return "Moved Permanently";
break;
case 302:
return "Found";
break;
case 303:
return "See Other";
break;
case 304:
return "Not Modified";
break;
case 305:
return "Use Proxy";
break;
case 306:
return "(Unused)";
break;
case 307:
return "Temporary Redirect";
break;
}
}

this.getClientErrorStatus = function(_status)
{
// Client Error 4xx
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4
switch(_status)
{
case 400:
return "Bad Request";
break;
case 401:
return "Unauthorized";
break;
case 402:
return "Payment Required";
break;
case 403:
return "Forbidden";
break;
case 404:
return "File not found.";
break;
case 405:
return "Method Not Allowed";
break;
case 406:
return "Not Acceptable";
break;
case 407:
return "Proxy Authentication Required";
break;
case 408:
return "Request Timeout";
break;
case 409:
return "Conflict";
break;
case 410:
return "Gone";
break;
case 411:
return "Length Required";
break;
case 412:
return "Precondition Failed";
break;
case 413:
return "Request Entity Too Large";
break;
case 414:
return "Request-URI Too Long";
break;
case 415:
return "Unsupported Media Type";
break;
case 416:
return "Requested Range Not Satisfiable";
break;
case 417:
return "Expectation Failed";
break;
}
}

this.getServerErrorStatus = function(_status)
{
// Server Error 5xx
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5
switch(_status)
{
case 500:
return "Internal Server Error";
break;
case 501:
return "Not Implemented";
break;
case 502:
return "Bad Gateway";
break;
case 503:
return "Service Unavailable";
break;
case 504:
return "Gateway Timeout";
break;
case 505:
return "HTTP Version Not Supported";
break;
}
}
}

Step3 create the response file with respone.js where the ajax response and the request function based on the id which u create in the html templates has to called here

Fro ex. “document.getElementById('resultdiv')” in the following cade is the field id to which u want to call the ajax from the html template
***********************
var ajax = new Ajax();
function onXHTMLResponse()
{
if(ajax.checkReadyState('resultdiv', '', '', '') == "OK")
{

if(ajax.request.responseText!='')
{
//alert(ajax.request.responseText);
var mySplitResult = ajax.request.responseText.split("");
document.getElementById('resultdiv').style.display='';
var spl_res=mySplitResult[0].split("$")
maxval=spl_res[1];
if(mySplitResult[1]!='')
var output=mySplitResult[1];
if(mySplitResult[1]==undefined)
{
var val = document.getElementById('txt_Anredekurzel').value;
document.getElementById('err_txt_Anredekurzel').innerHTML = ""+symbol_title+" "+val+" "+not_exist+"";
//var output="
"+symbol_title+" "+val+" "+not_exist+"
";
}
else
document.getElementById('resultdiv').innerHTML = output;
//document.getElementById('resultdiv').innerHTML =ajax.request.responseText;
//document.getElementById('link1').focus();
//document.getElementById('resdiv1').className='seldiv';
}

}
}



function onXHTMLResponse_info()
{
if(ajax.checkReadyState('resultdiv', '', '', '') == "OK")
{

if(ajax.request.responseText!='')
{
//alert(ajax.request.responseText);
var mySplitResult = ajax.request.responseText.split("");
document.getElementById('resultdiv').style.display='';
var spl_res=mySplitResult[0].split("$");
maxval=spl_res[1];
if(mySplitResult[1]!='')
var output=mySplitResult[1];
if(mySplitResult[1]==undefined)
var output="No Suggestions";

document.getElementById('resultdiv').innerHTML = output;
//document.getElementById('resultdiv').innerHTML =ajax.request.responseText;
//document.getElementById('link1').focus();
//document.getElementById('resdiv1').className='seldiv';
}

}
}


Step5 The code that has to inserted in the htm file is


{lang mkey="credit_card"}





If u have problem with this pls free to concern