Re: Variables visibility for methods

2016-09-01 Thread juraseg
среда, 31 августа 2016 г., 14:09:16 UTC+7 пользователь ast написал: > Hello > > I made few experiments about variables visibility > for methods. > > class MyClass: > a = 1 > def test(self): > print(a) > > obj = MyClass() > obj.test() > > Traceback (most recent call last): > Fi

Re: Variables visibility for methods

2016-08-31 Thread vern . muhr
On Wednesday, August 31, 2016 at 12:09:16 AM UTC-7, ast wrote: > Hello > > I made few experiments about variables visibility > for methods. > > class MyClass: > a = 1 > def test(self): > print(a) > > obj = MyClass() > obj.test() > > Traceback (most recent call last): > File ""

Re: Variables visibility for methods

2016-08-31 Thread ast
"dieter" a écrit dans le message de news:mailman.63.1472630594.24387.python-l...@python.org... "ast" writes: You are right. And it is documented this way. Thank you -- https://mail.python.org/mailman/listinfo/python-list

Re: Variables visibility for methods

2016-08-31 Thread dieter
"ast" writes: > ... > So it seems that when an object's méthod is executed, variables > in the scope outside the object's class can be read (2nd example), > but not variables inside the class (1st example). > > For 1st example, I know that print(MyClass.a) or print(self.a) > would have work. > > A

Re: Variables in a loop, Newby question

2013-12-27 Thread vanommen . robert
Op dinsdag 24 december 2013 17:23:43 UTC+1 schreef Jean-Michel Pichavant: > - Original Message - > > Hello, for the first time I'm trying te create a little Python > > program. (on a raspberri Pi) > > > > I don't understand the handling of variables in a loop with Python. > > > > > > Let

Re: Variables in a loop, Newby question

2013-12-27 Thread vanommen . robert
Hello everyone, I have been away for a while. I have been reading all the good advises and want to explain why I want to read the temperatures separately from the main script. It takes a long time to read out 10 temperatures. About 10 seconds. So that’s the reason why I had the idea to create a

Re: Variables in a loop, Newby question

