Re: [Tutor] Challenge supporting custom deepcopy with inheritance

2009-06-01 Thread Michael H . Goldwasser
Chris, Thanks for your well-written reply. Your analogy to the complexities of other special methods is well noted. I'll accept the "small price for flexibility" that you note, if necessary. However, I still desire a cleaner solution. I can examine the inherited slots to see which sp

[Tutor] Challenge supporting custom deepcopy with inheritance

2009-05-31 Thread Michael H . Goldwasser
Yesterday, I posted a question to python-list involving custom deepcopies in an inheritance hierarchy. I haven't received any responses, so I thought I'd cross-post to see if anyone on tutor has any thoughts. To avoid splitting the thread, I'll simply reference the original post at http://mail.p

[Tutor] PyCon2009 Tutorial: An Introduction to Object-Oriented Programming

2009-01-31 Thread Michael H . Goldwasser
David Letscher and I will be leading a tutorial at this year's PyCon titled "An Introduction to Object-Oriented Programming." This tutorial is designed for programmers who are familiar with Python yet new to the concept of object-oriented programming. We also welcome programmers who are experien

[Tutor] sorting objects on two attributes

2008-03-03 Thread Michael H. Goldwasser
Hello Eric, Your basic outlook is fine, but you can do it much more efficiently with a single sort. Here's the way I'd approach the task (untested): # -- # first compute the latest date for each id group; uses O(n) time newest = {} f

Re: [Tutor] Pointers in python ??

2008-01-20 Thread Michael H. Goldwasser
On Sunday January 20, 2008, Alan Gauld wrote: >"Varsha Purohit" <[EMAIL PROTECTED]> wrote > >>Does python has concept of pointers like c/cpp ?? If yes >> how.. can >> anyone give me a small example to how we can use pointers in python. > >No, not really. >

Re: [Tutor] Scope and elegance revisited

2008-01-09 Thread Michael H. Goldwasser
On Wednesday January 9, 2008, Kent Johnson wrote: >James Newton wrote: >> Hi Python Purists! >> >> I want all instances of a given class to share a piece of information, >> but I want to set that information on the fly. I have found that this >> works: >> >>

[Tutor] Urgent: Help

2008-01-07 Thread Michael H. Goldwasser
Very good questions indeed. Also familiar ones to me. The first is Exercise 5.28 and the second is Exercise 5.23 from the text book "Object-Oriented Programming in Python." Alan's advice was very sound, but I strongly recommend that you work with your instructor in guiding you through these prob

[Tutor] classes and the deepcopy function

2008-01-04 Thread Michael H. Goldwasser
Hi Michael, This is a very interesting example. You do indeed have two distinct copies. The interdependence you are observing is because you have defined CLASS-LEVEL variables (akin to static in Java) rather than instance-level variables. This is because of their declaration within th

Re: [Tutor] Closing GUI program

2007-12-28 Thread Michael H. Goldwasser
Hi Jim, The problem with your code is that Tk's mainloop continues to run even though you have closed the window. The cleaner way to close such a GUI program is to explicitly stop the main loop and the Python interpreter at the appropriate time. In this particular case, you may provid

[Tutor] Regular Expression

2007-12-21 Thread Michael H. Goldwasser
Que, I haven't tested the script, but please note that patt.match(line) will only succeed when the pattern is at the start of the line. Use patt.search(line) if you want to find the pattern anywhere within the line. Based on your desired highlight, you might want to use the pattern, patt = re.c

[Tutor] Bound To Be A Typo

2007-12-17 Thread Michael H. Goldwasser
You've inadvertently used three underscores around __init__ rather than two, and therefore you are not really defining __init__ but instead are relying upon the inherited one from object (which takes no parameters). With regard, Michael On Monday December 17, 2007, earlylight publishing wrote:

[Tutor] what is the difference

2007-12-13 Thread Michael H. Goldwasser
Hi John, It depends upon whether the "..." code fragment is affected in any way by the value of self._inFlush. The first code sample you offer should be identical to the following. if not self._inFlush: self._inFlush = True# reset this before the ... ... else:

[Tutor] Timed While Loops and Threads

2007-12-08 Thread Michael H. Goldwasser
Hi everyone, I'm having some fun combining two recent topics: the "Timed While Loops" game and that of communication between threads. Here is an example that allows a person to gather points in a while loop, but only for a fixed period of time. It relies on a few shared variables to coordinate

Re: [Tutor] Use of sqrt() from math module

