广告:个人专属 VPN,独立 IP,无限流量,多机房切换,还可以屏蔽广告和恶意软件,每月最低仅 5 美元

org/dev/3.0/library/getopt.html), regular expressions (http://www.diveintopython.org/

regular_expressions/index.html) and so on.

The best way to further explore the standard library is to read Doug Hellmann's excellent Python Module of the Week (http://www.doughellmann.com/projects/PyMOTW/) series.

Summary

We have explored some of the functionality of many modules in the Python Standard

Library. It is highly recommended to browse through the Python Standard Library

documentation (http:/ / docs. python. org/ dev/ 3. 0/ library/ ) to get an idea of all the

modules that are available.

Next, we will cover various aspects of Python that will make our tour of Python more

complete.

Previous Next

Source: http://www.swaroopch.com/mediawiki/index.php?oldid=1156

Contributors: Swaroop, 2 anonymous edits

Python en:More

Introduction

So far we have covered majority of the various aspects of Python that you will use. In this chapter, we will cover some more aspects that will make our knowledge of Python more

well-rounded.

Passing tuples around

Ever wished you could return two different values from a function? You can. All you have to do is use a tuple.

>>> def get_error_details():

... return (2, 'second error details')

...

>>> errnum, errstr = get_error_details()

>>> errnum

2

>>> errstr

'second error details'

Notice that the usage of a, b = <some expression> interprets the result of the expression as a tuple with two values.

If you want to interpret the results as (a, <everything else>), then you just need to star it just like you would in function parameters:

Python en:More

103

>>> a, *b = [1, 2, 3, 4]

>>> a

1

>>> b

[2, 3, 4]

This also means the fastest way to swap two variables in Python is:

>>> a = 5; b = 8

>>> a, b = b, a

>>> a, b

(8, 5)

Special Methods

There are certain methods such as the __init__ and __del__ methods which have special

significance in classes.

Special methods are used to mimic certain behaviors of built-in types. For example, if you want to use the x[key] indexing operation for your class (just like you use it for lists and tuples), then all you have to do is implement the __getitem__() method and your job is done. If you think about it, this is what Python does for the list class itself!

