Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'argument': 0.04; 'mentioned,': 0.07; 'python': 0.09; 'internally': 0.09; 'none.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'way:': 0.09; 'def': 0.10; 'aug': 0.13; 'passing': 0.15; '"module"': 0.16; '"new': 0.16; 'function"': 0.16; 'read:': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'statements,': 0.16; 'alternate': 0.17; 'module': 0.19; 'code.': 0.20; 'trying': 0.21; 'meant': 0.21; 'lets': 0.22; '(this': 0.24; 'second': 0.24; 'url:wiki': 0.26; 'values': 0.26; 'functions.': 0.27; 'primarily': 0.27; 'header:X-Complaints-To:1': 0.28; 'attempting': 0.29; 'falls': 0.29; 'url:wikipedia': 0.29; 'way?': 0.29; '"the': 0.29; 'fri,': 0.30; 'function': 0.30; 'print': 0.32; 'url:home': 0.33; 'to:addr:python-list': 0.33; 'recommended': 0.33; 'another': 0.33; 'whatever': 0.35; 'data,': 0.35; 'there': 0.35; 'received:org': 0.36; 'created': 0.36; 'url:org': 0.36; 'should': 0.36; 'charset:us-ascii': 0.36; 'does': 0.37; 'level': 0.37; 'two': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'url:en': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'end': 0.40; 'group,': 0.60; "you've": 0.61; 'skip:n 10': 0.63; 'results': 0.65; 'dear': 0.66; 'url:%1': 0.68; 'entity.': 0.84; 'dennis': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: Calling Values Date: Fri, 03 Aug 2012 13:20:52 -0400 Organization: > Bestiaria Support Staff < References: <8bdc29d5-fa88-4ead-a4a1-135d708eeb57@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-76-249-27-6.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES 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: , Newsgroups: comp.lang.python Message-ID: Lines: 68 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1344014492 news.xs4all.nl 6952 [2001:888:2000:d::a6]:53149 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26450 On Fri, 3 Aug 2012 04:49:46 -0700 (PDT), Subhabrata 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/