Learning Python

( 19 )

Overview

Get a comprehensive, in-depth introduction to the core Python language with this hands-on book. Based on author Mark Lutz’s popular training course, this updated fifth edition will help you quickly write efficient, high-quality code with Python. It’s an ideal way to begin, whether you’re new to programming or a professional developer versed in other languages.

Complete with quizzes, exercises, and helpful illustrations, this easy-to-follow, self-paced tutorial gets you started ...

See more details below
Paperback (Fifth Edition)
$41.30
BN.com price
(Save 36%)$64.99 List Price

Pick Up In Store

Reserve and pick up in 60 minutes at your local store

Other sellers (Paperback)
  • All (14) from $34.25   
  • New (9) from $41.13   
  • Used (5) from $34.25   
Learning Python

Available on NOOK devices and apps  
  • NOOK Devices
  • Samsung Galaxy Tab 4 NOOK 7.0
  • Samsung Galaxy Tab 4 NOOK 10.1
  • NOOK HD Tablet
  • NOOK HD+ Tablet
  • NOOK eReaders
  • NOOK Color
  • NOOK Tablet
  • Tablet/Phone
  • NOOK for Windows 8 Tablet
  • NOOK for iOS
  • NOOK for Android
  • NOOK Kids for iPad
  • PC/Mac
  • NOOK for Windows 8
  • NOOK for PC
  • NOOK for Mac
  • NOOK for Web

Want a NOOK? Explore Now

NOOK Book (eBook)
$27.49
BN.com price
(Save 42%)$47.99 List Price

Overview

Get a comprehensive, in-depth introduction to the core Python language with this hands-on book. Based on author Mark Lutz’s popular training course, this updated fifth edition will help you quickly write efficient, high-quality code with Python. It’s an ideal way to begin, whether you’re new to programming or a professional developer versed in other languages.

Complete with quizzes, exercises, and helpful illustrations, this easy-to-follow, self-paced tutorial gets you started with both Python 2.7 and 3.3— the latest releases in the 3.X and 2.X lines—plus all other releases in common use today. You’ll also learn some advanced language features that recently have become more common in Python code.

  • Explore Python’s major built-in object types such as numbers, lists, and dictionaries
  • Create and process objects with Python statements, and learn Python’s general syntax model
  • Use functions to avoid code redundancy and package code for reuse
  • Organize statements, functions, and other tools into larger components with modules
  • Dive into classes: Python’s object-oriented programming tool for structuring code
  • Write large programs with Python’s exception-handling model and development tools
  • Learn advanced Python tools, including decorators, descriptors, metaclasses, and Unicode processing
Read More Show Less

Product Details

  • ISBN-13: 9781449355739
  • Publisher: O'Reilly Media, Incorporated
  • Publication date: 7/3/2013
  • Edition description: Fifth Edition
  • Edition number: 5
  • Pages: 1540
  • Sales rank: 53,328
  • Product dimensions: 7.00 (w) x 9.20 (h) x 2.80 (d)

Meet the Author

Mark Lutz is a leading Python trainer, the author of Python’s earliest and best-selling texts, and a pioneering figure in the Python world.

Mark is the author of the three O’Reilly books: Learning Python, Programming Python, and Python Pocket Reference, all currently in fourth or fifth editions. He has been using and promoting Python since 1992, started writing Python books in 1995, and began teaching Python classes in 1997. As of Spring 2013, Mark has instructed 260 Python training sessions, taught roughly 4,000 students in live classes, and written Python books that have sold 400,000 units and been translated to at least a dozen languages.

Together, his two decades of Python efforts have helped to establish it as one of the most widely used programming languages in the world today. In addition, Mark has been in the software field for 30 years. He holds BS and MS degrees in computer science from the University of Wisconsin where he explored implementations of the Prolog language, and over his career has worked as a professional software developer on compilers, programming tools, scripting applications, and assorted client/server systems.

