Learning Python: Powerful Object-Oriented Programming

( 1 )

Overview

Python is a popular open source, object-oriented programming language used for both standalone programs and scripting applications. Portable, powerful, and a breeze to use, there's no quicker way to master the language than to learn from expert teachers. This new edition of Learning Python puts you in the hands of Mark Lutz and David Ascher, two notable Python experts and trainers whose friendly, well-structured prose has guided many programmers to proficiency in the language. Learning Python, Second Edition ...
See more details below
Available through our Marketplace sellers.
Other sellers (Paperback)
  • All (16) from $21.01   
  • New (5) from $21.54   
  • Used (11) from $21.01   
Close
Sort by
Page 1 of 1
Showing All
Note: Marketplace items are not eligible for any BN.com coupons and promotions
$21.54
Seller since 2009

Feedback rating:

(859)

Condition:

New — never opened or used in original packaging.

Like New — packaging may have been opened. A "Like New" item is suitable to give as a gift.

Very Good — may have minor signs of wear on packaging but item works perfectly and has no damage.

Good — item is in good condition but packaging may have signs of shelf wear/aging or torn packaging. All specific defects should be noted in the Comments section associated with each item.

Acceptable — item is in working order but may show signs of wear such as scratches or torn packaging. All specific defects should be noted in the Comments section associated with each item.

Used — An item that has been opened and may show signs of wear. All specific defects should be noted in the Comments section associated with each item.

Refurbished — A used item that has been renewed or updated and verified to be in proper working condition. Not necessarily completed by the original manufacturer.

New
0596513984 *BRAND NEW* Ships Same Day or Next!

Ships from: Springfield, VA

Usually ships in 1-2 business days

  • Canadian
  • International
  • Standard, 48 States
  • Standard (AK, HI)
  • Express, 48 States
  • Express (AK, HI)
$74.50
Seller since 2014

Feedback rating:

(267)

Condition: New
Brand New Item.

Ships from: Chatham, NJ

Usually ships in 1-2 business days

  • Canadian
  • International
  • Standard, 48 States
  • Standard (AK, HI)
  • Express, 48 States
  • Express (AK, HI)
$80.00
Seller since 2014

Feedback rating:

(149)

Condition: New
Brand new.

Ships from: acton, MA

Usually ships in 1-2 business days

  • Standard, 48 States
  • Standard (AK, HI)
$95.38
Seller since 2008

Feedback rating:

(191)

Condition: New
0596513984 New. Looks like an interesting title!

Ships from: Naperville, IL

Usually ships in 1-2 business days

  • Standard, 48 States
  • Standard (AK, HI)
$145.00
Seller since 2014

Feedback rating:

(149)

Condition: New
Brand new.

Ships from: acton, MA

Usually ships in 1-2 business days

  • Standard, 48 States
  • Standard (AK, HI)
Page 1 of 1
Showing All
Close
Sort by
Learning Python

Available on NOOK devices and apps  
  • NOOK Devices
  • NOOK HD/HD+ Tablet
  • NOOK
  • 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 Study
  • NOOK for Web

Want a NOOK? Explore Now

NOOK Book (eBook)
$17.99
BN.com price
(Save 43%)$31.99 List Price

Overview

Python is a popular open source, object-oriented programming language used for both standalone programs and scripting applications. Portable, powerful, and a breeze to use, there's no quicker way to master the language than to learn from expert teachers. This new edition of Learning Python puts you in the hands of Mark Lutz and David Ascher, two notable Python experts and trainers whose friendly, well-structured prose has guided many programmers to proficiency in the language. Learning Python, Second Edition offers programmers a comprehensive learning tool for Python and object-oriented programming. Thoroughly updated for the numerous language changes since the release of the first edition in 1999, this book introduces the basic elements of the latest release of Python 2.3 and covers new features, such as list comprehensions, nested scopes, and iterators/generators.

Beyond language features, this edition of Learning Python also includes new context for less-experienced programmers, including fresh overviews of object-oriented programming and dynamic typing, new discussions of program launch and configuration options, new coverage of documentation sources, and more. There are also new use cases throughout to make the application of language features more concrete. Learning Python starts by giving programmers all the information they'll need to understand and construct programs in the Python language, including types, operators, statements, classes, functions, modules, and exceptions. The authors then present more advanced material, showing how Python performs common tasks by offering real applications and the libraries available for those applications. There are exercises throughout the book to test your new skills. Learning Python, Second Edition is a self-paced book that allows readers to focus on the core Python language in depth. As you work through the book, you'll gain a deep and complete understanding of the Python language that will help you to develop larger applications on your own. This book is for anyone who doesn't want to stop at just learning Python, but wants to master it as well.