2013-12-26 Thread Chris Angelico
On Thu, Dec 26, 2013 at 7:14 PM, Dave Angel wrote: > On Thu, 26 Dec 2013 16:41:57 +1100, Steven D'Aprano > wrote: >> >> Chris Angelico wrote: >> > Does anyone else have the vague feeling that the OP's problem > might be >> > better served by simply importing the script (thus making those > values

Re: Variables in a loop, Newby question

2013-12-26 Thread Dave Angel
On Thu, 26 Dec 2013 16:41:57 +1100, Steven D'Aprano wrote: Chris Angelico wrote: > Does anyone else have the vague feeling that the OP's problem might be > better served by simply importing the script (thus making those values > available to another Python script) than by any of these rat

Re: Variables in a loop, Newby question

2013-12-25 Thread Michael Torrie
On 12/24/2013 11:27 AM, vanommen.rob...@gmail.com wrote: > Indeed this is code what I found on the web to read temperatures from > 10 DS18B20 singlewire sensors. > > My only programming (little) experience is VBA (Excel mostly). > Definitely you'll want to learn python before you go much farther

Re: Variables in a loop, Newby question

2013-12-25 Thread Steven D'Aprano
Chris Angelico wrote: > Does anyone else have the vague feeling that the OP's problem might be > better served by simply importing the script (thus making those values > available to another Python script) than by any of these rather more > complicated theories? Damn yes! -- Steven -- https

Re: Variables in a loop, Newby question

2013-12-25 Thread Chris Angelico
On Thu, Dec 26, 2013 at 12:01 PM, Cameron Simpson wrote: > On 25Dec2013 15:27, Denis McMahon wrote: >> On Wed, 25 Dec 2013 16:42:47 +1100, Cameron Simpson wrote: >> > On 25Dec2013 02:54, Denis McMahon wrote: >> >> On Tue, 24 Dec 2013 10:27:13 -0800, vanommen.robert wrote: >> >> > In this script

Re: Variables in a loop, Newby question

2013-12-25 Thread Cameron Simpson
On 25Dec2013 15:27, Denis McMahon wrote: > On Wed, 25 Dec 2013 16:42:47 +1100, Cameron Simpson wrote: > > On 25Dec2013 02:54, Denis McMahon wrote: > >> On Tue, 24 Dec 2013 10:27:13 -0800, vanommen.robert wrote: > >> > In this script i want to read the temperatures and make them > >> > available t

Re: Variables in a loop, Newby question

2013-12-25 Thread Denis McMahon
On Wed, 25 Dec 2013 16:42:47 +1100, Cameron Simpson wrote: > On 25Dec2013 02:54, Denis McMahon wrote: >> On Tue, 24 Dec 2013 10:27:13 -0800, vanommen.robert wrote: >> > In this script i want to read the temperatures and make them >> > available to other scripts. [...] >> If you want this process

Re: Variables in a loop, Newby question

2013-12-25 Thread Peter Otten
vanommen.rob...@gmail.com wrote: > Indeed this is code what I found on the web to read temperatures from 10 > DS18B20 singlewire sensors. > > My only programming (little) experience is VBA (Excel mostly). > > avgtemperatures = [] is indeed from the original code where this line > > 'avgtemperat

Re: Variables in a loop, Newby question

2013-12-25 Thread Larry Hudson
On 12/24/2013 08:07 AM, vanommen.rob...@gmail.com wrote: [snip...] x = 1 while x <> 10 var x = x x = x + 1 [snip...] Besides the other valid answers you have received, I want to add one other minor nit. The symbol <> for unequal is deprecated -- it's better to use != instead.

Re: Variables in a loop, Newby question

2013-12-24 Thread Cameron Simpson
On 25Dec2013 02:54, Denis McMahon wrote: > On Tue, 24 Dec 2013 10:27:13 -0800, vanommen.robert wrote: > > In this script i want to read the temperatures and make them available > > to other scripts. [...] > If you want this process to provide data to other processes, you might > want to look at u

Re: Variables in a loop, Newby question

2013-12-24 Thread Denis McMahon
On Tue, 24 Dec 2013 10:27:13 -0800, vanommen.robert wrote: > In this script i want to read the temperatures and make them available > to other scripts. The "global" keyword doesn't do that. "global" is used inside a function definition in python to tell the function that it is working with a gl

Re: Variables in a loop, Newby question

2013-12-24 Thread Dave Angel
On Tue, 24 Dec 2013 09:54:48 -0800 (PST), vanommen.rob...@gmail.com wrote: You should always start by mentioning python version and o.s. import time global Sens_Raw1, Sens_Raw2, Sens_Raw3, Sens_Raw4, Sens_Raw5, Sens_Raw6, Sens_Raw7, Sens_Raw8, Sens_Raw9, Sens_Raw10 The global statement make

Re: Variables in a loop, Newby question

2013-12-24 Thread vanommen . robert
Indeed this is code what I found on the web to read temperatures from 10 DS18B20 singlewire sensors. My only programming (little) experience is VBA (Excel mostly). avgtemperatures = [] is indeed from the original code where this line 'avgtemperatures.append(sum(temperatures) / float(len(temper

Re: Variables in a loop, Newby question

2013-12-24 Thread Joel Goldstick
On Tue, Dec 24, 2013 at 12:54 PM, wrote: > import time > global Sens_Raw1, Sens_Raw2, Sens_Raw3, Sens_Raw4, Sens_Raw5, Sens_Raw6, > Sens_Raw7, Sens_Raw8, Sens_Raw9, Sens_Raw10 > while True: > sensorids = ["28-054c4932", "28-054c9454", > "28-054c9fca", "28-054c4401", "28-00

Re: Variables in a loop, Newby question

2013-12-24 Thread vanommen . robert
import time global Sens_Raw1, Sens_Raw2, Sens_Raw3, Sens_Raw4, Sens_Raw5, Sens_Raw6, Sens_Raw7, Sens_Raw8, Sens_Raw9, Sens_Raw10 while True: sensorids = ["28-054c4932", "28-054c9454", "28-054c9fca", "28-054c4401", "28-054dab99", "28-054cf9b4", "28-054c8a03", "

Re: Variables in a loop, Newby question

2013-12-24 Thread bob gailer
On 12/24/2013 11:07 AM, vanommen.rob...@gmail.com wrote: Hello, for the first time I'm trying te create a little Python program. (on a raspberri Pi) I don't understand the handling of variables in a loop with Python. Lets say i want something like this. x = 1 while x <> 10 var x = x

Re: Variables in a loop, Newby question

2013-12-24 Thread Peter Otten
vanommen.rob...@gmail.com wrote: > Hello, for the first time I'm trying te create a little Python program. > (on a raspberri Pi) > > I don't understand the handling of variables in a loop with Python. > > > Lets say i want something like this. > > x = 1 > while x <> 10 > var x = x > x = x + 1

Re: Variables in a loop, Newby question

2013-12-24 Thread Tobias M.
On 24.12.2013 17:07, vanommen.rob...@gmail.com wrote: Hello, for the first time I'm trying te create a little Python program. (on a raspberri Pi) I don't understand the handling of variables in a loop with Python. Lets say i want something like this. x = 1 while x <> 10 var x = x

Re: Variables in a loop, Newby question

2013-12-24 Thread Jean-Michel Pichavant
- Original Message - > Hello, for the first time I'm trying te create a little Python > program. (on a raspberri Pi) > > I don't understand the handling of variables in a loop with Python. > > > Lets say i want something like this. > > x = 1 > while x <> 10 > var x = x > x =

Re: Variables in a loop, Newby question

2013-12-24 Thread Joel Goldstick
On Tue, Dec 24, 2013 at 11:07 AM, wrote: > Hello, for the first time I'm trying te create a little Python program. > (on a raspberri Pi) > > I don't understand the handling of variables in a loop with Python. > > > Lets say i want something like this. > > x = 1 > while x <> 10 > var x = x

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-26 Thread 88888 Dihedral
Michael Torrie於 2013年6月20日星期四UTC+8下午2時01分11秒寫道: > > But since the LISP never really got a form beyond S-expressions, > > leaving us with lots of parenthesis everywhere, Python wins much as the > > Hitchhiker's Guide to the Galaxy wins. Yep, a list is mutable even it's empty. But constant integ

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-20 Thread Roel Schroeven
Νίκος schreef: Στις 18/6/2013 12:05 μμ, ο/η Steven D'Aprano έγραψε: Names are *always* linked to objects, not to other names. a = [] b = a # Now a and b refer to the same list a = {} # Now a refers to a dict, and b refers to the same list as before I see, thank you Steven. But since this is

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-19 Thread Michael Torrie
On 06/19/2013 11:48 PM, Steven D'Aprano wrote: > On Wed, 19 Jun 2013 23:16:51 -0600, Michael Torrie wrote: > >> The real power and expressivity of Python comes from embracing the >> abstractions that Python provides to your advantage. There's a certain >> elegance and beauty that comes from such

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-19 Thread Steven D'Aprano
On Wed, 19 Jun 2013 23:16:51 -0600, Michael Torrie wrote: > The real power and expressivity of Python comes from embracing the > abstractions that Python provides to your advantage. There's a certain > elegance and beauty that comes from such things, which I believe really > comes from the elegan

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-19 Thread Michael Torrie
On 06/19/2013 11:16 PM, Michael Torrie wrote: > It turns out that lists, hashes (dicts), and classes can pretty much > do anything with having to much about with C-style pointers and > such. Oh wow. Parse error. should read, "pretty much do anything without having to muck about with C-style point

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-19 Thread Michael Torrie
On 06/18/2013 03:51 AM, Νίκος wrote: > Στις 18/6/2013 12:05 μμ, ο/η Steven D'Aprano έγραψε: >> Names are *always* linked to objects, not to other names. >> >> a = [] >> b = a # Now a and b refer to the same list >> a = {} # Now a refers to a dict, and b refers to the same list as before > > I see

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-18 Thread Chris Angelico
On Tue, Jun 18, 2013 at 7:51 PM, Νίκος wrote: > Στις 18/6/2013 12:05 μμ, ο/η Steven D'Aprano έγραψε: > >> Names are *always* linked to objects, not to other names. >> >> a = [] >> b = a # Now a and b refer to the same list >> a = {} # Now a refers to a dict, and b refers to the same list as befor

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-18 Thread Νίκος
Στις 18/6/2013 12:05 μμ, ο/η Steven D'Aprano έγραψε: Names are *always* linked to objects, not to other names. a = [] b = a # Now a and b refer to the same list a = {} # Now a refers to a dict, and b refers to the same list as before I see, thank you Steven. But since this is a fact how do y

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-18 Thread Steven D'Aprano
On Tue, 18 Jun 2013 11:49:36 +0300, Νίκος wrote: > Στις 18/6/2013 9:39 πμ, ο/η Larry Hudson έγραψε: >> Not quite: a and b _are_ memory addresses, At the same time, a and b >> are references to the data (the objects) stored in those memory >> locations. >> >> The distinction is probably more impo

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-18 Thread Νίκος
Στις 18/6/2013 9:39 πμ, ο/η Larry Hudson έγραψε: Not quite: a and b _are_ memory addresses, At the same time, a and b are references to the data (the objects) stored in those memory locations. The distinction is probably more important in languages like C/C++, where the _language_ gives you di

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-18 Thread Steven D'Aprano
On Mon, 17 Jun 2013 23:39:10 -0700, Larry Hudson wrote: > On 06/17/2013 08:50 AM, Simpleton wrote: >> On 17/6/2013 2:58 μμ, Michael Torrie wrote: >> >> a = 5 >> b = a >> >> a <---> memory address >> b <---> memory address >> >> I like to think a and b as references to the same memory address >> >

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-17 Thread Larry Hudson
On 06/17/2013 08:50 AM, Simpleton wrote: On 17/6/2013 2:58 μμ, Michael Torrie wrote: a = 5 b = a a <---> memory address b <---> memory address I like to think a and b as references to the same memory address Not quite: a and b _are_ memory addresses, At the same time, a and b are references

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-17 Thread Steven D'Aprano
On Tue, 18 Jun 2013 00:12:34 -0400, Dave Angel wrote: > On 06/17/2013 10:42 PM, Steven D'Aprano wrote: >> On Mon, 17 Jun 2013 21:06:57 -0400, Dave Angel wrote: >> >>> On 06/17/2013 08:41 PM, Steven D'Aprano wrote: In Python 3.2 and older, the data will be either UTF-4 or

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-17 Thread Dave Angel
On 06/17/2013 10:42 PM, Steven D'Aprano wrote: On Mon, 17 Jun 2013 21:06:57 -0400, Dave Angel wrote: On 06/17/2013 08:41 PM, Steven D'Aprano wrote: In Python 3.2 and older, the data will be either UTF-4 or UTF-8, selected when the Python compiler itself is compiled. I think that was

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-17 Thread Marcin Szamotulski
> While you said to me to forget about memory locations, and that's indeed > made things easy to follow i still keep wondering, how Python internally > keeping tracks of 'x' and 'y' names as well as their referenced objects > (i.e. number 6). There is an excellent blog post about CPython intern

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-17 Thread Steven D'Aprano
On Tue, 18 Jun 2013 02:38:20 +, Steven D'Aprano wrote: > On Tue, 18 Jun 2013 00:41:53 +, Steven D'Aprano wrote: > >> In Python 3.2 and older, the data will be either UTF-4 or UTF-8, >> selected when the Python compiler itself is compiled. In Python 3.3, >> the data will be stored in eithe

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-17 Thread Steven D'Aprano
On Mon, 17 Jun 2013 21:06:57 -0400, Dave Angel wrote: > On 06/17/2013 08:41 PM, Steven D'Aprano wrote: >> >> >> >> In Python 3.2 and older, the data will be either UTF-4 or UTF-8, >> selected when the Python compiler itself is compiled. > > I think that was a typo. Do you perhaps UCS-2 or U

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-17 Thread Steven D'Aprano
On Tue, 18 Jun 2013 00:41:53 +, Steven D'Aprano wrote: > In Python 3.2 and older, the data will be either UTF-4 or UTF-8, > selected when the Python compiler itself is compiled. In Python 3.3, the > data will be stored in either Latin-1, UTF-4, or UTF-8, depending on the > contents of the stri

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-17 Thread Dave Angel
On 06/17/2013 08:41 PM, Steven D'Aprano wrote: In Python 3.2 and older, the data will be either UTF-4 or UTF-8, selected when the Python compiler itself is compiled. I think that was a typo. Do you perhaps UCS-2 or UCS-4 In Python 3.3, the data will be stored in either Latin-1, UTF-4,

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-17 Thread Steven D'Aprano
On Tue, 18 Jun 2013 02:26:39 +0300, Νίκος wrote: > Στις 18/6/2013 2:09 πμ, ο/η Steven D'Aprano έγραψε: >> {"a": "Hello world"} >> >> Do you see a memory location there? There is no memory location. There >> is the name, "a", and the object it is associated with, "Hello world". >> Either the dict,

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-17 Thread Νίκος
Στις 18/6/2013 2:09 πμ, ο/η Steven D'Aprano έγραψε: {"a": "Hello world"} Do you see a memory location there? There is no memory location. There is the name, "a", and the object it is associated with, "Hello world". Either the dict, or the string, may move around memory if the underlying memory m

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-17 Thread Steven D'Aprano
On Mon, 17 Jun 2013 14:34:57 +0300, Simpleton wrote: > On 17/6/2013 9:51 πμ, Steven D'Aprano wrote: >> Now, in languages like Python, Ruby, Java, and many others, there is no >> table of memory addresses. Instead, there is a namespace, which is an >> association between some name and some value: >

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-17 Thread Terry Reedy
On 6/17/2013 1:17 PM, Νίκος wrote: On Mon, Jun 17, 2013 at 8:55 AM, Simpleton wrote: On 17/6/2013 5:22 μμ, Terry Reedy wrote: When you interpret Python code, do you put data in locations with integer addresses? I lost you here. Memory in biological brains is not a linear series of bits,

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-17 Thread Νίκος
On 17/6/2013 7:23 μμ, Benjamin Kaplan wrote: On Mon, Jun 17, 2013 at 8:55 AM, Simpleton wrote: On 17/6/2013 5:22 μμ, Terry Reedy wrote: On 6/17/2013 7:34 AM, Simpleton wrote: On 17/6/2013 9:51 πμ, Steven D'Aprano wrote: Now, in languages like Python, Ruby, Java, and many others, there is

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-17 Thread Benjamin Kaplan
On Mon, Jun 17, 2013 at 8:55 AM, Simpleton wrote: > On 17/6/2013 5:22 μμ, Terry Reedy wrote: >> >> On 6/17/2013 7:34 AM, Simpleton wrote: >>> >>> On 17/6/2013 9:51 πμ, Steven D'Aprano wrote: Now, in languages like Python, Ruby, Java, and many others, there is no table of memory addr

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-17 Thread Joel Goldstick
On Mon, Jun 17, 2013 at 11:55 AM, Simpleton wrote: > On 17/6/2013 5:22 μμ, Terry Reedy wrote: > >> On 6/17/2013 7:34 AM, Simpleton wrote: >> >>> On 17/6/2013 9:51 πμ, Steven D'Aprano wrote: >>> Now, in languages like Python, Ruby, Java, and many others, there is no table of memory addre

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-17 Thread Simpleton
On 17/6/2013 5:22 μμ, Terry Reedy wrote: On 6/17/2013 7:34 AM, Simpleton wrote: On 17/6/2013 9:51 πμ, Steven D'Aprano wrote: Now, in languages like Python, Ruby, Java, and many others, there is no table of memory addresses. Instead, there is a namespace, which is an association between some nam

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-17 Thread Simpleton
On 17/6/2013 2:58 μμ, Michael Torrie wrote: In python just think of assignment as making a name *be* an object. And if you assign one name to another name, that makes both names be the same object. When names are unbound (either they go out of scope or you manually unbind them), the objects the

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-17 Thread Terry Reedy
On 6/17/2013 7:34 AM, Simpleton wrote: On 17/6/2013 9:51 πμ, Steven D'Aprano wrote: Now, in languages like Python, Ruby, Java, and many others, there is no table of memory addresses. Instead, there is a namespace, which is an association between some name and some value: global namespace:

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-17 Thread Michael Torrie
On 06/17/2013 05:34 AM, Simpleton wrote: > So is it safe to say that in Python a == &a ? (& stands for memory address) > > is the above correct? It might be partially equivalent inside the interpreter, but it's not something you should concern yourself with. And in general, no it's not safe to s

Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

2013-06-17 Thread Simpleton
On 17/6/2013 9:51 πμ, Steven D'Aprano wrote: Now, in languages like Python, Ruby, Java, and many others, there is no table of memory addresses. Instead, there is a namespace, which is an association between some name and some value: global namespace: x --> 23 y --> "hello world" Firs

Re: Variables vs names

2012-08-24 Thread Ben Finney
Steven D'Aprano writes: > On Thu, 23 Aug 2012 14:22:08 -0500, Evan Driscoll wrote: > > > In [the hypothetical language] Python--, any time you use a name, > > you have to prefix it with the word 'variable': > > variable x = 4 > > print(variable x) > > > > Does Python-- have variables? > > O

Re: Variables vs names [was: Objects in Python]

2012-08-24 Thread Steven D'Aprano
On Thu, 23 Aug 2012 14:22:08 -0500, Evan Driscoll wrote: > On 08/23/2012 12:56 PM, Steven D'Aprano wrote: >> On Thu, 23 Aug 2012 12:17:03 -0500, Evan Driscoll wrote: >> >>> I definitely *wouldn't* say "Python >>> classes aren't really classes" -- even though (I assert) Python >>> classes are *far

Re: Variables vs names [was: Objects in Python]

2012-08-23 Thread Chris Angelico
On Fri, Aug 24, 2012 at 5:22 AM, Evan Driscoll wrote: > In Python--, any time you use a name, you have to prefix it with the > word 'variable': > variable x = 4 > print(variable x) That gets really unwieldy. You should shorten it to a single symbol. And your language could be called Python Hy

Re: Variables with cross-module usage

2009-11-30 Thread Lie Ryan
On 12/1/2009 7:51 AM, Terry Reedy wrote: In everyday life and natural languages, a single name can be used to refer to multiple objects just by context without referring any namespace. Namespace are contexts. They were (re)invented in programming just to make it easier to have single name could

Re: Variables with cross-module usage

2009-11-30 Thread Terry Reedy
Lie Ryan wrote: On 11/30/2009 12:00 PM, Terry Reedy wrote: Dennis Lee Bieber wrote: In these languages, the names always refer to the same location. Python confuses matters by having names that don't really refer to location, but are attached to the objects. In everyday life and natural lang

Re: Variables with cross-module usage

2009-11-29 Thread Lie Ryan
On 11/30/2009 12:00 PM, Terry Reedy wrote: Dennis Lee Bieber wrote: In these languages, the names always refer to the same location. Python confuses matters by having names that don't really refer to location, but are attached to the objects. In everyday life and natural languages, names refe

Re: Variables with cross-module usage

2009-11-29 Thread Terry Reedy
Dennis Lee Bieber wrote: In these languages, the names always refer to the same location. Python confuses matters by having names that don't really refer to location, but are attached to the objects. In everyday life and natural languages, names refer to people, other objects, roles,

Re: Variables with cross-module usage

2009-11-29 Thread Nitin Changlani.
Thanks Dennis and Steve, This explains it all! I will discard using one.a and use one.myList[0] directly, instead. I really appreciate your patience and the elaboration of the concept. Warm Regards, Nitin Changlani. On Sun, Nov 29, 2009 at 1:02 AM, Steven D'Aprano < st...@remove-this-cybersource

Re: Variables with cross-module usage

2009-11-28 Thread Steven D'Aprano
On Sat, 28 Nov 2009 22:18:11 -0500, Nitin Changlani wrote: > Thanks for the reply MRAB, Rami, Matt and Mel, > > I was assuming that since one.myList0] = one.a, the change in one.a will > ultimately trickle down to myList[0] whenever myList[0] is printed or > used in an expression. It doesn't come

Re: Variables with cross-module usage

2009-11-28 Thread Nitin Changlani
Thanks for the reply MRAB, Rami, Matt and Mel, I was assuming that since one.myList0] = one.a, the change in one.a will ultimately trickle down to myList[0] whenever myList[0] is printed or used in an expression. It doesn't come intuitively to me as to why that should not happen. Can you kindly su

Re: Variables with cross-module usage

2009-11-28 Thread Nitin Changlani.
Thanks for the reply MRAB, Rami, Matt and Mel, I was assuming that since one.myList0] = one.a, the change in one.a will ultimately trickle down to myList[0] whenever myList[0] is printed or used in an expression. It doesn't come intuitively to me as to why that should not happen. Can you kindly su

