Getting started Python
What is Python?
Python is a clear and powerful object-oriented programming language, comparable to Perl, Ruby, Scheme, or Java.
- It has been around for over 20years
- Dynamically typed, object-oriented language
- Influenced by ABC, ALGOL 68, C, C++, Dylan, Haskell, Icon, Java,[10] Lisp, Modula-3, Perl
- Runs on Win, Linux/Unix, Mac, OS/2 etc
The core philosophy
The core philosophy of the language is summarized by the document "PEP 20 (The Zen of Python)", which includes aphorisms such as:
- Beautiful is better than ugly
- Explicit is better than implicit
- Simple is better than complex
- Complex is better than complicated
- Readability counts
What can Python do?
- Scripting
- Rapid Prototyping
- Text Processing
- Web applications
- GUI programs
- Game Development
- Database Applications
- System Administrations
- And many more.
Features
Some of Python's notable features:
- Uses an elegant syntax, making the programs you write easier to read.
- Is an easy-to-use language that makes it simple to get your program working. This makes Python ideal for prototype development and other ad-hoc programming tasks, without compromising maintainability.
- Comes with a large standard library that supports many common programming tasks such as connecting to web servers, searching text with regular expressions, reading and modifying files.
- Python's interactive mode makes it easy to test short snippets of code. There's also a bundled development environment called IDLE.
- Is easily extended by adding new modules implemented in a compiled language such as C or C++.
- Can also be embedded into an application to provide a programmable interface.
- Runs on many different computers and operating systems: Windows, MacOS, many brands of Unix, OS/2, ...
- Is free software in two senses. It doesn't cost anything to download or use Python, or to include it in your application. Python can also be freely modified and re-distributed, because while the language is copyrighted it's available under an open source license.
Some programming-language features of Python are:
- A variety of basic data types are available: numbers (floating point, complex, and unlimited-length long integers), strings (both ASCII and Unicode), lists, and dictionaries.
- Python supports object-oriented programming with classes and multiple inheritance.
- Code can be grouped into modules and packages.
- The language supports raising and catching exceptions, resulting in cleaner error handling.
- Data types are strongly and dynamically typed. Mixing incompatible types (e.g. attempting to add a string and a number) causes an exception to be raised, so errors are caught sooner.
- Python contains advanced programming features such as generators and list comprehensions.
- Python's automatic memory management frees you from having to manually allocate and free memory in your code.
See the
Simple Programs collection of short programs, gradually increasing in length, which show off Python's syntax and readability.
Download
Download Python 3.4
Installing
Installing Python is generally easy, and nowadays many Linux and UNIX distributions include a recent Python. Even some Windows computers (notably those from HP) now come with Python already installed.
By default your Python will be installed at location
C:Python34
you can change the drive or the directory as you like.
Configuring Apache web server for Python CGI (Script)
1. Open up Apache config file httpd.conf
2. Look for the following line
AddHandler cgi-script .cgi
3. Add new extension for python support as
AddHandler cgi-script .cgi .py
4. Restart Apache web server.
Run and test your Python script
1. Open up notepad and write the following script.
#!C:/Python34/python
print("Content-Type: text/html
");
print("<h1>Hello World!</h1>");
2. Save it to
wampwwwcgi-bin directory as
wampwwwcgi-bin est.py
3. Run your script with the any browser as follows:
http:localhostcgi-bin est.py
Enjoy!
Comments 2