Download ITT751 Advance Internet and Web Programming

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
ITT751 Advance Internet and
Web Programming PYTHON
Presented by:
Saidatul Nurah, Sazimah and Noor Ilyani
1
Introduction to Python
 Python is a dynamic object-oriented programming language that can
be used for many kinds of software development. It offers strong
support for integration with other languages and tools, comes with
extensive standard libraries. Many Python programmers report
substantial productivity gains and feel the language encourages the
development of higher quality, more maintainable code.
 Python runs on Windows, Linux/Unix, Mac OS X, OS/2, Amiga,
Palm Handhelds, and Nokia mobile phones. Python has also been
ported to the Java and .NET virtual machines
 Python is distributed under an OSI-approved open source license
that makes it free to use, even for commercial products
 The Python Software Foundation (PSF) holds and protects the
intellectual property rights behind Python, underwrites the PyCon
conference, and funds grants and other projects in the Python
community
2
About Python
 Python is a remarkably powerful dynamic programming language
that is used in a wide variety of application domains.
 Python is often compared to Tcl, Perl, Ruby, Scheme or Java
 Some of its key distinguishing features include:
 very clear, readable syntax
 strong introspection capabilities
 intuitive object orientation
 natural expression of procedural code
 full modularity, supporting hierarchical packages
 exception-based error handling
 very high level dynamic data types
 extensive standard libraries and third party modules for
virtually every task
 extensions and modules easily written in C, C++ (or Java for
Jython, or .NET languages for IronPython)
 embeddable within applications as a scripting interface
3
About Python (Cont.)
 Python is powerful and fast
Python use the phrase “batteries included” to describe
the standard library, which covers everything from
processing to zip files.
The language itself is a flexible powerhouse that can
handle practically any problem domain.
Build flexible data-driven code using Python's powerful
and dynamic introspection capabilities and advanced
language features.
Can build our own web server and lets you write the
code that you need.
4
About Python (Cont.)
 Python plays well with others
Python can integrate with COM, .NET, and CORBA
objects. Example: For Java libraries, use Jython, an implementation of
Python for the Java Virtual Machine.
 For .NET, try Iron Python , Microsoft's new implementation
of Python for .NET, or Python for .NET
Python is also supported for the Internet
Communications Engine (ICE) and many other
integration technologies
If you find something that Python cannot do or you need
the performance advantage of low-level code, you can
write extension modules in C or C++ or even wrap
existing code with SWIG or Boost Python. Wrapped
modules appear into the program exactly like native
Python code.
5
About Python (Cont.)
Python runs everywhere
Python is available for all major operating
systems: Windows, Linux/Unix, OS/2, Mac,
Amiga, among others.
There are even versions that run on .NET, the
Java virtual machine, and Nokia Series 60 cell
phones.
The same source code will run unchanged
across all implementations.
6
About Python (Cont.)
Python is friendly and easy to learn
The Python newsgroup is known as one of the
friendliest around.
The avid developer and user community
maintains a wiki, hosts international and local
conferences, runs development sprints, and
contributes to online code repositories.
Python also comes with complete
documentation, both integrated into the
language and as separate web pages.
7
About Python (Cont.)
Python is open
The Python implementation is under an open
source license that makes it freely usable and
distributable, even for commercial use.
The Python license is administered by the
Python Software Foundation.
8
History of Python
 Python was first created by Guido von Rossum in 1990 and was
named after the Brit-com Monty Python's Flying Circus. It has since
been developed by a large team of volunteers and is freely available
from the Python Software Foundation. The most recent version of
Python, 2.5.1, was released on 18 April, 2007.
 Python is now found in many incarnations. At the website of the
Python Software Foundation, Python is written in C. Other
incarnations exist. A Java-based version of Python exists in Jython
and may be used to work with Java code natively. Iron Python, a C#
version, exists for the .Net and Mono platforms and allows C#
programmers access to Python's power and flexibility.
 In each of these instances, Python is written in one language and
works natively with that language; however, it also interacts very
well with other languages through its many modules.
9
Getting Started – How to Install?
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.
10
Getting Started – How to Install? (Cont.)
 Downloading Python
 Before you start, you will need Python on your computer, but you