Re: Variables with cross-module usage

2009-11-28 Thread Mel
Rami Chowdhury wrote: > Hi Nitin, > > On Sat, Nov 28, 2009 at 14:36, MRAB wrote: >> Nitin Changlani. wrote: >>> three.py >>> >>> import one >>> import two >>> >>> def argFunc(): >>> one.x = 'place_no_x' >>> one.a = 'place_no_a' >>> one.b = 'place_no_b' >>> > > I think this is what

Re: Variables with cross-module usage

2009-11-28 Thread Rami Chowdhury
Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) On Sat, Nov 28, 2009 at 14:57, Matt Nordhoff wrote: > Rami Chowdhury wrote: >> Hi Nitin, >> >> On Sat, Nov 28, 2009 at 14:36, MRAB wrote: >>> N

Re: Variables with cross-module usage

2009-11-28 Thread Matt Nordhoff
Rami Chowdhury wrote: > Hi Nitin, > > On Sat, Nov 28, 2009 at 14:36, MRAB wrote: >> Nitin Changlani. wrote: >>> three.py >>> >>> import one >>> import two >>> >>> def argFunc(): >>>one.x = 'place_no_x' >>>one.a = 'place_no_a' >>>one.b = 'place_no_b' >>> > > I think this

Re: Variables with cross-module usage

