Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > [NEWBIE] access return values

Reply
Thread Tools

[NEWBIE] access return values

 
 
=?ISO-8859-1?Q?paul_k=F6lle?=
Guest
Posts: n/a
 
      09-18-2003
hi folks,

during the last couple of days I wrote my first small app with wxPython
and it all works pretty well, but now I'm somewhat lost. I'd like to
access the return value from a function inside an imported module (a
method of a class of that module eh?)

---gui.py----

from wxPython.wx import *
from app.py import *

user=UserObject(config) # class instance from app.py

the class UserObject has a function set_pwd() which returns a var, say
"ch_success" indicating success/failure wich I'd like to pass to a
Dialog to give some feedback to the user.

but:
--in gui.py----

d=wxMessageDialog(self, user.ch_success,"Info:", wxICON_INFORMATION | wxOK)

gives:

AttributeError: UserObject instance has no attribute 'ch_success'

That makes sense, since ch_success is a local variable of set_pwd(), so
I tried to make it global but with very little success so far. I tried:

--in app.py----

def set_pwd(someargs, moreargs)
do stuff //
...
global ch_success
or:
return ch_success
or:
self.ch_success

Nothing worked (but frankly, I don't really know what I'm doing here).

Any ideas? Thanks

Paul






 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      09-18-2003
paul kölle wrote:

> hi folks,
>
> during the last couple of days I wrote my first small app with wxPython
> and it all works pretty well, but now I'm somewhat lost. I'd like to
> access the return value from a function inside an imported module (a
> method of a class of that module eh?)
>
> ---gui.py----
>
> from wxPython.wx import *
> from app.py import *
>
> user=UserObject(config) # class instance from app.py
>
> the class UserObject has a function set_pwd() which returns a var, say
> "ch_success" indicating success/failure wich I'd like to pass to a
> Dialog to give some feedback to the user.
>
> but:
> --in gui.py----
>
> d=wxMessageDialog(self, user.ch_success,"Info:", wxICON_INFORMATION |
> wxOK)
>
> gives:
>
> AttributeError: UserObject instance has no attribute 'ch_success'
>
> That makes sense, since ch_success is a local variable of set_pwd(), so
> I tried to make it global but with very little success so far. I tried:
>
> --in app.py----
>
> def set_pwd(someargs, moreargs)
> do stuff //
> ...
> global ch_success
> or:
> return ch_success
> or:
> self.ch_success
>
> Nothing worked (but frankly, I don't really know what I'm doing here).
>
> Any ideas? Thanks
>
> Paul


A function does not keep its return value between calls. You have to bind it
like so:

func(args) # return value lost forever
value = func(args) #keep it in value

and can use value in subsequent code. I can only guess that set_pwd() is a
method of UserObject and ch_success an attribute:

class UserObject:
set_pwd(self, pwd):
# your code
self.ch_success = True # say, the pwd was successfully set

which would be used:

user = UserObject()
user.set_pwd("secret")
print user.ch_success

Please post *real* code and the resulting tracebacks to allow for a more
detailed analysis.

Peter
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Unpack less values from function's return values Chris Rebert Python 1 05-28-2009 02:47 PM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM
difference between return &*i and return i; Ganesh Gella C++ 4 11-12-2004 04:28 PM
How do I return a return-code from main? wl Java 2 03-05-2004 05:15 PM
Return a return value from Perl to Javascript PvdK Perl 0 07-24-2003 09:20 AM



Advertisments