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
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
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
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
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.
>
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:
>>
>>
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
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
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
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
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:
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:
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
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
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
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
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
>
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:
>>
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?
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
>> 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
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
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
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
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 *
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:
>> >
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
27 matches
Mail list logo