Some useful special methods are listed in the following table. If you want to know about all the special methods, see the manual (http:/ / docs. python. org/ dev/ 3. 0/ reference/

datamodel.html#special-method-names).

Name

Explanation

__init__(self, ...)

This method is called just before the newly created object is returned for usage.

__del__(self)

Called just before the object is destroyed

__str__(self)

Called when we use the print function or when str() is used.

__lt__(self, other)

Called when the less than operator (<) is used. Similarly, there are special methods for all the operators (+, >, etc.)

__getitem__(self, key)

Called when x[key] indexing operation is used.

__len__(self)

Called when the built-in len() function is used for the sequence object.

Single Statement Blocks

We have seen that each block of statements is set apart from the rest by its own indentation level. Well, there is one caveat. If your block of statements contains only one single statement, then you can specify it on the same line of, say, a conditional statement or looping statement. The following example should make this clear:

>>> flag = True

>>> if flag: print 'Yes'

...

Yes

Notice that the single statement is used in-place and not as a separate block. Although, you can use this for making your program smaller, I strongly recommend avoiding this short-cut method, except for error checking, mainly because it will be much easier to add an extra Python en:More

104

statement if you are using proper indentation.

Lambda Forms

A lambda statement is used to create new function objects and then return them at

runtime.

#!/usr/bin/python

# Filename: lambda.py

def make_repeater(n):

return lambda s: s * n

twice = make_repeater(2)

print(twice('word'))

print(twice(5))

Output:

$ python lambda.py

wordword

10

How It Works:

Here, we use a function make_repeater to create new function objects at runtime and

return it. A lambda statement is used to create the function object. Essentially, the lambda takes a parameter followed by a single expression only which becomes the body of the

function and the value of this expression is returned by the new function. Note that even a print statement cannot be used inside a lambda form, only expressions.

TODO

Can we do a list.sort() by providing a compare function created using lambda?

points = [ { 'x' : 2, 'y' : 3 }, { 'x' : 4, 'y' : 1 } ]

# points.sort(lambda a, b : cmp(a['x'], b['x']))

List Comprehension

List comprehensions are used to derive a new list from an existing list. Suppose you have a list of numbers and you want to get a corresponding list with all the numbers multiplied by 2 only when the number itself is greater than 2. List comprehensions are ideal for such situations.

#!/usr/bin/python

# Filename: list_comprehension.py

listone = [2, 3, 4]

listtwo = [2*i for i in listone if i > 2]

print(listtwo)

Output:

Python en:More

105

$ python list_comprehension.py

[6, 8]

How It Works:

Here, we derive a new list by specifying the manipulation to be done (2*i) when some

condition is satisfied (if i > 2). Note that the original list remains unmodified.

The advantage of using list comprehensions is that it reduces the amount of boilerplate code required when we use loops to process each element of a list and store it in a new list.

Receiving Tuples and Lists in Functions

There is a special way of receiving parameters to a function as a tuple or a dictionary using the * or ** prefix respectively. This is useful when taking variable number of arguments in the function.

>>> def powersum(power, *args):

... '''Return the sum of each argument raised to specified power.'''

... total = 0

... for i in args:

... total += pow(i, power)

... return total

...

>>> powersum(2, 3, 4)

25

>>> powersum(2, 10)

100

Because we have a * prefix on the args variable, all extra arguments passed to the

function are stored in args as a tuple. If a ** prefix had been used instead, the extra parameters would be considered to be key/value pairs of a dictionary.

exec and eval

The exec function is used to execute Python statements which are stored in a string or file, as opposed to written in the program itself. For example, we can generate a string

containing Python code at runtime and then execute these statements using the exec

statement:

>>> exec('print("Hello World")')

Hello World

Similarly, the eval function is used to evaluate valid Python expressions which are stored in a string. A simple example is shown below.

>>> eval('2*3')

6

Python en:More

106

The assert statement

The assert statement is used to assert that something is true. For example, if you are very sure that you will have at least one element in a list you are using and want to check this, and raise an error if it is not true, then assert statement is ideal in this situation. When the assert statement fails, an AssertionError is raised.

>>> mylist = ['item']

>>> assert len(mylist) >= 1

>>> mylist.pop()

'item'

>>> mylist

[]

>>> assert len(mylist) >= 1

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

AssertionError

The assert statement should be used judiciously. Most of the time, it is better to catch exceptions, either handle the problem or display an error message to the user and then quit.

The repr function

The repr function is used to obtain a canonical string representation of the object. The interesting part is that you will have eval(repr(object)) == object most of the time.

>>> i = []

>>> i.append('item')

>>> repr(i)

"['item']"

>>> eval(repr(i))

['item']

>>> eval(repr(i)) == i

True

Basically, the repr function is used to obtain a printable representation of the object. You can control what your classes return for the repr function by defining the __repr__

method in your class.

Summary

We have covered some more features of Python in this chapter and yet we haven't covered all the features of Python. However, at this stage, we have covered most of what you are ever going to use in practice. This is sufficient for you to get started with whatever programs you are going to create.

Next, we will discuss how to explore Python further.

Python en:More

107

Previous Next

Source: http://www.swaroopch.com/mediawiki/index.php?oldid=1463

Contributors: Swaroop, 1 anonymous edits

Python en:What Next

If you have read this book thoroughly till now and practiced writing a lot of programs, then you must have become comfortable and familiar with Python. You have probably created

some Python programs to try out stuff and to exercise your Python skills as well. If you have not done it already, you should. The question now is 'What Next?'.

I would suggest that you tackle this problem:

Create your own command-line address-book program using which you can

browse, add, modify, delete or search for your contacts such as friends, family

and colleagues and their information such as email address and/or phone number.

Details must be stored for later retrieval.

This is fairly easy if you think about it in terms of all the various stuff that we have come across till now. If you still want directions on how to proceed, then here's a hint.

Hint (Don't read)

Create a class to represent the person's information. Use a dictionary to store person objects with their name as the key. Use the pickle module to store the objects

persistently on your hard disk. Use the dictionary built-in methods to add, delete and modify the persons.

Once you are able to do this, you can claim to be a Python programmer. Now, immediately send me a mail (http://www.swaroopch.com/contact/) thanking me for this great book ;-)

. This step is optional but recommended. Also, please consider making a donation,

contributing improvements or volunteering translations to support the continued

development of this book.

If you found that program easy, here's another one:

Implement the replace command (http:/ / unixhelp. ed. ac. uk/ CGI/

man-cgi?replace). This command will replace one string with another in the list of

files provided.

The replace command can be as simple or as sophisticated as you wish, from simple string substitution to looking for patterns (regular expressions).

After that, here are some ways to continue your journey with Python:

Python en:What Next

108

Example Code

The best way to learn a programming language is to write a lot of code and read a lot of code:

• The PLEAC project (http://pleac.sourceforge.net/pleac_python/index.html)

• Rosetta code repository (http://www.rosettacode.org/wiki/Category:Python)

• Python examples at java2s (http://www.java2s.com/Code/Python/CatalogPython.htm)

• Python Cookbook (http://code.activestate.com/recipes/langs/python/) is an

extremely valuable collection of recipes or tips on how to solve certain kinds of problems using Python. This is a must-read for every Python user.

Questions and Answers

• Official Python Dos and Don'ts (http://docs.python.org/dev/howto/doanddont.html)

• Official Python FAQ (http://www.python.org/doc/faq/general/)

• Norvig's list of Infrequently Asked Questions (http://norvig.com/python-iaq.html)

• Python Interview Q & A (http://dev.fyicenter.com/Interview-Questions/Python/index.

html)

• StackOverflow questions tagged with python (http://beta.stackoverflow.com/

questions/tagged/python)

Tips and Tricks

• Python Tips & Tricks (http://www.siafoo.net/article/52)

• Advanced Software Carpentry using Python (http://ivory.idyll.org/articles/

advanced-swc/)

• Charming Python (http://gnosis.cx/publish/tech_index_cp.html) is an excellent series

of Python-related articles by David Mertz.

Books, Papers, Tutorials, Videos

The logical next step after this book is to read Mark Pilgrim's awesome Dive Into Python

(http:/ / www. diveintopython. org) book which you can read fully online as well. The Dive

Into Python book explores topics such as regular expressions, XML processing, web

services, unit testing, etc. in detail.

Other useful resources are:

• ShowMeDo videos for Python (http://showmedo.com/videos/python)

• GoogleTechTalks videos on Python (http://youtube.com/

results?search_query=googletechtalks+python)

• Awaretek's comprehensive list of Python tutorials (http://www.awaretek.com/tutorials.

html)

• The Effbot's Python Zone (http://effbot.org/zone/)

• Links at the end of every Python-URL! email (http://groups.google.com/group/comp.

lang.python.announce/t/37de95ef0326293d)

• Python Papers (http://pythonpapers.org)

Python en:What Next

109

Discussion

If you are stuck with a Python problem, and don't know whom to ask, then the

comp.lang.python discussion group (http://groups.google.com/group/comp.lang.python/

topics) is the best place to ask your question.

Make sure you do your homework and have tried solving the problem yourself first.

News

If you want to learn what is the latest in the world of Python, then follow the Official Python Planet (http:/ / planet. python. org) and/or the Unofficial Python Planet (http:/ / www.

planetpython.org).

Installing libraries

There are a huge number of open source libraries at the Python Package Index (http:/ /

pypi.python.org/pypi) which you can use in your own programs.

To install and use these libraries, you can use Philip J. Eby's excellent EasyInstall tool

(http://peak.telecommunity.com/DevCenter/EasyInstall#using-easy-install).

Graphical Software

Suppose you want to create your own graphical programs using Python. This can be done

using a GUI (Graphical User Interface) library with their Python bindings. Bindings are what allow you to write programs in Python and use the libraries which are themselves

written in C or C++ or other languages.

There are lots of choices for GUI using Python:

PyQt

This is the Python binding for the Qt toolkit which is the foundation upon which the

KDE is built. Qt is extremely easy to use and very powerful especially due to the Qt

Designer and the amazing Qt documentation. PyQt is free if you want to create open

source (GPL'ed) software and you need to buy it if you want to create proprietary

closed source software. Starting with Qt 4.5 you can use it to create non-GPL software as well. To get started, read the PyQt tutorial (http://zetcode.com/tutorials/pyqt4/)

or the PyQt book (http://www.qtrac.eu/pyqtbook.html).

PyGTK

This is the Python binding for the GTK+ toolkit which is the foundation upon which

GNOME is built. GTK+ has many quirks in usage but once you become comfortable,

you can create GUI apps fast. The Glade graphical interface designer is indispensable.

The documentation is yet to improve. GTK+ works well on Linux but its port to

Windows is incomplete. You can create both free as well as proprietary software using

GTK+. To get started, read the PyGTK tutorial (http://www.pygtk.org/tutorial.html).

wxPython

This is the Python bindings for the wxWidgets toolkit. wxPython has a learning curve

associated with it. However, it is very portable and runs on Linux, Windows, Mac and

even embedded platforms. There are many IDEs available for wxPython which include

GUI designers as well such as SPE (Stani's Python Editor) (http://spe.pycs.net/) and

Python en:What Next

110

the wxGlade (http:/ / wxglade. sourceforge. net/ ) GUI builder. You can create free as

well as proprietary software using wxPython. To get started, read the wxPython

tutorial (http://zetcode.com/wxpython/).

TkInter

This is one of the oldest GUI toolkits in existence. If you have used IDLE, you have

seen a TkInter program at work. It doesn't have one of the best look & feel because it has an old-school look to it. TkInter is portable and works on both Linux/Unix as well as Windows. Importantly, TkInter is part of the standard Python distribution. To get

started, read the Tkinter tutorial (http:/ / www. pythonware. com/ library/ tkinter/

introduction/).

For more choices, see the GuiProgramming wiki page at the official python website (http://

www.python.org/cgi-bin/moinmoin/GuiProgramming).

Summary of GUI Tools

Unfortunately, there is no one standard GUI tool for Python. I suggest that you choose one of the above tools depending on your situation. The first factor is whether you are willing to pay to use any of the GUI tools. The second factor is whether you want the program to run only on Windows or on Mac and Linux or all of them. The third factor, if Linux is a chosen platform, is whether you are a KDE or GNOME user on Linux.

For a more detailed and comprehensive analysis, see Page 26 of the The Python Papers,

Volume 3, Issue 1 (http://archive.pythonpapers.org/ThePythonPapersVolume3Issue1.pdf).

Various Implementations

There are usually two parts a programming language - the language and the software. A

language is how you write something. The software is what actually runs our programs.

We have been using the CPython software to run our programs. It is referred to as CPython because it is written in the C language and is the Classical Python interpreter.

There are also other software that can run your Python programs:

Jython (http://www.jython.org)

A Python implementation that runs on the Java platform. This means you can use Java

libraries and classes from within Python language and vice-versa.

IronPython (http:/

/

www.

codeplex.

com/

Wiki/

View.

aspx?ProjectName=IronPython)

A Python implementation that runs on the .NET platform. This means you can use

.NET libraries and classes from within Python language and vice-versa.

PyPy (http://codespeak.net/pypy/dist/pypy/doc/home.html)

A Python implementation written in Python! This is a research project to make it fast

and easy to improve the interpreter since the interpreter itself is written in a dynamic language (as opposed to static languages such as C, Java or C# in the above three

implementations)

Stackless Python (http://www.stackless.com)

A Python implementation that is specialized for thread-based performance.

Python en:What Next

111

There are also others such as CLPython (http:/ / common-lisp. net/ project/ clpython/ ) - a

Python implementation written in Common Lisp and IronMonkey (http://wiki.mozilla.org/

Tamarin:IronMonkey) which is a port of IronPython to work on top of a JavaScript interpreter which could mean that you can use Python (instead of JavaScript) to write your web-browser ("Ajax") programs.

Each of these implementations have their specialized areas where they are useful.

Summary

We have now come to the end of this book but, as they say, this is the the beginning of the end!. You are now an avid Python user and you are no doubt ready to solve many problems using Python. You can start automating your computer to do all kinds of previously

unimaginable things or write your own games and much much more. So, get started!

Previous Next

Source: http://www.swaroopch.com/mediawiki/index.php?oldid=1845

Contributors: Swaroop, 2 anonymous edits

Python en:Appendix FLOSS

Free/Libre and Open Source Software (FLOSS)

FLOSS (http:/ / en. wikipedia. org/ wiki/ FLOSS) is based on the concept of a community,

which itself is based on the concept of sharing, and particularly the sharing of knowledge.

FLOSS are free for usage, modification and redistribution.

If you have already read this book, then you are already familiar with FLOSS since you have been using Python all along and Python is an open source software!

Here are some examples of FLOSS to give an idea of the kind of things that community

sharing and building can create:

Linux. This is a FLOSS operating system that the whole world is slowly embracing! It was started by Linus Torvalds as a student. Now, it is giving competition to Microsoft Windows. [ Linux Kernel (http://www.kernel.org) ]

Ubuntu. This is a community-driven distribution, sponsored by Canonical and it is the most popular Linux distribution today. It allows you to install a plethora of FLOSS

available and all this in an easy-to-use and easy-to-install manner. Best of all, you can just reboot your computer and run Linux off the CD! This allows you to completely try out the new OS before installing it on your computer. [ Ubuntu Linux (http://www.ubuntu.

com) ]

OpenOffice.org. This is an excellent office suite with a writer, presentation, spreadsheet and drawing components among other things. It can even open and edit MS

Word and MS PowerPoint files with ease. It runs on almost all platforms. [ OpenOffice

(http://www.openoffice.org) ]

Mozilla Firefox. This is the next generation web browser which is giving great competition to Internet Explorer. It is blazingly fast and has gained critical acclaim for its sensible and impressive features. The extensions concept allows any kind of plugins to be used.

Python en:Appendix FLOSS

112

• Its companion product Thunderbird is an excellent email client that makes reading email a snap. [ Mozilla Firefox (http://www.mozilla.org/products/firefox), Mozilla

Thunderbird (http://www.mozilla.org/products/thunderbird) ]

Mono. This is an open source implementation of the Microsoft .NET platform. It allows

.NET applications to be created and run on Linux, Windows, FreeBSD, Mac OS and many

other platforms as well. [ Mono (http://www.mono-project.com), ECMA (http://www.

ecma-international.org), Microsoft .NET (http://www.microsoft.com/net) ]

Apache web server. This is the popular open source web server. In fact, it is the most popular web server on the planet! It runs nearly more than half of the websites out there.

Yes, that's right - Apache handles more websites than all the competition (including

Microsoft IIS) combined. [ Apache (http://httpd.apache.org) ]

MySQL. This is an extremely popular open source database server. It is most famous for it's blazing speed. It is the M in the famous LAMP stack which runs most of the websites on the internet. [ MySQL (http://www.mysql.com) ]

VLC Player. This is a video player that can play anything from DivX to MP3 to Ogg to VCDs and DVDs to ... who says open source ain't fun? ;-) [ VLC media player (http://

www.videolan.org/vlc/) ]

GeexBox is a Linux distribution that is designed to play movies as soon as you boot up from the CD! [ GeexBox (http://geexbox.org/en/start.html) ]

This list is just intended to give you a brief idea - there are many more excellent FLOSS out there, such as the Perl language, PHP language, Drupal content management system for

websites, PostgreSQL database server, TORCS racing game, KDevelop IDE, Xine - the

movie player, VIM editor, Quanta+ editor, Banshee audio player, GIMP image editing

program, ... This list could go on forever.

To get the latest buzz in the FLOSS world, check out the following websites:

• linux.com (http://www.linux.com)

• LinuxToday (http://www.linuxtoday.com)

• NewsForge (http://www.newsforge.com)

• DistroWatch (http://www.distrowatch.com)

Visit the following websites for more information on FLOSS:

• SourceForge (http://www.sourceforge.net)

• FreshMeat (http://www.freshmeat.net)

So, go ahead and explore the vast, free and open world of FLOSS!

Previous Next

Source: http://www.swaroopch.com/mediawiki/index.php?oldid=1580

Contributors: Swaroop, 1 anonymous edits

Python en:Appendix About

113

Python en:Appendix About

Colophon

Almost all of the software that I have used in the creation of this book are free and open source software.

Birth of the Book

In the first draft of this book, I had used Red Hat 9.0 Linux as the foundation of my setup and in the sixth draft, I used Fedora Core 3 Linux as the basis of my setup.

Initially, I was using KWord to write the book (as explained in the History Lesson in the preface).

Teenage Years

Later, I switched to DocBook XML using Kate but I found it too tedious. So, I switched to OpenOffice which was just excellent with the level of control it provided for formatting as well as the PDF generation, but it produced very sloppy HTML from the document.

Finally, I discovered XEmacs and I rewrote the book from scratch in DocBook XML (again) after I decided that this format was the long term solution.

In the sixth draft, I decided to use Quanta+ to do all the editing. The standard XSL

stylesheets that came with Fedora Core 3 Linux were being used. The standard default

fonts are used as well. The standard fonts are used as well. However, I had written a CSS

document to give color and style to the HTML pages. I had also written a crude lexical analyzer, in Python of course, which automatically provides syntax highlighting to all the program listings.

Now

For this seventh draft, I'm using MediaWiki (http://www.mediawiki.org) as the basis of my

setup (http://www.swaroopch.com/notes/). Now I edit everything online and the readers

can directly read/edit/discuss within the wiki website.

I still use Vim for editing thanks to the ViewSourceWith extension for Firefox (https:/ /

addons.mozilla.org/en-US/firefox/addon/394) that integrates with Vim.

Python en:Appendix About

114

About The Author

http://www.swaroopch.com/about/

Previous Next

Source: http://www.swaroopch.com/mediawiki/index.php?oldid=236

Contributors: Swaroop

Python en:Appendix Revision History

• 1.90

• 04/09/2008 and still in progress

• Revival after a gap of 3.5 years!

• Updating to Python 3.0

• Rewrite using MediaWiki (again)

• 1.20

• 13/01/2005

• Complete rewrite using Quanta+ on FC3 with lot of corrections and updates. Many

new examples. Rewrote my DocBook setup from scratch.

• 1.15

• 28/03/2004

• Minor revisions

• 1.12

• 16/03/2004

• Additions and corrections.

• 1.10

• 09/03/2004

• More typo corrections, thanks to many enthusiastic and helpful readers.

• 1.00

• 08/03/2004

• After tremendous feedback and suggestions from readers, I have made significant

revisions to the content along with typo corrections.

• 0.99

• 22/02/2004

• Added a new chapter on modules. Added details about variable number of arguments

in functions.

• 0.98

• 16/02/2004

• Wrote a Python script and CSS stylesheet to improve XHTML output, including a

crude-yet-functional lexical analyzer for automatic VIM-like syntax highlighting of the program listings.

• 0.97

• 13/02/2004

• Another completely rewritten draft, in DocBook XML (again). Book has improved a lot

- it is more coherent and readable.

Python en:Appendix Revision History

115

• 0.93

• 25/01/2004

• Added IDLE talk and more Windows-specific stuff

• 0.92

• 05/01/2004

• Changes to few examples.

• 0.91

• 30/12/2003

• Corrected typos. Improvised many topics.

• 0.90

• 18/12/2003

• Added 2 more chapters. OpenOffice format with revisions.

• 0.60

• 21/11/2003

• Fully rewritten and expanded.

• 0.20

• 20/11/2003

• Corrected some typos and errors.

• 0.15

• 20/11/2003

• Converted to DocBook XML.

• 0.10

• 14/11/2003

• Initial draft using KWord.

→ Previous → Back to Table of Contents

Source: http://www.swaroopch.com/mediawiki/index.php?oldid=240

Contributors: Swaroop

Python en:Appendix Changes for Python 3000

116

Python en:Appendix Changes for

Python 3000

• Vim and Emacs editors

http://henry.precheur.org/2008/4/18/Indenting%20Python%20with%20VIM.html

http://www.enigmacurry.com/2008/05/09/emacs-as-a-powerful-python-ide/

• String - unicode only

http://docs.python.org/dev/3.0/tutorial/introduction.html#about-unicode

• Non-ASCII identifiers allowed

http://www.python.org/dev/peps/pep-3131/

print() function

http://www.python.org/dev/peps/pep-3105/

raw_input() becomes input()

http://www.python.org/dev/peps/pep-3111/

• Integer Literal Support and Syntax

http://www.python.org/dev/peps/pep-3127/

nonlocal statement

http://www.python.org/dev/peps/pep-3104/

• Functions can take * argument (varargs) for lists and keyword-only arguments

http://www.python.org/dev/peps/pep-3102/

• Functions can have annotations (make a passing note?)

http://www.python.org/dev/peps/pep-3107/

• Better explanation of modules, packages and their organization (including __init__.py, etc.)

http://ivory.idyll.org/articles/advanced-swc/#packages

• String .format() instead of % operator

http://www.python.org/dev/peps/pep-3101/

http://docs.python.org/dev/library/string.html#formatstrings

• Dict method changes

http://www.python.org/dev/peps/pep-3106/

• Built-in set class, in data structures chapter

• Problem Solving

• Use http://gnuwin32.sourceforge.net/packages/zip.htm on Windows

• Classes

http://docs.python.org/dev/3.0/reference/datamodel.html

• Metaclasses

http://www.python.org/dev/peps/pep-3115/

• Abstract Base Classes

http://www.python.org/dev/peps/pep-3119/

• Not sure if any changes required for New I/O

http://www.python.org/dev/peps/pep-3116/

• Exception handling

Python en:Appendix Changes for Python 3000

117

http://www.python.org/dev/peps/pep-0352/

http://www.python.org/dev/peps/pep-3109/

http://www.python.org/dev/peps/pep-3110/

• Standard Library - interesting additions

Reorganization : http://www.python.org/dev/peps/pep-3108/

http://docs.python.org/dev/library/warnings.html

http://docs.python.org/dev/library/logging.html (important)

http://docs.python.org/dev/library/urllib.html

http://docs.python.org/dev/library/json.html

• Debugging

http://docs.python.org/dev/library/pdb.html

http://docs.python.org/dev/3.0/library/trace.html

• eval, repr/ascii functions

• getopt/optparse - how to write a standard command-line program using python?

• something like replace?

http://hpux.connect.org.uk/hppd/hpux/Users/replace-2.24/man.html

• More

• Unpacking can take * argument

http://www.python.org/dev/peps/pep-3132/

with statement

http://www.python.org/dev/peps/pep-0343/

• What Next?

• Implement 'replace'

http://unixhelp.ed.ac.uk/CGI/man-cgi?replace

• Mention use of PyPI

• Q&A

http://docs.python.org/dev/howto/doanddont.html

http://www.python.org/doc/faq/general/

http://norvig.com/python-iaq.html

• Books & Resources

http://www.coderholic.com/free-python-programming-books/

http://pythonpapers.org

http://www.mobilepythonbook.org

http://effbot.org/zone/

• Links at the end of every Python-URL! email

http://groups.google.com/group/comp.lang.python.announce/t/

37de95ef0326293d

• Examples

http://www.rosettacode.org

http://dev.fyicenter.com/Interview-Questions/Python/index.html

http://www.java2s.com/Code/Python/CatalogPython.htm

• Tips & Tricks

http://www.siafoo.net/article/52

Source: http://www.swaroopch.com/mediawiki/index.php?oldid=242

Python en:Appendix Changes for Python 3000

118

Contributors: Swaroop

License

Creative Commons Attribution-Share Alike 3.0 Unported

http://creativecommons.org/licenses/by-sa/3.0/