Question about functions
Terry Reedy
tjreedy at udel.edu
Fri Dec 26 09:57:01 EST 2003
More information about the Python-list mailing list
Fri Dec 26 09:57:01 EST 2003
- Previous message (by thread): Question about functions
- Next message (by thread): Socket Programming
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Aubrey Hutchison" <abhjrpe at comcast.net> wrote in message news:I_2dnalUksLsg3GiRVn-uA at comcast.com... > Question about functions: It is not clear what your question is. Some comments anyway: > 1)--- module "A" contains the following > X = 999666 #easy to notice value > Y = 111222 #easy to notice value > Product = 69696969 #easy to notice value Should this just be "Product = X*Y' ? > def DoSomething(): > global Product,X,Y global Product # is sufficient since X,Y are read only > Product = X*Y return X*Y # might be better > return 0 Omit: better to allow default return of None when there is no real return value > module imported I presume this is a comment missing # > from A import * and that this belongs with the toplevel code below. But you almost certainly do not want to import everything. 'import A' or 'from A import DoSomething'. > 2)--- toplevel code > > def Mult(): > global Product,X,Y omit since not used in this function > DoSomething(): > return 0 Again, no return. Better would simply be 'Mult = DoSomething' > """start of top level code """ > ... > ... > Product =Mult() > ... > print Product ( Result ----> print out is 69696...) > > Per "Python Nutshell" this appears to be the correct result. > How do you or can you modify the imported variables without using > classes objects? You have not used any class objects, so I do not understand question. In any case, you can only modify mutable objects. Otherwise, you can only rebind name in one namespace or another. You must keep module A namespace and main module namespace distinct in your mind since interpreter does. Terry J. Reedy > Aubrey > >
- Previous message (by thread): Question about functions
- Next message (by thread): Socket Programming
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list