2009-11-28 Thread Rami Chowdhury
Hi Nitin, On Sat, Nov 28, 2009 at 14:36, MRAB wrote: > Nitin Changlani. wrote: >> three.py >> >> import one >> import two >> >> def argFunc(): >>    one.x = 'place_no_x' >>    one.a = 'place_no_a' >>    one.b = 'place_no_b' >> I think this is what is biting you. You might expect tha

Re: Variables with cross-module usage

2009-11-28 Thread MRAB
Nitin Changlani. wrote: Hello everyone, I am fairly new to Python and occasionally run into problems that are almost always resolved by referring to this mailing-list's archives. However, I have this one issue which has got me stuck and I hope you will be tolerant enough to help em out with i

Re: Variables vs attributes

2009-09-12 Thread Steven D'Aprano
On Sat, 12 Sep 2009 00:39:17 -0700, Miles Kaufmann wrote: > On Apr 17, 2009, at 8:56 PM, Steven D'Aprano wrote: >> If an integer variable is an integer, and a string variable is a >> string, >> and float variable is a float, and a list variable is a list (there's a >> pattern here), shouldn't a cl

Re: Variables vs attributes

2009-09-12 Thread Miles Kaufmann
On Apr 17, 2009, at 8:56 PM, Steven D'Aprano wrote: If an integer variable is an integer, and a string variable is a string, and float variable is a float, and a list variable is a list (there's a pattern here), shouldn't a class variable be a class and an instance variable be an instance? I