Mark maintains a training website (http://learning-python.com) and an additional book support site on the Web (http://www.rmi.net/~lutz).

Read More Show Less

Read an Excerpt


Excerpt from Chapter 10: Frameworks and Applications

JPython: The Felicitous Union of Python and Java

JPython is a recently released version of Python written entirely in Java by Jim Hugunin. JPython is a very exciting development for both the Python community and the Java community. Python users are happy that their current Python knowledge can transfer to Java-based development environments; Java programmers are happy that they can use the Python scripting language as a way to control their Java systems, test libraries, and learn about Java libraries from an interpreted environment.

JPython is available from http://www.python.org/jpython, with license and distribution terms similar to those of CPython (which is what the reference implementation of Python is called when contrasted with JPython).

The JPython installation includes several parts:

  • jpython: The equivalent of the Python program used throughout the book.
  • jpythonc: Takes a JPython program and compiles it to Java class files. The resulting Java class files can be used as any Java class file can,for example as applets, as servlets, or as beans.
  • A set of modules that provide the JPython user with the vast majority of the modules in the standard Python library.
  • A few programs demonstrating various aspects of JPython programming.

Using JPython is very similar to using Python:



~/book> 
jpythonJPython 1.0.3 on java1.2beta4Copyright 1997-1998 Corporation for National Research Initiatives>>> 
2 + 35

In fact, JPython works almost identically to CPython. For an up-to-date listing of the differences between the two, see http://www.python.org/jpython/differences.html. The most important differences are:

  • JPython is currently slower than CPython. How much slower depends on the test code used and on the Java Virtual Machine JPython is using. JPython''s author has, on the other hand, explored very promising optimizations, which could make future versions of JPython as fast or faster than CPython.
  • Some of the built-ins or library modules aren''t available for JPython. For example, the os.system() call is not implemented yet, as doing so is difficult given Java''s interaction with the underlying operating system. Also, some of the largest extension modules such as the Tkinter GUI framework aren''t available, because the underlying tools (the Tk/Tcl toolkit, in the case of Tkinter) aren''t available in Java.

JPython Gives Python Programmers Access
to Java Libraries

The most important difference between JPython and CPython, however, is that JPython offers the Python programmer seamless access to Java libraries. Consider the following program, jpythondemo.py, the output of which is shown in Figure 10-5.

Figure 10-5. The output of jpythondemo.py



from pawt import swingimport java def exit(e): java.lang.System.exit(0) frame = swing.JFrame(''Swing Example'', visible=1)button = swing.JButton(This is a Swinging button!'', actionPerformed=exit)frame.contentPane.add(button)frame.pack()

This simple program demonstrates how easy it is to write a Python program that uses the Swing Java GUI framework.[7] The first line imports the swing Java package (the pawt module figures out the exact location of Swing, which can be in java.awt.swing, in com.sun.java.swing, or maybe in javax.swing). The second line imports the java package that we need for the java.lang.System.exit() call. The fourth line creates a JFrame, setting its bean property visible to true. The fifth line creates a JButton with a label and specifies what function should be called when the button is clicked. Finally, the last two lines put the JButton in the JFrame and make them both visible.

Experienced Java programmers might be a bit surprised at some of the code in jpythondemo.py, as it has some differences from the equivalent Java program. In order to make using Java libraries as easy as possible for Python users, JPython performs a lot of work behind the scenes. For example, when JPython imports a Java package, it actively tracks down the appropriate package, and then, using the Java Reflection API, finds the contents of packages, and the signatures of classes and methods. JPython also performs on-the-fly conversion between Python types and Java types. In jpythondemo.py, for example, the text of the button (''This is a Swinging example!'') is a Python string. Before the constructor for JButton is called, JPython finds which variant of the constructor can be used (e.g., by rejecting the version that accepts an Icon as a first argument), and automatically converts the Python string object to a Java string object. More sophisticated mechanisms allow the convenient actionPerformed=exit keyword argument to the JButton constructor. This idiom isn''t possible in Java, since Java can''t manipulate functions (or methods) as first-class objects. JPython makes it unnecessary to create an ActionListener class with a single actionPerformed method, although you can use the more verbose form if you wish.

JPython as a Java Scripting Language

JPython is gaining in popularity because it allows programmers to explore the myriad Java libraries that are becoming available in an interactive, rapid turnaround environment. It also is proving useful to embed Python as a scripting language in Java frameworks, for customization, testing, and other programming tasks by end users (as opposed to systems developers). For an example of a Python interpreter embedded in a Java program, see the program in the demo/embed directory of the JPython distribution.

A Real JPython/Swing Application: grapher.py

The grapher.py program (output shown in Figure 10-6) allows users to graphically explore the behavior of mathematical functions. It''s also based on the Swing GUI toolkit. There are two text-entry widgets in which Python code should be entered. The first is an arbitrary Python program that''s invoked before the function is drawn; it imports the needed modules and defines any functions that might be needed in computing the value of the function. The second text area (labeled Expression:) should be a Python expression (as in sin(x)), not a statement. It''s called for each data point, with the value of the variable x set to the horizontal coordinate.

Figure 10-6. Output of grapher.py

The user can control whether to draw a line graph or a filled graph, the number of points to plot, and what color to plot the graph in. Finally, the user can save configurations to disk and reload them later (using the pickle module) Here is the grapher.py program:



from pawt import swing, awt, colors, GridBagRIGHT = swing.JLabel.RIGHTAPPROVE_OPTION = swing.JFileChooser.APPROVE_OPTIONimport java.ioimport pickle, os 
default_setup = """from math import *
def squarewave(x,order): 
   total = 0.0 
   for i in range(1, order*2+1, 2): 
       total = total + sin(x*i/10.0)/(float(i)) 
   return total
"""default_expression = "squarewave(x, order=3)" class Chart(awt.Canvas):    color = colors.darkturquoise    style = ''Filled''     def getPreferredSize(self):        return awt.Dimension(600,300)     def paint(self, graphics):        clip = self.bounds        graphics.color = colors.white        graphics.fillRect(0, 0, clip.width, clip.height)         width = int(clip.width * .8)        height = int(clip.height * .8)        x_offset = int(clip.width * .1)        y_offset = clip.height - int(clip.height * .1)         N = len(self.data); xs = [0]*N; ys = [0]*N         xmin, xmax = 0, N-1        ymax = max(self.data)        ymin = min(self.data)         zero_y = y_offset - int(-ymin/(ymax-ymin)*height)        zero_x = x_offset + int(-xmin/(xmax-xmin)*width)         for i in range(N):            xs[i] = int(float(i)*width/N) + x_offset            ys[i] = y_offset - int((self.data[i]-ymin)/(ymax-ymin)*height)        graphics.color = self.color        if self.style == "Line": graphics.drawPolyline(xs, ys, len(xs))        else:            xs.insert(0, xs[0]); ys.insert(0, zero_y)            xs.append(xs[-1]); ys.append(zero_y)            graphics.fillPolygon(xs, ys, len(xs))         # draw axes        graphics.color = colors.black        graphics.drawLine(x_offset,zero_y, x_offset+width, zero_y)        graphics.drawLine(zero_x, y_offset, zero_x, y_offset-height)         # draw labels        leading = graphics.font.size        graphics.drawString("%.3f" % xmin, x_offset, zero_y+leading)        graphics.drawString("%.3f" % xmax, x_offset+width, zero_y+leading)        graphics.drawString("%.3f" % ymin, zero_x-50, y_offset)        graphics.drawString("%.3f" % ymax, zero_x-50, y_offset-height+leading) class GUI:    def __init__(self):        self.numelements = 100        self.frame = swing.JFrame(windowClosing=self.do_quit)         # build menu bar        menubar = swing.JMenuBar()        file = swing.JMenu("File")        file.add(swing.JMenuItem("Load", actionPerformed = self.do_load))        file.add(swing.JMenuItem("Save", actionPerformed = self.do_save))        file.add(swing.JMenuItem("Quit", actionPerformed = self.do_quit))        menubar.add(file)        self.frame.JMenuBar = menubar         # create widgets        self.chart = Chart(visible=1)        
self.execentry = swing.JTextArea(default_setup, 8, 60) 
       self.evalentry = swing.JTextField(default_expression, 
                                         actionPerformed = self.update)         # create options panel        optionsPanel = swing.JPanel(awt.FlowLayout(            alignment=awt.FlowLayout.LEFT))         # whether the plot is a line graph or a filled graph        self.filled = swing.JRadioButton("Filled",                                         actionPerformed=self.set_filled)        optionsPanel.add(self.filled)        self.line = swing.JRadioButton("Line",                                       actionPerformed=self.set_line)        optionsPanel.add(self.line)        styleGroup = swing.ButtonGroup()        styleGroup.add(self.filled)        styleGroup.add(self.line)         # color selection        optionsPanel.add(swing.JLabel("Color:", RIGHT))        colorlist = filter(lambda x: x[0] != ''_'', dir(colors))        self.colorname = swing.JComboBox(colorlist)        self.colorname.itemStateChanged = self.set_color        optionsPanel.add(self.colorname)         # number of points        optionsPanel.add(swing.JLabel("Number of Points:", RIGHT))        self.sizes = [50, 100, 200, 500]        self.numpoints = swing.JComboBox(self.sizes)        self.numpoints.selectedIndex = self.sizes.index(self.numelements)        self.numpoints.itemStateChanged = self.set_numpoints        optionsPanel.add(self.numpoints)         # do the rest of the layout in a GridBag        self.do_layout(optionsPanel)     def do_layout(self, optionsPanel):        bag = GridBag(self.frame.contentPane, fill=''BOTH'',                      weightx=1.0, weighty=1.0)        bag.add(swing.JLabel("Setup Code: ", RIGHT))        bag.addRow(swing.JScrollPane(self.execentry), weighty=10.0)        bag.add(swing.JLabel("Expression: ", RIGHT))        bag.addRow(self.evalentry, weighty=2.0)        bag.add(swing.JLabel("Output: ", RIGHT))        bag.addRow(self.chart, weighty=20.0)        bag.add(swing.JLabel("Options: ", RIGHT))  def set_color(self, event):        self.chart.color = getattr(colors, event.item)        self.chart.repaint()     def set_numpoints(self, event):        self.numelements = event.item        self.update(None)     def set_filled(self, event):        self.chart.style = ''Filled''        self.chart.repaint()     def set_line(self, event):        self.chart.style = ''Line''        self.chart.repaint()     def update(self, event):        
context = {} 
       exec self.execentry.text in context 
       each = compile(self.evalentry.text, ''
'', ''eval'') 
       numbers = [0]*self.numelements 
       for x in xrange(self.numelements): 
           context[''x''] = float(x) 
           numbers[x] = eval(each, context)        self.chart.data = numbers        if self.chart.style == ''Line'':            self.line.setSelected(1)        else:            self.filled.setSelected(1)        self.chart.repaint() GUI()

The logic of this program is fairly straightforward, and the class and method names make it easy to follow the flow of control. Most of this program could have been written in fairly analogous (but quite a bit longer) Java code. The parts in bold, however, show the power of having Python available: at the top of the module, default values for the Setup and Expression text widgets are defined. The former imports the functions in the math module and defines a function called squarewave. The latter specifies a call to this function, with a specific order parameter (as that parameter grows, the resulting graph looks more and more like a square wave, hence the name of the function). If you have Java, Swing, and JPython installed, feel free to play around with other possibilities for both the Setup and Expression text widgets.

The key asset of using JPython instead of Java in this example is in the update method: it simply calls the standard Python exec statement with the Setup code as an argument, and then calls eval with the compiled version of the Expression code for each coordinate. The user is free to use any part of Python in these text widgets!

JPython is still very much a work in progress; Jim Hugunin is constantly refining the interface between Python and Java and optimizing it. JPython, by being the second implementation of Python, is also forcing Guido van Rossum to decide what aspects of Python are core to the language and what aspects are features of his implementation. Luckily, Jim and Guido seem to be getting along and agreeing on most points.


7. Documentation for Swing and the Java Foundation Classes is available online at http://java.sun.com/products/jfc/index.html. Alternatively, Robert Eckstein, Marc Loy, and Dave Wood have published a thorough review of the Swing toolkit for Java, Java Swing, published by O'Reilly & Associates.

Read More Show Less

Table of Contents

Dedication;
Preface;
This Book’s “Ecosystem”;
About This Fifth Edition;
The Python 2.X and 3.X Lines;
This Book’s Prerequisites and Effort;
This Book’s Structure;
What This Book Is Not;
This Book’s Programs;
Font Conventions;
Book Updates and Resources;
Acknowledgments;
Getting Started;
Chapter 1: A Python Q&A Session;
1.1 Why Do People Use Python?;
1.2 Is Python a “Scripting Language”?;
1.3 OK, but What’s the Downside?;
1.4 Who Uses Python Today?;
1.5 What Can I Do with Python?;
1.6 How Is Python Developed and Supported?;
1.7 What Are Python’s Technical Strengths?;
1.8 How Does Python Stack Up to Language X?;
1.9 Chapter Summary;
1.10 Test Your Knowledge: Quiz;
1.11 Test Your Knowledge: Answers;
Chapter 2: How Python Runs Programs;
2.1 Introducing the Python Interpreter;
2.2 Program Execution;
2.3 Execution Model Variations;
2.4 Chapter Summary;
2.5 Test Your Knowledge: Quiz;
2.6 Test Your Knowledge: Answers;
Chapter 3: How You Run Programs;
3.1 The Interactive Prompt;
3.2 System Command Lines and Files;
3.3 Unix-Style Executable Scripts: #!;
3.4 Clicking File Icons;
3.5 Module Imports and Reloads;
3.6 Using exec to Run Module Files;
3.7 The IDLE User Interface;
3.8 Other IDEs;
3.9 Other Launch Options;
3.10 Which Option Should I Use?;
3.11 Chapter Summary;
3.12 Test Your Knowledge: Quiz;
3.13 Test Your Knowledge: Answers;
3.14 Test Your Knowledge: Part I Exercises;
Types and Operations;
Chapter 4: Introducing Python Object Types;
4.1 The Python Conceptual Hierarchy;
4.2 Why Use Built-in Types?;
4.3 Python’s Core Data Types;
4.4 Numbers;
4.5 Strings;
4.6 Lists;
4.7 Dictionaries;
4.8 Tuples;
4.9 Files;
4.10 Other Core Types;
4.11 Chapter Summary;
4.12 Test Your Knowledge: Quiz;
4.13 Test Your Knowledge: Answers;
Chapter 5: Numeric Types;
5.1 Numeric Type Basics;
5.2 Numbers in Action;
5.3 Other Numeric Types;
5.4 Numeric Extensions;
5.5 Chapter Summary;
5.6 Test Your Knowledge: Quiz;
5.7 Test Your Knowledge: Answers;
Chapter 6: The Dynamic Typing Interlude;
6.1 The Case of the Missing Declaration Statements;
6.2 Shared References;
6.3 Dynamic Typing Is Everywhere;
6.4 Chapter Summary;
6.5 Test Your Knowledge: Quiz;
6.6 Test Your Knowledge: Answers;
Chapter 7: String Fundamentals;
7.1 This Chapter’s Scope;
7.2 String Basics;
7.3 String Literals;
7.4 Strings in Action;
7.5 String Methods;
7.6 String Formatting Expressions;
7.7 String Formatting Method Calls;
7.8 General Type Categories;
7.9 Chapter Summary;
7.10 Test Your Knowledge: Quiz;
7.11 Test Your Knowledge: Answers;
Chapter 8: Lists and Dictionaries;
8.1 Lists;
8.2 Lists in Action;
8.3 Dictionaries;
8.4 Dictionaries in Action;
8.5 Chapter Summary;
8.6 Test Your Knowledge: Quiz;
8.7 Test Your Knowledge: Answers;
Chapter 9: Tuples, Files, and Everything Else;
9.1 Tuples;
9.2 Files;
9.3 Core Types Review and Summary;
9.4 Built-in Type Gotchas;
9.5 Chapter Summary;
9.6 Test Your Knowledge: Quiz;
9.7 Test Your Knowledge: Answers;
9.8 Test Your Knowledge: Part II Exercises;
Statements and Syntax;
Chapter 10: Introducing Python Statements;
10.1 The Python Conceptual Hierarchy Revisited;
10.2 Python’s Statements;
10.3 A Tale of Two ifs;
10.4 A Quick Example: Interactive Loops;
10.5 Chapter Summary;
10.6 Test Your Knowledge: Quiz;
10.7 Test Your Knowledge: Answers;
Chapter 11: Assignments, Expressions, and Prints;
11.1 Assignment Statements;
11.2 Expression Statements;
11.3 Print Operations;
11.4 Chapter Summary;
11.5 Test Your Knowledge: Quiz;
11.6 Test Your Knowledge: Answers;
Chapter 12: if Tests and Syntax Rules;
12.1 if Statements;
12.2 Python Syntax Revisited;
12.3 Truth Values and Boolean Tests;
12.4 The if/else Ternary Expression;
12.5 Chapter Summary;
12.6 Test Your Knowledge: Quiz;
12.7 Test Your Knowledge: Answers;
Chapter 13: while and for Loops;
13.1 while Loops;
13.2 break, continue, pass, and the Loop else;
13.3 for Loops;
13.4 Loop Coding Techniques;
13.5 Chapter Summary;
13.6 Test Your Knowledge: Quiz;
13.7 Test Your Knowledge: Answers;
Chapter 14: Iterations and Comprehensions;
14.1 Iterations: A First Look;
14.2 List Comprehensions: A First Detailed Look;
14.3 Other Iteration Contexts;
14.4 New Iterables in Python 3.X;
14.5 Other Iteration Topics;
14.6 Chapter Summary;
14.7 Test Your Knowledge: Quiz;
14.8 Test Your Knowledge: Answers;
Chapter 15: The Documentation Interlude;
15.1 Python Documentation Sources;
15.2 Common Coding Gotchas;
15.3 Chapter Summary;
15.4 Test Your Knowledge: Quiz;
15.5 Test Your Knowledge: Answers;
15.6 Test Your Knowledge: Part III Exercises;
Functions and Generators;
Chapter 16: Function Basics;
16.1 Why Use Functions?;
16.2 Coding Functions;
16.3 A First Example: Definitions and Calls;
16.4 A Second Example: Intersecting Sequences;
16.5 Chapter Summary;
16.6 Test Your Knowledge: Quiz;
16.7 Test Your Knowledge: Answers;
Chapter 17: Scopes;
17.1 Python Scope Basics;
17.2 The global Statement;
17.3 Scopes and Nested Functions;
17.4 The nonlocal Statement in 3.X;
17.5 Why nonlocal? State Retention Options;
17.6 Chapter Summary;
17.7 Test Your Knowledge: Quiz;
17.8 Test Your Knowledge: Answers;
Chapter 18: Arguments;
18.1 Argument-Passing Basics;
18.2 Special Argument-Matching Modes;
18.3 The min Wakeup Call!;
18.4 Generalized Set Functions;
18.5 Emulating the Python 3.X print Function;
18.6 Chapter Summary;
18.7 Test Your Knowledge: Quiz;
18.8 Test Your Knowledge: Answers;
Chapter 19: Advanced Function Topics;
19.1 Function Design Concepts;
19.2 Recursive Functions;
19.3 Function Objects: Attributes and Annotations;
19.4 Anonymous Functions: lambda;
19.5 Functional Programming Tools;
19.6 Chapter Summary;
19.7 Test Your Knowledge: Quiz;
19.8 Test Your Knowledge: Answers;
Chapter 20: Comprehensions and Generations;
20.1 List Comprehensions and Functional Tools;
20.2 Generator Functions and Expressions;
20.3 Comprehension Syntax Summary;
20.4 Chapter Summary;
20.5 Test Your Knowledge: Quiz;
20.6 Test Your Knowledge: Answers;
Chapter 21: The Benchmarking Interlude;
21.1 Timing Iteration Alternatives;
21.2 Timing Iterations and Pythons with timeit;
21.3 Other Benchmarking Topics: pystones;
21.4 Function Gotchas;
21.5 Chapter Summary;
21.6 Test Your Knowledge: Quiz;
21.7 Test Your Knowledge: Answers;
21.8 Test Your Knowledge: Part IV Exercises;
Modules and Packages;
Chapter 22: Modules: The Big Picture;
22.1 Why Use Modules?;
22.2 Python Program Architecture;
22.3 How Imports Work;
22.4 Byte Code Files: __pycache__ in Python 3.2+;
22.5 The Module Search Path;
22.6 Chapter Summary;
22.7 Test Your Knowledge: Quiz;
22.8 Test Your Knowledge: Answers;
Chapter 23: Module Coding Basics;
23.1 Module Creation;
23.2 Module Usage;
23.3 Module Namespaces;
23.4 Reloading Modules;
23.5 Chapter Summary;
23.6 Test Your Knowledge: Quiz;
23.7 Test Your Knowledge: Answers;
Chapter 24: Module Packages;
24.1 Package Import Basics;
24.2 Package Import Example;
24.3 Why Use Package Imports?;
24.4 Package Relative Imports;
24.5 Python 3.3 Namespace Packages;
24.6 Chapter Summary;
24.7 Test Your Knowledge: Quiz;
24.8 Test Your Knowledge: Answers;
Chapter 25: Advanced Module Topics;
25.1 Module Design Concepts;
25.2 Data Hiding in Modules;
25.3 Enabling Future Language Features: __future__;
25.4 Mixed Usage Modes: __name__ and __main__;
25.5 Example: Dual Mode Code;
25.6 Changing the Module Search Path;
25.7 The as Extension for import and from;
25.8 Example: Modules Are Objects;
25.9 Importing Modules by Name String;
25.10 Example: Transitive Module Reloads;
25.11 Module Gotchas;
25.12 Chapter Summary;
25.13 Test Your Knowledge: Quiz;
25.14 Test Your Knowledge: Answers;
25.15 Test Your Knowledge: Part V Exercises;
Classes and OOP;
Chapter 26: OOP: The Big Picture;
26.1 Why Use Classes?;
26.2 OOP from 30,000 Feet;
26.3 Chapter Summary;
26.4 Test Your Knowledge: Quiz;
26.5 Test Your Knowledge: Answers;
Chapter 27: Class Coding Basics;
27.1 Classes Generate Multiple Instance Objects;
27.2 Classes Are Customized by Inheritance;
27.3 Classes Can Intercept Python Operators;
27.4 The World’s Simplest Python Class;
27.5 Chapter Summary;
27.6 Test Your Knowledge: Quiz;
27.7 Test Your Knowledge: Answers;
Chapter 28: A More Realistic Example;
28.1 Step 1: Making Instances;
28.2 Step 2: Adding Behavior Methods;
28.3 Step 3: Operator Overloading;
28.4 Step 4: Customizing Behavior by Subclassing;
28.5 Step 5: Customizing Constructors, Too;
28.6 Step 6: Using Introspection Tools;
28.7 Step 7 (Final): Storing Objects in a Database;
28.8 Future Directions;
28.9 Chapter Summary;
28.10 Test Your Knowledge: Quiz;
28.11 Test Your Knowledge: Answers;
Chapter 29: Class Coding Details;
29.1 The class Statement;
29.2 Methods;
29.3 Inheritance;
29.4 Namespaces: The Conclusion;
29.5 Documentation Strings Revisited;
29.6 Classes Versus Modules;
29.7 Chapter Summary;
29.8 Test Your Knowledge: Quiz;
29.9 Test Your Knowledge: Answers;
Chapter 30: Operator Overloading;
30.1 The Basics;
30.2 Indexing and Slicing: __getitem__ and __setitem__;
30.3 Index Iteration: __getitem__;
30.4 Iterable Objects: __iter__ and __next__;
30.5 Membership: __contains__, __iter__, and __getitem__;
30.6 Attribute Access: __getattr__ and __setattr__;
30.7 String Representation: __repr__ and __str__;
30.8 Right-Side and In-Place Uses: __radd__ and __iadd__;
30.9 Call Expressions: __call__;
30.10 Comparisons: __lt__, __gt__, and Others;
30.11 Boolean Tests: __bool__ and __len__;
30.12 Object Destruction: __del__;
30.13 Chapter Summary;
30.14 Test Your Knowledge: Quiz;
30.15 Test Your Knowledge: Answers;
Chapter 31: Designing with Classes;
31.1 Python and OOP;
31.2 OOP and Inheritance: “Is-a” Relationships;
31.3 OOP and Composition: “Has-a” Relationships;
31.4 OOP and Delegation: “Wrapper” Proxy Objects;
31.5 Pseudoprivate Class Attributes;
31.6 Methods Are Objects: Bound or Unbound;
31.7 Classes Are Objects: Generic Object Factories;
31.8 Multiple Inheritance: “Mix-in” Classes;
31.9 Other Design-Related Topics;
31.10 Chapter Summary;
31.11 Test Your Knowledge: Quiz;
31.12 Test Your Knowledge: Answers;
Chapter 32: Advanced Class Topics;
32.1 Extending Built-in Types;
32.2 The “New Style” Class Model;
32.3 New-Style Class Changes;
32.4 New-Style Class Extensions;
32.5 Static and Class Methods;
32.6 Decorators and Metaclasses: Part 1;
32.7 The super Built-in Function: For Better or Worse?;
32.8 Class Gotchas;
32.9 Chapter Summary;
32.10 Test Your Knowledge: Quiz;
32.11 Test Your Knowledge: Answers;
32.12 Test Your Knowledge: Part VI Exercises;
Exceptions and Tools;
Chapter 33: Exception Basics;
33.1 Why Use Exceptions?;
33.2 Exceptions: The Short Story;
33.3 Chapter Summary;
33.4 Test Your Knowledge: Quiz;
33.5 Test Your Knowledge: Answers;
Chapter 34: Exception Coding Details;
34.1 The try/except/else Statement;
34.2 The try/finally Statement;
34.3 Unified try/except/finally;
34.4 The raise Statement;
34.5 The assert Statement;
34.6 with/as Context Managers;
34.7 Chapter Summary;
34.8 Test Your Knowledge: Quiz;
34.9 Test Your Knowledge: Answers;
Chapter 35: Exception Objects;
35.1 Exceptions: Back to the Future;
35.2 Why Exception Hierarchies?;
35.3 Built-in Exception Classes;
35.4 Custom Print Displays;
35.5 Custom Data and Behavior;
35.6 Chapter Summary;
35.7 Test Your Knowledge: Quiz;
35.8 Test Your Knowledge: Answers;
Chapter 36: Designing with Exceptions;
36.1 Nesting Exception Handlers;
36.2 Exception Idioms;
36.3 Exception Design Tips and Gotchas;
36.4 Core Language Summary;
36.5 Chapter Summary;
36.6 Test Your Knowledge: Quiz;
36.7 Test Your Knowledge: Answers;
36.8 Test Your Knowledge: Part VII Exercises;
Advanced Topics;
Chapter 37: Unicode and Byte Strings;
37.1 String Changes in 3.X;
37.2 String Basics;
37.3 Coding Basic Strings;
37.4 Coding Unicode Strings;
37.5 Using 3.X bytes Objects;
37.6 Using 3.X/2.6+ bytearray Objects;
37.7 Using Text and Binary Files;
37.8 Using Unicode Files;
37.9 Other String Tool Changes in 3.X;
37.10 Chapter Summary;
37.11 Test Your Knowledge: Quiz;
37.12 Test Your Knowledge: Answers;
Chapter 38: Managed Attributes;
38.1 Why Manage Attributes?;
38.2 Properties;
38.3 Descriptors;
38.4 __getattr__ and __getattribute__;
38.5 Example: Attribute Validations;
38.6 Chapter Summary;
38.7 Test Your Knowledge: Quiz;
Chapter 39: Decorators;
39.1 What’s a Decorator?;
39.2 The Basics;
39.3 Coding Function Decorators;
39.4 Coding Class Decorators;
39.5 Managing Functions and Classes Directly;
39.6 Example: “Private” and “Public” Attributes;
39.7 Example: Validating Function Arguments;
39.8 Chapter Summary;
39.9 Test Your Knowledge: Quiz;
39.10 Test Your Knowledge: Answers;
Chapter 40: Metaclasses;
40.1 To Metaclass or Not to Metaclass;
40.2 The Metaclass Model;
40.3 Declaring Metaclasses;
40.4 Coding Metaclasses;
40.5 Inheritance and Instance;
40.6 Metaclass Methods;
40.7 Example: Adding Methods to Classes;
40.8 Example: Applying Decorators to Methods;
40.9 Chapter Summary;
40.10 Test Your Knowledge: Quiz;
40.11 Test Your Knowledge: Answers;
Chapter 41: All Good Things;
41.1 The Python Paradox;
41.2 Where to Go From Here;
41.3 Encore: Print Your Own Completion Certificate!;
Appendixes;
Installation and Configuration;
Installing the Python Interpreter;
Configuring Python;
For More Help;
The Python 3.3 Windows Launcher;
The Unix Legacy;
The Windows Legacy;
Introducing the New Windows Launcher;
A Windows Launcher Tutorial;
Pitfalls of the New Windows Launcher;
Conclusions: A Net Win for Windows;
Python Changes and This Book;
Major 2.X/3.X Differences;
General Remarks: 3.X Changes;
Fifth Edition Python Changes: 2.7, 3.2, 3.3;
Fourth Edition Python Changes: 2.6, 3.0, 3.1;
Third Edition Python Changes: 2.3, 2.4, 2.5;
Earlier and Later Python Changes;
Solutions to End-of-Part Exercises;
Part I, Getting Started;
Part II, Types and Operations;
Part III, Statements and Syntax;
Part IV, Functions and Generators;
Part V, Modules and Packages;
Part VI, Classes and OOP;
Part VII, Exceptions and Tools;
Colophon;

Read More Show Less

Customer Reviews

Average Rating 3.5
( 19 )
Rating Distribution

5 Star

(7)

4 Star

(3)

3 Star

(3)

2 Star

(2)

1 Star

(4)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing all of 19 Customer Reviews
  • Posted September 9, 2011

    Be VERY careful purchasing this book

    If you go to the page for the 4th edition and press the link to download a sample, you WILL get a sample for the 2nd edition...covering Python 2.3, not 2.6 and 3.1. The same if you buy it without rooting around through the editions listed as ebooks.

    B&N will then tell you that they do not issue refunds for ebooks.

    8 out of 8 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted January 12, 2004

    Better than Perl or Tcl or shell scripts

    It gives a thorough description of how to use Python; which is indeed easy to learn if you already know another language. But when the authors say that not having to compile Python programs means that development time is speeded up, perhaps they are overstating. For most programmers who use compiled languages like C or C++, the biggest time is taken up in finding a method that solves a problem, coding it and subsequent debugging. These days, compilers on recent hardware are fast enough that link/compile times are simply not a bottleneck to development productivity. So it is a bit of a straw dummy that the authors put forth. However, they are absolutely spot on when comparing this to Perl or Tcl. Perl is powerful, but its code looks like assembler. Perl gurus tend to shrug when you point this out, usually saying they understand it, with the not-so-implicit suggestion that if you can't, it is your fault. But this leads to a real maintenance problem and a barrier to entry to others. The cleaner Python syntax can show coding intent far clearer. Plus, and more importantly, the object oriented nature of Python lets you scale up to much larger programs. This has always been a problem with scripting languages, all the way back to the various unix shell scripts and DOS bat files. Often, the most those ever gave you in terms of modular capabilities was the equivalent of subroutines. Which is strictly procedural and not OO. By the way, there is a small contradiction between the above claim that Python is more understandable than Perl and the claim that it has an advantage over C++ or Java because it is not as verbose as those. Typically, in increasing amount of source code, you have Perl -> Python -> (C++,Java). If you think that Python is more understandable than Perl, then by that same logic, we could conclude that C++ or Java is more understandable than Python. So if you are using Perl or Tcl and want something better, Python is a good choice. A good upgrade path. But if you are currently using C or C++, with maybe X for graphics, or Java, then I suggest you stay with those. All three languages, with their graphics, give you a far richer toolset. Python would be a retrograde choice.

    3 out of 6 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted January 22, 2013

    Its a 4494 page sample

    Its a freaking 4494 page sample totally get the free sample( this ' sample'includes all chaptets except the appendexs)very well written good for the begginnr and more experianced alike

    2 out of 3 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted February 11, 2014

    Nurses office

    Here.

    0 out of 2 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted November 23, 2013

    snakeclan

    warriors den for snakeclan.

    0 out of 1 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted November 13, 2013

    Excellent python resource

    Excellent for beginner but still worthwhile for more advanced python programmer

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted September 23, 2013

    OF ALL TIME!!!!!!!!

    0 out of 2 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted January 19, 2013

    This is an excellent book to teach yourself Python! I have the 4

    This is an excellent book to teach yourself Python!
    I have the 4th edition. It focuses on Python 3.2 but explains the differences with Python 2.7 and earlier versions as those areas are encountered in the book. The book starts with the basics, which most will find very easy, and proceeds to the most advanced Python topics. Every chapter builds on what was taught in previous chapters. There are numerous WORKING examples throughout the book, and the author has a web site where you may down load all of the examples. I have Python 3.2 and 2.7 and have run most of the examples in both versions. This is an EXCELLENT book if you need, or just want to learn Python!

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted May 9, 2010

    No text was provided for this review.

  • Anonymous

    Posted December 8, 2010

    No text was provided for this review.

  • Anonymous

    Posted October 27, 2009

    No text was provided for this review.

  • Anonymous

    Posted September 9, 2009

    No text was provided for this review.

  • Anonymous

    Posted October 20, 2010

    No text was provided for this review.

  • Anonymous

    Posted August 2, 2011

    No text was provided for this review.

  • Anonymous

    Posted April 21, 2013

    No text was provided for this review.

  • Anonymous

    Posted December 19, 2010

    No text was provided for this review.

  • Anonymous

    Posted December 17, 2010

    No text was provided for this review.

  • Anonymous

    Posted November 2, 2009

    No text was provided for this review.

  • Anonymous

    Posted January 10, 2011

    No text was provided for this review.

Sort by: Showing all of 19 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)