Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Calling Values

Reply
Thread Tools

Calling Values

 
 
subhabangalore@gmail.com
Guest
Posts: n/a
 
      08-03-2012
On Friday, August 3, 2012 10:50:52 PM UTC+5:30, Dennis Lee Bieber wrote:
> On Fri, 3 Aug 2012 04:49:46 -0700 (PDT), Subhabrata
>
> <(E-Mail Removed)> 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/Couplin...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
>
> http://www.velocityreviews.com/forums/(E-Mail Removed) HTTP://wlfraed.home.netcom.com/


Dear Group,
Absolutely brilliant, Ramit. Dennis also came with almost same answer. Using global may not give clean results everytime.

I wanted to say,
>>> def func1():

num1=10
num2=20
print "The Second Number is:",num2


>>> def func2():

func1()
num3=50
print "The New Number is:",num3

>>> func2()

The Second Number is: 20
The New Number is: 50
The post went slightly wrong sorry.
No, I experiment myself on idle evenings to experiment with coding etc so Ithink of problems, practice on them and try to see if any better code evolves. Nothing else. I posted and Steve did not comment perhaps never happens.. He rebukes me so much from my early days here, I just enjoy it.

Regards and best wishes,
Subhabrata.


 
Reply With Quote
 
 
 
 
alex23
Guest
Posts: n/a
 
      08-06-2012
On Aug 3, 9:49*pm, Subhabrata <(E-Mail Removed)> wrote:
> I am preferring not to use argument passing or using class? Is there any alternate way?


If you don't want to program in Python, don't use Python.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
c++ calling java calling c++ ... Klaus Friese C++ 7 08-15-2005 09:23 PM
calling virtual function results in calling function of base class... Andreas Lagemann C++ 8 01-10-2005 11:03 PM
calling virtual function results in calling function of base class ... tiwy C++ 0 01-09-2005 11:17 PM
Calling FormsAuthentication.SignOut() after calling Response.Flush =?Utf-8?B?TWFydGluIExlZQ==?= ASP .Net 1 09-28-2004 12:47 PM
Server Side button calling page_load before calling it's own click event. Ryan Ternier ASP .Net 4 07-29-2004 01:06 PM



Advertisments