Simple Class Question - need clarity please
alan.gauld at btinternet.com
Sat Apr 10 01:42:47 CEST 2004
On Sat, 10 Apr 2004 00:03:07 +0100, "Stevie_mac"
<no.email at please.com> wrote:
> What is wrong with this?...
> import win32con, win32ui
> from pywin.mfc import dialog #, window
> class Window:
> def MakeDlgTemplate(self):
> def DoModal(self):
> mw = win32ui.CreateDialogIndirect( self.MakeDlgTemplate() )
> # file test.py #
> import mywindow
> class MyClass(mywindow.Window):
> def Show(self):
> t = MyClass()
> . . . I get
> NameError: global name 'MakeDlgTemplate' is not defined ???
Its a good idea to post the entire error traceback so we see the
actual line of code the error refers to. This error usually means
you accessed a name from a module without prefixing it with the
module name. But so far as I can see you haven't done that here.
> another 1 I managed to clear up was . . .
> TypeError: Show() takes no arguments (1 given)
> . . . until I added 'self' to the Show function ???
Yes, every method of a class must have a parameter that refers to
the instance at call time, usually called self (or maybe "this"
if you come from Java or C++)
At runtime Python effectively calls
> I'm also struggling with other things like...
> Where do I save .py files?
Anywhere you like! I have a folder called Projects\Python where I
keep mine :-)
So long as Python knows where to find them - either by modifying
the sys.path value (explicitly or via the registry setting) or
the PYTHONPATH environment variable...
> Will 'import' find my files where ever they are?
Yes if one of the two locations above are set.
Author of the Learn to Program website
More information about the Python-list