Read More Show Less

Editorial Reviews

From Barnes & Noble

This is an introductory tutorial for Python, the popular object-oriented scripting language used in many domains, especially on the web. Programmers are beginning to use it for standalone programs and seeing dramatic productivity improvements. Authors Mark Lutz & David Ascher cover Python essentials and core concepts, organizing their text around major language features, not examples. The tutorial is based on a three day hands-on Python course. Nonetheless, a basic understanding of object-oriented programming concepts and scripting environments will help you to work quickly through this text. You should also download a free copy of Python and install it to work the examples and code; authors provide the information and sources.

Highlights:

  • Core language section focuses on programming essentials, such as built-in types, statements, tools and packaged program components. Here, you also learn about types and operators, functions, modules, classes and exceptions.
  • Builds upon core concepts as it explains how to use built-in tools and perform common programming tasks. Leads into frameworks and applications by introducing elements of COM, the GUI editor, Python and Java integration.

Advantages:

  • This well-organized self-study tutorial clearly explains and annotates code. Discussions proceed from elementary to more difficult concepts and structures. End-of-chapter exercises are designed to make you think, not just regurgitate code.
  • Appendices contain additional references, resources and solutions to exercises.
  • Additional information is available on the authors' web site.

Related Titles:

Afteryou have mastered this tutorial, you may be interested in more intermediate to advanced programming guides, such as Programming Python, and Internet Programming with Python. A Python pocket reference, The Python Pocket Reference, is also available.

Read More Show Less

Product Details

  • ISBN-13: 9780596513986
  • Publisher: O'Reilly Media, Incorporated
  • Publication date: 10/28/2007
  • Edition description: Third Edition
  • Edition number: 3
  • Pages: 752
  • Product dimensions: 9.10 (w) x 10.08 (h) x 1.36 (d)

Meet the Author


Mark Lutz is a software developer and a Python writer and trainer. He is the author of Programming Python and Python Desktop Reference, both published by O'Reilly & Associates. Mark has programmed a variety of Python systems, teaches courses about Python, and has been involved with the Python community since 1992.

David Ascher is a hybrid scientist/software engineer/trainer. By day, he is a vision scientist; additionally, he spends a fair bit of his free time learning about computer science and teaching Python.

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

Preface
I. The Core Language
1. Getting Started
     Why Python?
     How to Run Python Programs
     A First Look at Module Files
     Python Configuration Details
     Summary
     Exercises

2. Types and Operators
     Python Program Structure
     Why Use Built-in Types?
     Numbers
     Strings
     Lists
     Dictionaries
     Tuples
     Files
     General Object Properties
     Built-in Type Gotchas
     Summary
     Exercises

3. Basic Statements
     Assignment
     Expressions
     Print
     if Tests
     while Loops
     for Loops
     Common Coding Gotchas
     Summary
     Exercises

4. Functions
     Why Use Functions?
     Function Basics
     Scope Rules in Functions
     Argument Passing
     Odds and Ends
     Function Gotchas
     Summary
     Exercises

5. Modules
     Why Use Modules?
     Module Basics
     Module Files Are Namespaces
     Import Model
      Reloading Modules
     Odds and Ends
     Module Gotchas
     Summary
     Exercises

6. Classes
     Why Use Classes?
     Class Basics
     Using the Class Statement
     Using Class Methods
     Inheritance Searches Namespace Trees
     Operator Overloading in Classes
     Namespace Rules: The Whole Story
     Designing with Classes
     Odds and Ends
     Class Gotchas
     Summary
     Exercises

7. Exceptions
     Why Use Exceptions?
     Exception Basics
     Exception Idioms
     Exception Catching Modes
     Odds and Ends
     Exception Gotchas
     Summary
     Exercises

II. The Outer Layers

8. Built-in Tools
     Built-in Functions
     Library Modules
     Exercises

9. Common Tasks in Python
     Data Structure Manipulations
     Manipulating Files
     Manipulating Programs
     Internet-Related Activities
     Bigger Examples
     Exercises

10. Frameworks and Applications
     An Automated Complaint System
     Interfacing with COM: Cheap Public Relations
     A Tkinter-Based GUI Editor for Managing Form Data
     Design Considerations
     JPython: The Felicitous Union of Python and Java
     Other Frameworks and Applications
     Exercises

III. Appendixes

A. Python Resources

B. Platform-Specific Topics

C. Solutions to Exercises

INDEX:

Read More Show Less

Customer Reviews

Average Rating 5
( 1 )
Rating Distribution

5 Star

(1)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

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 1 Customer Reviews
  • Anonymous

    Posted August 25, 2009

    No text was provided for this review.

Sort by: Showing 1 Customer Reviews

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