2007-12-01 Thread Michael H. Goldwasser
Matt, After using "import math" you will need to use the qualified name math.sqrt(blah) to call the square root function. That explains the NameError when trying to use the unqualified name, sqrt. As to your first message, the ValueError that you are reporting with the usage math.sqrt is likel

Re: [Tutor] parsing a continuous log file

2007-11-29 Thread Michael H. Goldwasser
The for loop below will exit once it hits EOF (and will not continue if more data is later appended. But as Alan says, a while loop will suffice. I've tested the following variant. import time f = file('foo.txt') while True: line = f.readline() if line: print "do what you want

Re: [Tutor] Variables and Functions

2007-11-28 Thread Michael H. Goldwasser
Hello Devon, Here's a quick [untested] push in the direction of taking the code you gave below and modeling it as a class using an object-oriented design. With this code, you could then create an instance of a puzzle as: toughOne = Sudoku() toughOne.play_game() Within

[Tutor] repeat

2007-11-17 Thread Michael H. Goldwasser
On Saturday November 17, 2007, Michael wrote: >Hi All > >This has probably been asked before but can I get some clarification on >why Python does not have a repeat...until statement, and does that mean >repeat...until is bad practice? I was trying to get Python on the >

[Tutor] Little subclass understanding problem

2007-11-15 Thread Michael H. Goldwasser
example is certainly not a proper use of inheritance. With regard, Michael On Thursday November 15, 2007, Michael H. Goldwasser wrote: > >On Thursday November 15, 2007, Tom wrote: > >>I am trying to understand what happens in the following scenario: >>

[Tutor] Little subclass understanding problem

2007-11-15 Thread Michael H. Goldwasser
On Thursday November 15, 2007, Tom wrote: >I am trying to understand what happens in the following scenario: > >class Sub_class(Base_class): >def __init__(self, data): >Base_class.__init__(self, data) > >as in: > ># snippet from http://viner.tv/go?

Re: [Tutor] manipulating data

2007-11-15 Thread Michael H. Goldwasser
On Monday November 12, 2007, Bryan Fodness wrote: >I try this, > >f = open('TEST1.MLC') > >fields = {} > >for line in f: >if line.split()[0] == 'Field': >field = int(line.split()[-1]) >elif line.split()[0] == 'Leaf': >fields[fie

Re: [Tutor] global is bad but ...

2007-11-13 Thread Michael H. Goldwasser
>> okay, i tried. so why are globals bad and what problems >> do they solve? The biggest complaint I have with the original example is that you've writen code to "do stuff" with array G, yet that code cannot directly be used to do the same stuff to some other array. In this sense, th

[Tutor] assignment question

2007-11-11 Thread Michael H. Goldwasser
On Sunday November 11, 2007, Ryan Hughes wrote: >Hello, > >Why does the following not return [1,2,3,4] ? > >>>> x = [1,2,3].append(4) >>>> print x >None The reason is that the append method does not return anything. In effect, the expresison [1,2,3].append(4) tempo

[Tutor] Problem with default arguments for function

2007-11-11 Thread Michael H. Goldwasser
Dick, Another typical strategy is to use some prescribed special value for the precision parameter to designate the desire for full precision. For example, since precisions should presumably be positive, one could design this function as: def fact(n, precision=15): """compute n!. preci

Re: [Tutor] New Introductory Book

2007-11-08 Thread Michael H. Goldwasser
On Thursday November 8, 2007, bhaaluu wrote: >I asked if the source code for the textbook is available for download? >One of the best ways to judge the quality of a textbook is by the example >source code. I also asked if a sample chapter was available to read? >Sometimes an auth

[Tutor] From Numpy Import *

2007-11-07 Thread Michael H. Goldwasser
On Wednesday November 7, 2007, Dinesh B Vadhia wrote: >Hello! The standard Python practice for importing modules is, for example: > >import sys >import os >etc. > >In NumPy (and SciPy) the 'book' suggests using: > >from numpy import * >from scipy import *

Re: [Tutor] New Introductory Book

2007-11-06 Thread Michael H. Goldwasser
I agree as well. Its not like there is a flood of these books coming >out, or emails slamming the list announcing them. > >Jay > >On Nov 6, 2007 1:38 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: >> Rikard Bosnjakovic wrote: >> >

[Tutor] New Introductory Book

2007-11-06 Thread Michael H. Goldwasser
We are pleased to announce the release of a new Python book. Object-Oriented Programming in Python by Michael H. Goldwasser and David Letscher Prentice Hall, 2008 (available as of 10/29/2007) The book differs greatly from existing introductory Python books as it