may not need to download it. First of all check (by entering
python in a command line window) that you don't already have
Python installed!
 If you see a response from a Python interpreter it will include a
version number in its initial display. Generally any recent version
will do, as Python makes every attempt to maintain backwards
compatibility.
 If you need to install, you may as well download the most recent
stable version. This is the one with the highest number that isn't
marked as an alpha or beta release. Currently the stable version
is Python 2.5.1.
11
Getting Started – How to Install? (Cont.)
 If you're running Windows: the most stable Windows download is
Python 2.5.1 for Windows.
 If you are using a Mac, MacOS 10.2 (Jaguar), 10.3 (Panther) and
10.4 (Tiger) come with Python already, but you will probably want to
install the latest universal build. For MacOS X 10.3 and later: install
python-2.5.1-macosx.dmg. This is a Universal installer. The
Universal OS X image contains an installer for python 2.5.1 that
works on Mac OS X 10.3.9 and later, on both PPC and Intel Macs.
 For Red Hat, install the python2 and python2-devel packages.
 For Debian or Ubuntu, install the python2.5 and python2.5-dev
packages.
 For Gentoo, install the '=python-2.5*' ebuild (you may have to
unmask it first).
 For Linux, most Linux distributions have Python installed.
12
Python Features
Beginners Guide / overview
Python is a clear and powerful object-oriented
programming language, comparable to Perl,
Ruby, Scheme, or Java.
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
13
Python Features (Cont.)
 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 both 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 14
copyrighted it's available under an open source license.
Python Features (Cont.)
 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 inheritances.
 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.
15
Python Features (Cont.)
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.
16
The Architecture of Python
 Python is a portable, interpreted, interactive, and objectoriented programming language. It is widely used for all
kinds of Internet applications ranging from CGI scripts to
complex servers, including Zope, a very popular, open
source web server. As it is being developed and
maintained with an Open Source development model,
the source code is meant to be self-documenting.




i.
ii.
iii.
iv.
Python - The Language
Python – Architecture Business Cycle
Python – Architectural Structures
Python - Styles
17
The Architecture of Python (Cont.)
 Python - The Language
Python is very expressive and easy to use. It's also considerably more
readable than PERL. One of the best things about Python is that it
allows users to define classes and create objects.
According to Mark Lutz in Learning Python lists the following features
and benefits of Python: Example:Features
Benefits
No compile or link steps
Rapid development cycle turnaround
No type declarations
Simpler, shorter, and more flexible programs
Object-oriented
programming
Code reuse, C++, Java, and COM integration
Simple, clear syntax and
design
Readability, maintainability, ease of learning
18
The Architecture of Python (Cont.)
 Python - Architecture Business Cycle
In Python's architecture business cycle (ABC),
the influences on the architect have evolved
over time, with the biggest change occurring
when the source code was released to the
public making Python open source.
The illustration below shows the various factors
involved in the Python ABC.
19
The Architecture of Python (Cont.)
Python's ABC. (Adapted from ABC diagrams in Software Architecture in
Practice by Bass, et al., 98).
20
The Architecture of Python (Cont.)
Python - Architectural Structures
The term between Python, the language
and Python, the interpreter are the
interpreter is the system being
implemented by a Python developer; the
language is the system being executed or
used by a Python programmer.
21
The Architecture of Python (Cont.)
Architecture Overview of Python
22
The Architecture of Python (Cont.)
File Layout
The following is a description of the physical file layout of Python.
Python has four main folders as depicted in the diagram below.
Python uses the term module to mean extended functionality, but,
by the Python convention, there is always only one file in a module.
1.
2.
3.
4.
The Module folder
The Parser folder
The Objects folder
The Lib folder
23
The Architecture of Python (Cont.)
24
The Architecture of Python (Cont.)
iv.
Python - Architectural Styles
Focus on these factors:-
Layers
■
The Memory Manager
25
The Architecture of Python (Cont.)
 The C/Python Interface
