[Tutor] classes passing information

Alan Gauld alan.gauld at btinternet.com
Wed Apr 21 19:20:01 CEST 2010


"Stefan Lesicnik" <stefan at lsd.co.za> wrote

Caveat: I know zilch about pyGtk.

> My question is maybe more generic with functions as opposed to classes,
> but i've been trying some pyGtk and I am unsure how i get values back
> from other classes.

They should be returned by the methods. So you just assign the method
result to a variable:

foo = someModule.SomeClass() # create an instance
bar = foo.someMethod()  # call a merthod and store the result.

> Its something like, i have a program.py which has a class and methods.
> One of those methods would be create a new dialog which is a class in
> dialog.py. So i can call that and pass it parameters.

import dialog

d = dialog.Dialog(foo, bar)

> The question is, how do i get the result of that dialog back to the calling 
> method?

The result being what? A reference to the new dialog object?
Or the button pressed by the user of the dialog?
For that I would need to know more about Gtk than I do.

> Im not even sure if this makes sense. I guess im still struggling to 
> understand
> how to pass parameters around to other methods, methods in other files,
> and get answers back.

It sounds like its the functions and parameter/value passing that you need help
with. The classes aspect is just an extra layer of fog.

Try my tutorial topic on Methods and Functions, see if that helps.

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list