Re: variables of the class are not available as default values?

2009-08-28 Thread Aahz
In article , Chris Rebert wrote: > >class foo: >def __init__(self, maxvalue): >self.maxvalue =3D maxvalue >self.value =3D 0 > >def put(self, value=3DNone): >self.value =3D self.value if value is None else value Stylistic nit: I'd make that self.value = v

Re: variables of the class are not available as default values?

2009-08-28 Thread Bruno Desthuilliers
Chris Rebert a écrit : (snip) Default values are only evaluated once, when the class is defined, s/class/function/ The function objects (defined in a class statement body...) are created before the class object itself. thus "self" is not defined at that point since the class is still

Re: variables of the class are not available as default values?

2009-08-27 Thread seanacais
On Aug 27, 5:44 pm, Chris Rebert wrote: > On Thu, Aug 27, 2009 at 2:37 PM, seanacais wrote: > > I'm working on a program where I wish to define the default value of a > > method as a value that was set in __init__.  I get a compilation error > > saying that self is undefined. > > > As always a cod

Re: variables of the class are not available as default values?

2009-08-27 Thread Andre Engels
On Thu, Aug 27, 2009 at 11:37 PM, seanacais wrote: > I'm working on a program where I wish to define the default value of a > method as a value that was set in __init__.  I get a compilation error > saying that self is undefined. > > As always a code snippet helps :-) > > class foo: >    def __init

