[Tutor] Shortening the code of a finsihed program.
steve at pearwood.info
Sat Nov 26 01:14:02 CET 2011
>> Its usually better to paste long programs into a pastebin web site and
>> give us a link.
>> This saves cluttering up people mail with long messages, and also the
>> pastebin rendering will usually be easier to read with syntax coloring
Please keep a attribution line when quoting people directly. Even
something simple like "Fred wrote" will do.
> Alright. Sorry if I should know this, but what is a pastebin web site
> and how do
> I paste my program into a pastebin web site?
Here's one: http://pastebin.com/
But as I've just written in another post, please don't use it :)
>> While its perfectly legal Python to create a class inside a method its
>> very unusual in practice and very restricting in the use of the class.
>> Its nearly always better to declare all your classes at the top level of
>> the program.
> Why is it restricting?
Because generally speaking, if you define a class inside a function (or
method), you can't use it *except* inside that function or method.
def method(self, x):
instance = Q()
This doesn't work because Q is not visible from the outside of K.method.
Sometimes this is what you want; generally it is not.
I don't know much about tkinter, so I will avoid commenting about your code.
More information about the Tutor