Carrying variables over from function to function

Ivan Shevanski darkpaladin79 at hotmail.com
Mon Sep 26 01:41:38 CEST 2005


Alright heres my problem. . .Say I want to carry over a variable from one 
function to another or even another run of the same function. Is that 
possible? Heres a quick example of what I'm talking about.

def abc():
    x = 1
    y = x + 1
    print y

def abcd():
    y = x + 1
    print y

abc()
abcd()

the output would be:

>>>abc()
2
>>>abcd()
Traceback (most recent call last):
    File "(stdin)", line 1, in ?
    File "(stdin)", line 2, in abcd
NameError: global name 'x' is not defined
>>>




See, I want y in the second function to equal 4, carrying the x from the 
first function over to the next.  Is there any way to do this?



-Ivan

_________________________________________________________________
Don’t just search. Find. Check out the new MSN Search! 
http://search.msn.click-url.com/go/onm00200636ave/direct/01/




More information about the Python-list mailing list