Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #26440

RE: Calling Values

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ramit.prasad@jpmorgan.com>
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; 'completeness': 0.07; 'works.': 0.07; 'python': 0.09; 'etc).': 0.09; 'nameerror:': 0.09; 'received:155': 0.09; 'def': 0.10; '"new': 0.16; '24,': 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'from:addr:jpmorgan.com': 0.16; 'received:155.180': 0.16; 'received:159.53': 0.16; 'received:159.53.110': 0.16; 'received:bankone.net': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'received:svr.bankone.net': 0.16; 'run.': 0.16; 'say.': 0.16; 'securities,': 0.16; 'too?': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'to:name:python-list@python.org': 0.20; 'trying': 0.21; 'do.': 0.21; 'error.': 0.21; 'java': 0.21; 'defined': 0.22; 'work.': 0.23; '15,': 0.23; 'received:169.254': 0.24; 'second': 0.24; 'header:In-Reply-To:1': 0.25; 'values': 0.26; '(most': 0.27; 'question': 0.27; 'accuracy': 0.27; 'received:169': 0.29; '"the': 0.29; 'code': 0.31; 'file': 0.32; 'could': 0.32; 'print': 0.32; 'traceback': 0.33; 'to:addr:python- list': 0.33; 'languages': 0.33; 'there': 0.35; 'really': 0.36; 'charset:us-ascii': 0.36; 'enough': 0.36; 'does': 0.37; 'two': 0.37; 'why': 0.37; 'moment': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'shows': 0.38; 'to:addr:python.org': 0.39; 'help': 0.40; 'your': 0.60; 'lost': 0.60; 'skip:n 10': 0.63; 'information,': 0.63; 'url:email': 0.63; 'legal': 0.65; 'subject': 0.66; 'purchase': 0.67; 'manner': 0.74; 'sale': 0.76; 'received:169.254.8': 0.84; 'deal,': 0.93
X-DKIM OpenDKIM Filter v2.1.3 sj1.jpmchase.com q73FUrP0013344
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1344007853; bh=CdfvIf6XCr7N+ehUsKYjzonNUmD+PYgmO/Oz/PKQLSI=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=fD2e4Pt5qXxWrAZojNtTZgU+egFjhv5iaYS/qBim1rVtXOTP6YFbRjDrNWMhEkewS 6UE6uYLGkh3/zm0uF7OFZP9P47Dsij3HMyzpbnkX73M2vYMsoXZxD99J8QETs+kEMH M7gHRYp2ZNxFoCznoQxcy1cUrkIT5VRKpM7FWfZI=
From "Prasad, Ramit" <ramit.prasad@jpmorgan.com>
To "python-list@python.org" <python-list@python.org>
Subject RE: Calling Values
Thread-Topic Calling Values
Thread-Index AQHNcW7VBs0ox8ge90qUJzdZfp2XPpdIa4+A///JdbA=
Date Fri, 3 Aug 2012 15:30:41 +0000
References <8bdc29d5-fa88-4ead-a4a1-135d708eeb57@googlegroups.com> <21f0980d-10dc-4970-bace-8e909994fafd@googlegroups.com>
In-Reply-To <21f0980d-10dc-4970-bace-8e909994fafd@googlegroups.com>
Accept-Language en-US
Content-Language en-US
X-MS-Has-Attach
X-MS-TNEF-Correlator
x-originating-ip [10.67.79.47]
Content-Transfer-Encoding quoted-printable
MIME-Version 1.0
X-DLP-FWD Yes
Content-Type text/plain; charset="us-ascii"
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2908.1344007857.4697.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1344007857 news.xs4all.nl 6923 [2001:888:2000:d::a6]:41934
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:26440

Show key headers only | View raw


> def func1():
> 
>  	num1=10
> 
>  	num2=20
> 
>  	print "The Second Number is:",num2
> 
>  	return
> 
> 
> def func2():
> 
>         func1()
> 	num3=num1+num2
> 
>  	num4=num3+num1
> 
> 	print "New Number One is:",num3
> 
> 	print "New Number Two is:",num4
> 
> 
> This works. Even you can incoportate some conditionals over func1() in func2()
> and run.

This does not work. Python does not get "compiled" in the same manner
as other languages (C, Java etc). Since you never call func2(), there is no
error. Once you try calling func2() you will see it does not work. func1()
does work.

The Second Number is: 20
Traceback (most recent call last):
  File "subha.py", line 24, in <module>
    func2()
  File "subha.py", line 15, in func2
    num3=num1+num2
NameError: global name 'num1' is not defined

> My question can I call its values of func1() too?
> What it is the big deal in experimenting we may come up with some new code or
> a new need?

It is not a big deal, that is how you learn. You are just writing code that
neither works nor really shows enough to tell us why or what you are trying 
to do. Not much I can do to guide or help you because I am completely lost
at your goal. The best I can do at the moment is say. func2 will not work.
You could return num1 and num2 from func1() and then it would work.

def func1():
 	num1=10
 	num2=20
 	print "The Second Number is:",num2
 	return num1, num2


def func2():
       num1, num2 = func1()
	num3=num1+num2
 	num4=num3+num1
	print "New Number One is:",num3
	print "New Number Two is:",num4

    
func2()

Ramit
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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