Python Introduction Python is an interpreted, object-oriented, high level scripting and programming language. Python was first introduced in 1991 by Guido van Rossum, a Dutch computer programmer who wanted to develop a language that could be used by anyone. The main goal of Python was to reduce the learning curve by choosing a syntax that is understandable as plain English. Python has a very simple programming philosophy, “there should be one and preferably only one obvious way to do it”. This is a characteristic that sets Python apart from its competitors such as Perl.
Python rejects exuberant syntax and favors sparse, less cluttered syntax. Perl on the other hand sees programming as, “there is more than one way to do it”. This is evident in Perl’s regular expressions. The numerous backslashes, quotations and variable notations can give a novice programmer a headache. Perl is still considered a powerful language; however, the syntax can be cryptic and hard to read. Python is a multi-paradigm programming language, which allows users to code in several different programming styles.
A programmer can code in a functional, objectoriented or imperative format. Python supports cross platform development and is available through open source and the latest stable release is version 2. 5. 1. Uses for Python Python is an excellent answer to all those who cried out for a more modern version of Perl. After being introduced to Perl, the advantages become quite obvious; that being it is easy to code a small program in a short amount of time. After working with a Perl application for sometime though, like any other language, it starts to look cryptic and sloppy.
Even worse, just like any command line tool a user needs to first understand which arguments need to be set for the program to run, and then know how to present them syntactically. A first view of a Python program shows a language that is not only readable, but read like English. It is easy to see quite quickly that advanced users would not only be able to pick it up quickly, but even those with little to no programming experience could as well. The second great feature of Python besides readability is the integration. Inevitably with any scripting language, complex operations might have to be made.
Python’s answer to this is its ease as an integration tool. The use of Python with SWIG is already of frequent use in the gaming industry. Starting from the second version of Sid Meier’s Civilization series, Python has been used for scripting in game menu’s effectively. In addition, the building of levels is often used by gaming companies since it is far cleaner to hard code level design as a series of scripts separate from program code. This has also allowed for avid users of these games to write their own Python code to create level esigns of their own. The most recent installment of Civilization has API for creating new scripts online. This creates further replay value for their customers. Another great use of the integration functionality is it allows companies who have grown tired of dealing with legacy code to be able to choose new programming languages without having to throw away old, still functioning code. With easy to read scripts, it allows for new programmers, coming on board, to not have to read through thousands of lines of code to get up to speed.
This means the learning curve for legacy systems is less steep, and there is less reliance on having to pore over documents to understand code. This works great for updating user interface’s for new versions of products without touching back-end code. The two main flavors of integration for Python is the C/C++ version dubbed CPython, and the pure integration language JPython or renamed Jython more recently. CPython does not actually act as a pure integration language. CPython must by integrated using a tool such as SWIG. Python allows ease of use of complicated C/C++ functions that are still useful.
Well documented functions could be easily called from Python and the results could be manipulated and presented within the script. Jython is a purely integrated language where you can interchangeably use Java and Python code inline in the program. This allows even more readable code by doing basic overhead operations in Python code, but using Java code when more detail and control is needed. With a combination of readability and an ability to integrate between languages, it is easy to see that in addition to scripting, Python would function as an excellent CGI.
With the use of back end functionality being accomplished in C/C++ code, a developer can maintain readability while performing complex operations at the same time. This also forces a user to keep user-interface processing and business logic distinctly separate, and allows the user-interface potion of the program to remain more flexible, since it is often the UI that will need to be updated over time rather then core application functionalities. Python makes an excellent language for use in web development.
Advantages/Disadvantages of Python Python is a language built to exploit the advantages and circumvent the disadvantages of several programming languages. In order to cerate a language that developers would be pleased with Python designers implemented popular features from the most popular programming languages. Some of the advantages Python is well known for include: ease of learning, portability, dynamic typing and integration with other languages. Python does not use any syntax whatsoever, instead tabbing and spacing play an important role in program flow.
With the absence of syntax; developers wishing to use Python need not learn any new rules. Because developers need only understand the functionality of Python to use it, it is estimated that the development process proceeds 5 to 10 times faster then in other languages such as Java or C/C++. Rapid development allows Python to be used extensively in throw-away prototyping. Python is also very robust because of its lack of syntax. Users with little to no experience with Python can quickly determine program functionality and begin re-factoring code for upgrades or bug fixes.
With the capabilities of running on most operating system platforms from Windows to Linux to OS X, Python is a language with very few boundaries. A program written in Python, for one platform, using only the standard libraries can easily be ported to another operating system without need for recompiling or repackaging. Python is even capable of operating on several types of Nokia cell phones. Python does not enforce a strict type on containers or variables. With this concept, developers can design a container to hold different types of data (integer, string, float etc. A single container for different data types means less memory is used to create distinct containers for different data types. Along with less memory usage, the user can implement the same functions on different data types rather then defining a distinct function for each type. Since Python implements the advantageous aspects of several languages it is only natural that it be able to interact with those languages. The integration of Python with languages such as Java and C/C++ allows Python to remove some stress from the interpreter.
Functions can be written in another language and compiled so that at runtime they do not need to be interpreted which leads to a quicker and smoother running program. Although Python is a very advantageous language it does have some downfalls. One of the main disadvantages of Python is that it is an interpreted language. Most of the other disadvantages of Python deal with the personal preferences of developers. The disadvantages of Python include: language translation, documentation and the use of modules.
Rather then compiling a Python program and then running it, the program is interpreted at runtime. Languages such as Java or C/C++ have overhead before the program begins execution so that programs run much quicker, with a Python program the interpreter reads the code and determines what to do while the program is executing. Python adds the overhead on interpretation to the runtime of the program which can lead to a slower runtime. It is estimated that Python runs 1-5 times slower then Java or C/C++.
Because of its lack of syntax Python is an easy language to program in; however it is not very simple to translate a Python program into any other language. The translation from Python to another language would require the user to carefully examine the structure of the code and make sure to implement the same structure using the syntax of the new programming language. Python is a constantly evolving language and thus has a module to integrate it with almost every new technology. With a constant evolution there is very little concrete documentation for Python.
The official Python documentation consists of two printed books as well as a tutorial and library reference present in each release. Although there is very little official documentation the documentation that does exist is of excellent quality. Python is a very powerful language. Developers are constantly designing new modules so that Python can use the latest and greatest technologies. A major disadvantage with these new modules is that if a developer would like to make use of the technology of a certain module, the module must be imported into the project.
The modules are not always part of the standard release or the standard library of Python. Python Examples Python is not widely used for the front-end of applications, but a simple shopping cart example was created to demonstrate Python’s front-end capabilities. This simple example illustrates several important aspects to Python. The entire stand-alone application is contained in a file that is only 60 lines long including empty new-lines for readability. Also the emonstration gives an opportunity to illustrate that indenting in Python source code is taken into consideration by the interpreter. What is meant by this is that if single space is added before one line of code in a series of lines, it will report an error. Enforcing the look of the code and the succinct way in which it is written are both key features of Python. Because CMPUT 410 is a web application course, it would be appropriate to find a Python example that could be applied to concepts covered in class.