Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'argument': 0.04; 'say,': 0.05; 'mentioned,': 0.07; 'python': 0.09; 'friday,': 0.09; 'internally': 0.09; 'none.': 0.09; 'to:addr:comp.lang.python': 0.09; 'way:': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'aug': 0.13; 'steve': 0.13; 'passing': 0.15; 'slightly': 0.15; '"module"': 0.16; '"new': 0.16; 'function"': 0.16; 'read:': 0.16; 'statements,': 0.16; 'wrote:': 0.17; 'alternate': 0.17; '>>>': 0.18; 'module': 0.19; 'code.': 0.20; 'trying': 0.21; 'meant': 0.21; 'lets': 0.22; 'posted': 0.22; 'cc:2**0': 0.23; '(this': 0.24; 'cc:no real name:2**0': 0.24; 'second': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'url:wiki': 0.26; 'values': 0.26; 'coding': 0.27; 'functions.': 0.27; 'primarily': 0.27; 'went': 0.28; 'post': 0.28; 'attempting': 0.29; 'falls': 0.29; 'url:wikipedia': 0.29; 'way?': 0.29; 'no,': 0.29; '"the': 0.29; 'fri,': 0.30; 'function': 0.30; 'code': 0.31; 'print': 0.32; 'idle': 0.33; 'url:home': 0.33; 'wishes,': 0.33; 'recommended': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'wrong': 0.34; 'whatever': 0.35; 'data,': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'created': 0.36; 'wanted': 0.36; 'url:org': 0.36; 'should': 0.36; 'does': 0.37; 'level': 0.37; 'two': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'comment': 0.38; 'some': 0.38; 'nothing': 0.38; 'url:en': 0.38; 'received:209.85.214': 0.39; 'end': 0.40; 'think': 0.40; 'group,': 0.60; 'days': 0.60; 'from:no real name:2**0': 0.60; "you've": 0.61; 'skip:n 10': 0.63; 'results': 0.65; 'else.': 0.65; 'dear': 0.66; 'august': 0.66; 'enjoy': 0.67; 'url:%1': 0.68; 'answer.': 0.71; 'absolutely': 0.84; 'entity.': 0.84; 'evenings': 0.84; 'experiment': 0.84; 'received:209.85.214.184': 0.84; 'received:mail-ob0-f184.google.com': 0.84; 'dennis': 0.91; 'sorry.': 0.91 Newsgroups: comp.lang.python Date: Fri, 3 Aug 2012 11:23:58 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=122.161.236.224; posting-account=6SonuQoAAACzSakS5dCECcJQe6ylLrzY References: <8bdc29d5-fa88-4ead-a4a1-135d708eeb57@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 122.161.236.224 MIME-Version: 1.0 Subject: Re: Calling Values From: subhabangalore@gmail.com To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 166 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1344018241 news.xs4all.nl 6841 [2001:888:2000:d::a6]:36919 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26452 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 >=20 > declaimed the following in >=20 > gmane.comp.python.general: >=20 >=20 >=20 > > Dear Group, >=20 > >=20 >=20 > > I am trying to call the values of one function in the another function = in the following way: >=20 >=20 >=20 > Technically, "the values of one function" are whatever it RETURNS; >=20 >=20 >=20 > > def func1(): >=20 > > num1=3D10 >=20 > > num2=3D20 >=20 > > print "The Second Number is:",num2 >=20 > > return >=20 > > >=20 > This function returns None. >=20 >=20 >=20 > Recommended software design practices are that any thing inside the >=20 > function should be local to just that function -- a function should be a >=20 > black box -- you call it with some data, and you obtain some results >=20 > when it returns; what it does internally should be "invisible" and have >=20 > no effect on any other code. >=20 >=20 >=20 > Read: >=20 > http://en.wikipedia.org/wiki/Coupling_%28computer_programming%29 >=20 > (what you are attempting falls into "content coupling" if you change the >=20 > use of "module" to "function") >=20 >=20 >=20 > However, Python lets you declare names to be global (to the >=20 > module/file). This is primarily meant to be used when a function must >=20 > rebind a module level entity. (This would be "common coupling") >=20 >=20 >=20 > def func1(): >=20 > global num1, num2 >=20 > ... >=20 >=20 >=20 > But, as mentioned, that now makes num1 and num2 names that are known >=20 > outside the functions. >=20 > =20 >=20 > > def func2(): >=20 > > num3=3Dnum1+num2 >=20 > > num4=3Dnum3+num1 >=20 > > print "New Number One is:",num3 >=20 > > print "New Number Two is:",num4 >=20 > > return >=20 > >=20 >=20 > Misleading print statements, as you are NOT changing "number one" or >=20 > "number two"; you've just created two NEW names (num3, num4). >=20 >=20 >=20 > > I am preferring not to use argument passing or using class? Is there an= y alternate way? >=20 > > >=20 >=20 >=20 > Well, if you end func1 with >=20 >=20 >=20 > return num1, num2 >=20 >=20 >=20 > you can change func2 into: >=20 >=20 >=20 > def func2(): >=20 > n1, n2 =3D func1() >=20 > num3 =3D n1 + n2 >=20 > num4 =3D num3 + n1 >=20 > ... >=20 > --=20 >=20 > Wulfraed Dennis Lee Bieber AF6VN >=20 > wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/ Dear Group, Absolutely brilliant, Ramit. Dennis also came with almost same answer. Us= ing global may not give clean results everytime.=20 I wanted to say,=20 >>> def func1(): num1=3D10 num2=3D20 print "The Second Number is:",num2 =09 >>> def func2(): func1() num3=3D50 print "The New Number is:",num3 >>> func2() The Second Number is: 20 The New Number is: 50 The post went slightly wrong sorry.=20 No, I experiment myself on idle evenings to experiment with coding etc so I= think of problems, practice on them and try to see if any better code evol= ves. 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.=20