Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #26450
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Subject | Re: Calling Values |
| Date | 2012-08-03 13:20 -0400 |
| Organization | > Bestiaria Support Staff < |
| References | <8bdc29d5-fa88-4ead-a4a1-135d708eeb57@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2914.1344014492.4697.python-list@python.org> (permalink) |
On Fri, 3 Aug 2012 04:49:46 -0700 (PDT), Subhabrata
<subhabangalore@gmail.com> declaimed the following in
gmane.comp.python.general:
> Dear Group,
>
> I am trying to call the values of one function in the another function in the following way:
Technically, "the values of one function" are whatever it RETURNS;
> def func1():
> num1=10
> num2=20
> print "The Second Number is:",num2
> return
>
This function returns None.
Recommended software design practices are that any thing inside the
function should be local to just that function -- a function should be a
black box -- you call it with some data, and you obtain some results
when it returns; what it does internally should be "invisible" and have
no effect on any other code.
Read:
http://en.wikipedia.org/wiki/Coupling_%28computer_programming%29
(what you are attempting falls into "content coupling" if you change the
use of "module" to "function")
However, Python lets you declare names to be global (to the
module/file). This is primarily meant to be used when a function must
rebind a module level entity. (This would be "common coupling")
def func1():
global num1, num2
...
But, as mentioned, that now makes num1 and num2 names that are known
outside the functions.
> def func2():
> num3=num1+num2
> num4=num3+num1
> print "New Number One is:",num3
> print "New Number Two is:",num4
> return
>
Misleading print statements, as you are NOT changing "number one" or
"number two"; you've just created two NEW names (num3, num4).
> I am preferring not to use argument passing or using class? Is there any alternate way?
>
Well, if you end func1 with
return num1, num2
you can change func2 into:
def func2():
n1, n2 = func1()
num3 = n1 + n2
num4 = num3 + n1
...
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Calling Values Subhabrata <subhabangalore@gmail.com> - 2012-08-03 04:49 -0700
Re: Calling Values Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-08-03 13:07 +0100
Re: Calling Values Nobody <nobody@nowhere.com> - 2012-08-03 13:44 +0100
Re: Calling Values Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-08-03 14:32 +0200
Re: Calling Values subhabangalore@gmail.com - 2012-08-03 07:38 -0700
RE: Calling Values "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-08-03 15:30 +0000
Re: Calling Values Ethan Furman <ethan@stoneleaf.us> - 2012-08-03 08:37 -0700
Re: Calling Values Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-03 16:24 +0000
Re: Calling Values Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-08-03 13:20 -0400
Re: Calling Values subhabangalore@gmail.com - 2012-08-03 11:23 -0700
Re: Calling Values subhabangalore@gmail.com - 2012-08-03 11:23 -0700
Re: Calling Values alex23 <wuwei23@gmail.com> - 2012-08-05 19:56 -0700
csiph-web