Carrying variables over from function to function

Ivan Shevanski darkpaladin79 at
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


the output would be:

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?


Don’t just search. Find. Check out the new MSN Search!

More information about the Python-list mailing list