Tải bản đầy đủ (.ppt) (94 trang)

python and xml

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (247.86 KB, 94 trang )

Copyright 2001,
ActiveState
Python and XML
Copyright 2001,
ActiveState
About me

Paul Prescod, ()

ActiveState Senior Developer

Co-Author, XML Handbook
Copyright 2001,
ActiveState
Preview

About Python

Python SAX/DOM

PyXML Package

Python XSLT/XPath

Python SOAP/XML-RPC

XML and Zope
Copyright 2001,
ActiveState
What is Python?


Python is an easy to learn, powerful
programming language.

Efficient high-level data structures

Simple approach to object-oriented
programming.

Elegant syntax and dynamic typing
Copyright 2001,
ActiveState
Brief History of Python

CWI, early 90s.

Dynamic Object Oriented High Level
Language.

More than a text processing language.

More than a scripting language.

Scalable and object oriented from the
beginning.

Dynamically type checked.
Copyright 2001,
ActiveState
Python's business case


Python can displace many other
languages in the organization.

The Python interpreter is free.

Python is legally unencumbered.

Professional programmers find Python
more flexible than most languages.

Amateur programmers are (often) more
comfortable than with Perl or Java.
Copyright 2001,
ActiveState
Usability features

Exceptionally clear syntax.

Provides an obvious way to do most
things.

Small set of features combine in
powerful ways.

Only innovative where innovation is
really necessary.
Copyright 2001,
ActiveState
More Usability features


Huge amount of free code and libraries

Interactive.

Designed to talk to the world.

Runs with Unix, Mac and Windows.

Integrates with JVM (Jython) and .NET
Framework (Python.NET)

Talks MS COM, XPCOM,
CORBA,SOAP, XML-RPC, …
Copyright 2001,
ActiveState
Scalability features

Simple but powerful module system.

Simple but powerful class system.

Structured, standardized exceptions.
Copyright 2001,
ActiveState
Environments

Unix (almost all)

Windows (3.1, 95, NT, CE)


Mac

JVM

Various legacy systems
Copyright 2001,
ActiveState
Extendable

New data types in Python or C

Modules in Python or C

Functions in Python or C
Copyright 2001,
ActiveState
Python isn't picky!

COM/CORBA

HTML/XML/SGML

Win API/POSIX

You can write code that is portable or
platform-specific.
Copyright 2001,
ActiveState
Compared to Perl


Simpler syntactically.

More object oriented.

Easier to extend.

But slower regular expressions
Copyright 2001,
ActiveState
Compared to Java

Java is more difficult for amateur
programmers.

Static type checking can be
inconvenient in text processing.

Puritanical OO can be inconvenient.

Bottom line: Java can make simple
projects harder.
Copyright 2001,
ActiveState
Why not Java: political

"100% pure Java" gets in the way.

The Java environment punishes
interoperability. (e.g. getenv is
deprecated)


Java is designed to have interoperability
limitations.

Embedding Java is relatively painful.
Copyright 2001,
ActiveState
Jython (nee JPython)

Compiles Python classes to Java
classes

Embedded interpreter allows interactive
coding.

Access to all Java classes.

For better or worse: maintains Java's
security/platform-independence bubble.
Copyright 2001,
ActiveState
Jython can use Java tools

RDF

XPointer

Various parsers

Swing GUI


Unicode
Copyright 2001,
ActiveState
Python Limitations

“Ordinary Python" has 8-bit and Unicode
string types.

Handling explicit conversions can be annoying.

Not as fast as C++.

Raw text searching is not as fast as Perl.

Dynamic type checking requires more care in
testing.
Copyright 2001,
ActiveState
Python “Hello world"
print "Hello, World“
Copyright 2001,
ActiveState
Python interpreter

Just type:
C:\> python
Python 1.5.2 (#0, Apr 13 1999, 10:51:12)
[MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch

Centrum, Amsterdam
>>> print "Hello, World"
Hello, Python
>>> print "Goodbye, World "
Goodbye, Python
>>> ^Z
C:\>
Copyright 2001,
ActiveState
Byte-compiling

Python automatically bytecompiles
modules.

Next execution does not require
compilation.

.py files get a .pyc in the same directory

When the .py is updated, the .pyc is
updated
Copyright 2001,
ActiveState
Interpreters

DOS/Win32 (last slide)

Unix (use ^D to exit)

Graphical: “IDLE”, “PythonWin”

Copyright 2001,
ActiveState
Python variables

Any Python variable can hold any value.
>>> width = 20
>>> height = 5 * 9
>>> width * height
900
>>> width = "really wide“
>>> width
'really wide'
Copyright 2001,
ActiveState
Numeric types

int: 32 bit, e.g. "x=5"

long: arbitrary sized, e.g. "x=2L**128"

float: accuracy depends on platform,
e.g. "x=3.14"

complex: real+imag., "x=5.3+3.2j"
Copyright 2001,
ActiveState
Sequence types:

Strings: "abcd"


Tuples: (1,2,"b")

Lists: [1,"a",3]

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×