Re: variables of the class are not available as default values?

2009-08-27 Thread Chris Rebert
On Thu, Aug 27, 2009 at 2:37 PM, seanacais wrote: > I'm working on a program where I wish to define the default value of a > method as a value that was set in __init__.  I get a compilation error > saying that self is undefined. > > As always a code snippet helps :-) > > class foo: >    def __init_

Re: Variables vs attributes

2009-04-18 Thread Piet van Oostrum
> Steven D'Aprano (SD) wrote: >SD> On Fri, 17 Apr 2009 17:48:55 +0200, Diez B. Roggisch wrote: >>> No, because you are creating *classvariables* when declaring things like >>> this: >SD> ... >>> OTOH, when assigning to an instance, this will create an >>> *instance*-variable. Which is what

Re: variables bound in moudules are None when module is not completely imported

2009-02-25 Thread Gabriel Genellina
En Wed, 25 Feb 2009 21:24:33 -0200, escribió: On Wed, Feb 25, 2009 at 05:05:28PM -0200, Gabriel Genellina wrote: I'd try to move all the global stuff in that module into a function, "init". Importing the module will always succeed - you have to manually call init() after importing it. i nor

Re: variables bound in moudules are None when module is not completely imported

2009-02-25 Thread chrysn
On Wed, Feb 25, 2009 at 05:05:28PM -0200, Gabriel Genellina wrote: > I'd try to move all the global stuff in that module into a function, > "init". Importing the module will always succeed - you have to manually > call init() after importing it. i normally do that anyway and would also have do

