ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Re: Assigning to global variables from within a function
by Tom Plunket other posts by this author
Jul 12 2003 8:49PM messages near this date
Re: Assigning to global variables from within a function | Re: Assigning to global variables from within a function
Psymaster wrote:

>  I want to do this:
>  
>  int= 0
>  
>  def change_int():
>      	int += 1
>  
>  change_int()

You shouldn't do that, 'int' is a built-in name.  Additionally,
you need to tell the function that the variable is a global one.

my_int = 0
def change_int():
    global my_int
    my_int += 1

change_int()

You'll find that it works fine.

-tom!
-- 
http://mail.python.org/mailman/listinfo/python-list
Thread:
Psymaster
Irmen de Jong
Psymaster
Tom Plunket
W Isaac Carroll

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved