[Tutor] Class Inheritance
steve at pearwood.info
Fri Apr 23 11:49:19 CEST 2010
On Fri, 23 Apr 2010 04:54:11 pm David Hutto wrote:
> > Something is screwy there. I believe you have broken your
> > installation by making changes to files without having any
> > understanding of what you are doing.
> My original post was incorrect: the first error should be:
> Traceback (most recent call last):
> File "C:\python26\Script3.py", line 1, in <module>
> from Tkinter import *
> File "C:\Python26\lib\lib-tk\Tkinter.py", line 44, in
> from turtle import *
> File "C:\Python26\lib\lib-tk\turtle.py", line 374, in
> class ScrolledCanvas(TK.Frame):
> AttributeError: 'module' object has no attribute 'Frame'
For anyone else reading this, this is a good example of why retyping
error messages is a bad, bad idea. That just wastes everybody's time,
and sends us on wild-goose chases trying to diagnose problems that
didn't actually occur.
> > Please don't try to "fix" library files when you don't understand
> > what they are doing. Confine your experiments to your own code, so
> > that when things break, you know that the cause is in your code,
> > not some random change you have done to the library.
> I know this, but I reinstall regularly, so evereything is 'pristine'.
You know it but continue to do it anyway?
If you want to experiment with library modules, make a copy of them into
your home directory, with a different name, and experiment to your
heart's desire. That gives you all the benefits of experimentation with
none of the disadvantages.
When you mangle a standard library module, then post long complicated
posts suggesting that the Python development team don't understand
their own language, you waste our time as well as yours. If you want to
waste your time, go right ahead, but don't send us on wild goose chases
with nonsense about the turtle module not allowing inheritance when the
breakage was due to your tinkering.
Next time you do something like this, be up front about it. Tell us
right from the beginning that you've been editing the modules, so we
don't have to spend our time discovering this for ourselves. If you
had, this conversation would have taken a completely different turn.
> If I get an error, I don't wait for mailing list responses, I usually
> try to analyze, from what I've learned so far, what's wrong and
> figure out why on my own
All that is good practice. What's not good practice is making random
changes to complicated libraries.
A good exercise in programming discipline is to try to reproduce the
fault in the smallest amount of code possible. When asking for help,
you'll often be asked to do this, because when asking for volunteers to
spend their time solving your problems for free, it is only fair that
you reduce the amount of effort needed as much as possible. As an
exercise, I've reproduced your error in minimal form:
>>> import mytkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "mytkinter.py", line 1, in <module>
from myturtle import *
File "myturtle.py", line 3, in <module>
AttributeError: 'module' object has no attribute 'Frame'
and here's the minimal implementation:
from myturtle import *
import mytkinter as TK
> P.S. I bet you've been waiting since you got your first condescending
> response to a similar question, to lay it on someone about touching
> the Almighty Library.
> Way to keep up the cycle.
Don't try to psychoanalyse people you've never met, you aren't any good
More information about the Tutor