Re: variables bound in moudules are None when module is not completely imported

2009-02-25 Thread Gabriel Genellina
En Wed, 25 Feb 2009 16:48:16 -0200, escribió: update: i've found one, but this only works if the exception is raised at a point determined by the outside. to explain why this is applicable: in the examples, i used `1/0` to raise a zero division exception inside the module whose scope i want to

Re: variables bound in moudules are None when module is not completely imported

2009-02-25 Thread chrysn
On Tue, Feb 24, 2009 at 03:27:19PM +0100, chr...@fsfe.org wrote: > * is there a workaround? > * especially, is there a workaround that works w/o rewriting the > modules that raise the exceptions? (otherwise, wrapping all the > stuff called in the __name__=="__main__" wrapper into a

Re: Variables and their domain

2007-11-29 Thread Terry Reedy
"Jose Ignacio Gisbert" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | I have one doubt, in my applciation I have a method (Method1) which has | other method (Method2) inside of it. You have a function inside a function. In Python, methods are functions bound to classes. |

Re: variables with dynamicly generated names

2006-12-14 Thread Gabriel Genellina
At Thursday 14/12/2006 05:50, avlee wrote: Is it possible to use in python variables with dynamicly created names ? How ? Use a dictionary: d = {} d[almost_arbitrary_key] = value -- Gabriel Genellina Softlab SRL __ Correo Yahoo! Espacio par

Re: variables with dynamicly generated names

2006-12-14 Thread Paul Rubin
avlee <[EMAIL PROTECTED]> writes: > Is it possible to use in python variables with dynamicly created names ? Yes, but don't. > How ? You almost certainly want to use something like a dictionary instead. -- http://mail.python.org/mailman/listinfo/python-list

Re: variables with dynamicly generated names

2006-12-14 Thread Diez B. Roggisch
avlee schrieb: > Hello > > Is it possible to use in python variables with dynamicly created names ? > How ? In such cases, use a dictionary: vars = {} for some_name, some_value in some_values_generating_thing(): vars[some_name] = some_value Diez -- http://mail.python.org/mailman/listinf

Re: Variables in nested functions

2006-08-30 Thread Bryan Olson
Ben Cartwright wrote: > The typical kludge is to wrap the variable in the outer function inside > a mutable object, then pass it into the inner using a default argument: > > def outer(): > a = "outer" > def inner(wrapa=[a]): > print wrapa[0] > wrapa[0] = "inner" > retu

Re: Variables in nested functions

2006-08-30 Thread Bruno Desthuilliers
[EMAIL PROTECTED] wrote: > Is it possible to change the value of a variable in the outer function > if you are in a nested inner function? Depends on what you mean by "changing the value". If you mean mutating a mutable object, yes, it's possible. If you mean rebinding the name to a different obje

Re: Variables in nested functions

2006-08-29 Thread Ben Cartwright
[EMAIL PROTECTED] wrote: > Is it possible to change the value of a variable in the outer function > if you are in a nested inner function? The typical kludge is to wrap the variable in the outer function inside a mutable object, then pass it into the inner using a default argument: def outer():

Re: variables preceeded with @

2006-02-07 Thread Thomas Girod
Yum, food for thoughts. Thanks Diez. -- http://mail.python.org/mailman/listinfo/python-list

Re: variables preceeded with @

2006-02-07 Thread Diez B. Roggisch
Thomas Girod wrote: > Hello there. > > I recently started looking at turbogears and I found code such as : > > class Root(controllers.Root): > @turbogears.expose(html="blog.templates.accueil") > def index(self,**kw): > return dict() > > > What is this "@" ? I looked around

Re: Variables and none?

2006-01-21 Thread Terry Reedy
"Steve Holden" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Ivan Shevanski wrote: >> python way to detect if a variable exsists? Say I had a program that >> needed a certain variable to be set to run and the variable was not >> found when it came time to use it. . .Would I just

Re: Variables and none?

2006-01-20 Thread Steve Holden
Ivan Shevanski wrote: > Alright first of all I'd like to say I'm a python noob. > Welcome to c.l.py. > Now that thats over with, heres what I'd like to know about. Is there a > python way to detect if a variable exsists? Say I had a program that > needed a certain variable to be set to run an

Re: Variables and none?

2006-01-20 Thread Ivan Shevanski
On 1/20/06, Ivan Shevanski <[EMAIL PROTECTED]> wrote: Alright first of all I'd like to say I'm a python noob.Now that thats over with, heres what I'd like to know about.  Is there a python way to detect if a variable exsists?  Say I had a program that needed a certain variable to be set to run and

Re: Variables in REs

2005-08-24 Thread Yoav
Such a sweet and simple way. Thanks. tooper wrote: > Use os.sep to get / or \ or whatever character used to build pathes on > the os you're working on > -- http://mail.python.org/mailman/listinfo/python-list

Re: Variables in REs

2005-08-24 Thread tooper
Use os.sep to get / or \ or whatever character used to build pathes on the os you're working on -- http://mail.python.org/mailman/listinfo/python-list

Re: Variables

2005-04-25 Thread Donn Cave
Quoth Richard Blackwood <[EMAIL PROTECTED]>: ... | Would you agree that the concept of variables differs in very important | ways between the domains of math and programming? No, if "math" means the elementary notions that I have been exposed to and "very important" means "important to implemento

  1   2   >