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-Tutor
python-Tutor
RE: [Tutor] Re: Newbie OOP Question. (diff between function, modu le and class)
by other posts by this author
Jun 11 2002 1:16PM messages near this date
RE: [Tutor] loop problem | RE: [Tutor] Re: Newbie OOP Question. (diff between function, modu le and class)
>  > system doesn't have a syntax for referring to the current 
>  module's parent
>  > (no "..").
>  Ahh. Now that may prove interesting. Would it be beneficial to make a
>  reserved command like .. That pops you back into the parent namespace?

There is sort of its the global statement:

z = 42

def f(x):
   z = 2*x
   return z

This creates a new z with value twice x.
If we really want to access the external(global z) we can do 
so like this:

def f(x):
   global z
   z = 2*x
   return z

Now we modify the external z instead of creating a new one.
Generally this is a bad idea and you should pass the value 
into the function for modification:

def f(x,y):
   y = 2*x
   return y

But this still doesn't change the global z even if we pass 
it in as y, we have to assign the result:

z = f(5,z)

This now modifies global z asnd makes its value available 
to the function(as the parameter y).

HTH,

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld


_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:

Skip Montanaro

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