An example of relaxed layering is in the C/Python interface. A C
program can employ three techniques to access Python objects.
The first technique, which is the easiest and provides the highest level
of control, is the use of the Very-High Level Layer (VHLL).
The second technique is the use of concrete or built-in objects. Each
of these objects defines its own type-dependent interface.
The third technique is the use of abstract objects. Example: a C
program
26
The Architecture of Python (Cont.)
Reflection
Python does not implement a pure reflective
architectural pattern. Reflection is evidenced in a
program that is able to change its structure or
behavior at run-time.
■
■
Textbook Reflection
Python Reflection
27
The Architecture of Python (Cont.)
 Batch Sequential
The main interpreter of Python uses a Data Flow Architecture. In
the Python interpreter each component could be a standalone
program. In Python these components are integrated to achieve
better performance, but the underlying theme hasn't changed from
batch-sequential. Each component completes its task prior to the
next one starting and calls the next component with the results of
its transformation on the data.
28
Application Domain
Python is used in many application domains. There are for:
Web and Internet Development
 Python offers a wide range of choices for web development:




Writing basic CGI (Computer Graphic Interface) scripts.
Frameworks such as Django and TurboGears.
High-end solutions such as Zope.
Advanced content management systems such as Plone.
 For custom web solutions and other internet-based applications:
 Extensive support for XML.
 E-mail processing.
 Processing RSS (Really Simple Syndication) feeds. RSS is a family of
web feed formats used to publish frequently updated content such as
blog entries, news headlines or pod casts.
 Support for many other Internet protocols.
29
Application Domain (Cont.)
Database Access
 Custom and ODBC interfaces to MySQL, Oracle, MS SQL Server,
PostgreSQL, SybODBC, and others are available for free download.
 Standard Database API.
 Object databases such as ZODB and Durus.
Desktop GUIs
 The Tk GUI development library is included with most binary
distributions for Python.





wxWidgets
GTK+
Qt
Microsoft Foundation Classes through the win32 extensions
Delphi
30
Application Domain (Cont.)
Scientific and Numeric
Python is widely used in scientific and numeric computing:
Bioinformatics
Python course in Bioinformatics
Physics
Education
Python is a superb language for teaching programming,
both at the introductory level and for more advanced
courses.
Education Special Interest Group is a good place to start.
pyBiblio links to many different resources.
The Software Carpentry Course, funded by the Python
Software Foundation.
31
Application Domain (Cont.)
Network Programming
In addition to the web and internet support described above, Python
also provides support for lower level network programming:
Easy-to-use socket interface.
Twisted Python, a framework for asynchronous network
programming.
Software Development
Python is often used as a support language for software developers, for
build control and management, testing, and in many other ways.
SCons for build control.
Buildbot and Apache Gump for automated continuous compilation
and testing.
Roundup or Trac for bug tracking and project management.
Integrated Development Environments.
32
Application Domain (Cont.)
Game and 3D Graphics
Python is widely used in commercial and hobby game
development:
A partial list of games is on the Python Games Wiki page.
PyGame and PyKyra are two of the game frameworks
available for Python.
List of 3D rendering libraries available for Python.
PyWeek is a semi-annual game programming contest.
33
Advantages of Python
Python is open source
 You can get it for free. Free is not the same as unsupported; in fact,
the Python support community is populated by the best minds in
software today. Commercial software vendors have yet to match the
quality and speed of support offered in the Python community. The
combination of being freely available and also meticulously
supported confers a powerful competitive advantage.
 Furthermore, the open source evolution happened for good reason;
namely, to answer the pressing need for modular, pluggable, highly
communicable software that allows organizations to create solutions
that work. Proprietary technologies, with all due respect for
commercial enterprises, simply did not solve the underlying
problems that businesses face. Solving those problems requires a
set of open standards to encourage software solutions to work well
together in a complete system. Open source software is part of that
solution.
34
Advantages of Python (Cont.)
Python is portable.
 The core Python language runs on any platform: Unix, Windows,
Macintosh, Linux, Amiga, Be-OS, OS/2, VMS, QNX, even MS-DOS. You
can, however, write platform-specific code if your application requires it.
Python has platform-specific extensions (like COM support, for example)
for specialized functionality.
Python is all about speed and productivity.
 This is where Python shines. You simply will not find a language that is
easier to write and read. Moreover, since developers do not need to
spend time compiling or porting to various platforms, development
happens in a fraction of the time.
Python’s speed means you can support your customers better, faster,
cheaper.
 It takes a literal fraction of the time it once did to make bug fixes and
enhancements.
35
Advantages of Python (Cont.)
Python communicates seamlessly with almost anything.
 If you need to tie in something written in another language,
you can do it easily. While Python is excellent for almost any
programming task, you may find some special need that can
be fulfilled in another language. You can avail yourself of all
the advantages of Python programming, and still integrate
special modules written in other tools. In fact, Python excels
at tying disparate components together.
Python is object-oriented.
 It is enough to point out that Python is innately objectoriented. Its class model supports advanced concepts such
as polymorphism, operator overloading, and multiple
inheritance.
36
Disadvantages of Python
 Not terribly fast on computationally intensive operations.
 Language processor cares at a syntactic level, how
many spaces are in a tab.
 There is a limitation to using Python as a client-side
solution for your Web applications: Each client machine
must have Python installed. That's probably the greatest
disadvantage that Python has among the other Active
Scripting languages because Internet Explorer provides
core support for VBScript and JScript.
 Other problems with using Python as a client-side
scripting language include the fact that it is only
supported in Internet Explorer, it only works on Windows,
and it requires that the Python Active Scripting
37
component be installed.
Syntax and Semantics
Python was designed to be a highly
readable language.
Python uses indentation/whitespace,
rather than curly braces or keywords, to
delimit statement blocks.
An increase in indentation comes after
certain statements; a decrease in
indentation signifies the end of the current
block.
38
Syntax and Semantics (Cont.)
Python's statements include:
 The if statement, which conditionally executes a block of
code, along with else and elif (a contraction of else-if).
 The while statement, which runs a block of code until a
condition is False.
 The for statement, which iterates over an iterable,
capturing each element to a local variable for use by the
attached block.
 The class statement, which executes a block of code
and attaches its local namespace to a class, for use in
object oriented programming.
 The def statement, which defines a function.
39
Syntax and Semantics (Cont.)
 Python uses duck typing, also known as latent typing.
Type constraints are not checked at compile time; rather,
operations on an object may fail, signifying that the given
object is not of a suitable type.
 Python includes a number of built-in types used for a
variety of purposes such as, str, unicode, list, tuple, int,
float, complex, bool etc.
 Python also allows programmers to define their own
types. This is in the form of classes, most often used for
an object-oriented style of programming. New instances
of classes are constructed by calling the class (ie, like
FooClass()), and the classes themselves are instances
of class type (itself an instance of itself), allowing
metaprogramming and reflection.
40
Why Using Python?
 Python is over 10 years old, and its development
process is quite mature at this point .
 C programmers will find that the C source code
for the Python interpreter is clearly written and
easy to dive into.
 Programming in Python is much more pleasant
than programming in C, because you get nicely
formatted trace backs instead of nasty core
dumps and protection faults.
 Can be run on any platform (UNIX, Windows or
MacOS).
41
Quotes
 "Python is fast enough for our site and allows us to
produce maintainable features in record times, with a
minimum of developers," said Cuong Do, Software
Architect, YouTube.com.
 "Python has been an important part of Google since the
beginning, and remains so as the system grows and
evolves. Today dozens of Google engineers use Python,
and we're looking for more people with skills in this
language." said Peter Norvig, director of search quality at
Google, Inc.
 "I have the students learn Python in our undergraduate
and graduate Semantic Web courses. Why? Because
basically there's nothing else with the flexibility and as
many web libraries," said Prof. James A. Hendler.
University of Maryland.
42
Conclusion
 Python is a very useful and powerful
programming languages which bring a lot of
benefits in a various fields of business.
 A good language for a beginning programmers.
 It is good to all programmers at least to know
about Python, because Python is used
everywhere in almost all the sectors like Web
Development, Games, Graphics, Financial,
Science, Software Development and Education.
43