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


Groups > comp.lang.python > #18653

Re: Calling a variable inside a function of another class

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: Calling a variable inside a function of another class
Date 2012-01-07 14:03 -0500
References <5a91e124-b6e9-4e2f-88d6-50a33eb496db@k29g2000vbl.googlegroups.com> <4f086c52$0$29966$c3e8da3$5496439d@news.astraweb.com> <dfaf55fe-c87a-4aed-83e3-b372bc0ead73@t13g2000vbt.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.4517.1325963033.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Sat, 7 Jan 2012 08:18:10 -0800 (PST), Yigit Turgut
<y.turgut@gmail.com> wrote:

>How about assigning the variable as global, wouldn't it be more
>effective?

	"global somename" only tells the Python interpreter that all
references WITHIN a function definition to "somename" really are
references to "somename" at the MODULE level. 


-=-=-=-=- amodule.py

name1 = 123
name2 = 456
name3 = 789

def afunc(x):
	global name1
	z = x + name1	#okay, it is using the module name1
	name1 = z		#still okay
	y = x + name2	#okay so far, will look up to the module level
	e = y + name3	#due to the next line, this will error
	name3 = e		#no global, name3 is local, and above is undefined
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

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


Thread

Calling a variable inside a function of another class Yigit Turgut <y.turgut@gmail.com> - 2012-01-07 07:00 -0800
  Re: Calling a variable inside a function of another class Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-07 16:01 +0000
    Re: Calling a variable inside a function of another class Yigit Turgut <y.turgut@gmail.com> - 2012-01-07 08:18 -0800
      Re: Calling a variable inside a function of another class Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-01-07 14:03 -0500
  Re: Calling a variable inside a function of another class Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-01-10 12:03 +0100
  Re: Calling a variable inside a function of another class Terry Reedy <tjreedy@udel.edu> - 2012-01-10 17:41 -0500

csiph-web