[Tutor] getting names from other funcs

Karl Pflästerer sigurd at 12move.de
Mon Mar 22 19:08:52 EST 2004


On 22 Mar 2004, kevin parks <- kp8 at mac.com wrote:

> I can't recall how you get to a name in another function. Let's say
> that i have a func called foo and it has certain variables and values
> held in it that i want to grab and use in test():


> def foo(seq):
>      '''foo -- makes foo of sequence'''
>      output = []
>      bob = 32768
>      fred = ['a', 6, 'yo mama', 'c']
>      return fred

> def test():
>      # how can i get access to the names bob and fred in here?

`foo()' should return fred and bob.  The alternative would be to use
global variabels which is seldom a good idea.

So you get:

def foo(seq):
    '''foo -- makes foo of sequence'''
    output = []
    bob = 32768
    fred = ['a', 6, 'yo mama', 'c']
    return fred, bob

def test():
    f, b = foo([])
    f.append(1)
    return f



   Karl
-- 
Please do *not* send copies of replies to me.
I read the list




More information about the Tutor mailing list