473,225 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,225 software developers and data experts.

Question about functions

Question about functions:

1)--- module "A" contains the following
X = 999666 #easy to notice value
Y = 111222 #easy to notice value
Product = 69696969 #easy to notice value

def DoSomething():
global Product,X,Y
Product = X*Y
return 0

module imported
from A import *

2)--- toplevel code

def Mult():
global Product,X,Y
DoSomething():
return 0

"""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?

Aubrey
Jul 18 '05 #1
2 1328
Hi,
don't use the form "from A import"
instead use the form " import A" and then use A.Product to modify the
"Product" variable.
Ahmed

"Aubrey Hutchison" <ab*****@comcast.net> wrote in message
news:I_********************@comcast.com...
Question about functions:

1)--- module "A" contains the following
X = 999666 #easy to notice value
Y = 111222 #easy to notice value
Product = 69696969 #easy to notice value

def DoSomething():
global Product,X,Y
Product = X*Y
return 0

module imported
from A import *

2)--- toplevel code

def Mult():
global Product,X,Y
DoSomething():
return 0

"""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?

Aubrey

Jul 18 '05 #2

"Aubrey Hutchison" <ab*****@comcast.net> wrote in message
news:I_********************@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

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

55
by: ben | last post by:
is it true that a function without an inline keyword never get inlined? If not true when is it inlined or not? ben
3
by: Roman Mashak | last post by:
Hello, All! As far as I understand, function declaration with 'static' keyword limits the access to these functions within the file where it declared. So, my question is: where can it be used in...
6
by: rodchar | last post by:
Hey all, I'm trying to understand Master/Detail concepts in VB.NET. If I do a data adapter fill for both customer and orders from Northwind where should that dataset live? What client is...
5
by: Urs Beeli | last post by:
I have a question regarding errno. If I understand it correctly, including <errno.h> allows me to check "errno" for error values that some standard library functions may set. This brings up some...
12
by: Bryan Parkoff | last post by:
I write my large project in C++ source code. My C++ source code contains approximate four thousand small functions. Most of them are inline. I define variables and functions in the global scope....
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.