Re: Importing variables non-deterministic?

2013-08-20 Thread wxjmfauth
Le mardi 20 août 2013 09:55:44 UTC+2, Antoon Pardon a écrit : > Op 20-08-13 09:31, wxjmfa...@gmail.com schreef: > > > Le mardi 20 août 2013 08:55:18 UTC+2, Antoon Pardon a écrit : > > >> > > >>> > > >> > > > > > >> > > >> > > >> > > >>> If you consider the implementation of sin and cos fu

Re: Importing variables non-deterministic?

2013-08-20 Thread Antoon Pardon
Op 20-08-13 09:31, wxjmfa...@gmail.com schreef: > Le mardi 20 août 2013 08:55:18 UTC+2, Antoon Pardon a écrit : >> >>> >> > >> >> >> >>> If you consider the implementation of sin and cos functions, they usually >> >>> reduce the argument modulo π to something in the first quadrant, and then >> >

Re: Importing variables non-deterministic?

2013-08-20 Thread wxjmfauth
Le mardi 20 août 2013 08:55:18 UTC+2, Antoon Pardon a écrit : > > > > > > > > > If you consider the implementation of sin and cos functions, they usually > > > reduce the argument modulo π to something in the first quadrant, and then > > > use symmetry to adjust the value. So changing th

Re: Importing variables non-deterministic?

2013-08-19 Thread Antoon Pardon
Op 20-08-13 07:48, Steven D'Aprano schreef: > On Mon, 19 Aug 2013 22:34:00 +0200, Antoon Pardon wrote: > >> Op 19-08-13 19:05, Steven D'Aprano schreef: >> >> >>> I wish Python had stronger support for enforcing constantness, to whit, >>> some way to say "you can't rebind or delete this name once i

Re: Importing variables non-deterministic?

2013-08-19 Thread wxjmfauth
Le mardi 20 août 2013 07:48:37 UTC+2, Steven D'Aprano a écrit : > On Mon, 19 Aug 2013 22:34:00 +0200, Antoon Pardon wrote: > > > > > Op 19-08-13 19:05, Steven D'Aprano schreef: > > > > > > > > >> I wish Python had stronger support for enforcing constantness, to whit, > > >> some way to say

Re: Importing variables non-deterministic?

2013-08-19 Thread Steven D'Aprano
On Mon, 19 Aug 2013 22:34:00 +0200, Antoon Pardon wrote: > Op 19-08-13 19:05, Steven D'Aprano schreef: > > >> I wish Python had stronger support for enforcing constantness, to whit, >> some way to say "you can't rebind or delete this name once it is >> bound". You can do it with attributes, by u

Re: Importing variables non-deterministic?

2013-08-19 Thread Ben Finney
Antoon Pardon writes: > Op 19-08-13 09:45, Dave Angel schreef: > > Antoon Pardon wrote: > >> I think you are overstating your case. Classes and functions are > >> variables too and in general nobody seems to have a problem with > >> them being global. > > > > It's global *variables* that are to

Re: Importing variables non-deterministic?

2013-08-19 Thread Antoon Pardon
Op 19-08-13 19:05, Steven D'Aprano schreef: I wish Python had stronger support for enforcing constantness, to whit, some way to say "you can't rebind or delete this name once it is bound". You can do it with attributes, by use of property, or in C extensions, but you cannot do it with top-level

Re: Importing variables non-deterministic?

2013-08-19 Thread Antoon Pardon
Op 19-08-13 18:57, Steven D'Aprano schreef: On Mon, 19 Aug 2013 10:16:36 +0200, Antoon Pardon wrote: Op 19-08-13 09:45, Dave Angel schreef: Antoon Pardon wrote: Op 17-08-13 17:01, Steven D'Aprano schreef: And here you re-import the name "y" from struct_global. That rebinds the current modu

Re: Importing variables non-deterministic?

2013-08-19 Thread Antoon Pardon
Op 19-08-13 17:04, Chris Angelico schreef: On Mon, Aug 19, 2013 at 3:55 PM, Antoon Pardon wrote: Pity enough they chose a way that didn't allow programmers to protect names they thought important enough to do so too. As of Python 3, we can redefine something that used to be a keyword, which i

Re: Importing variables non-deterministic?

2013-08-19 Thread Chris Angelico
On Mon, Aug 19, 2013 at 6:16 PM, Steven D'Aprano wrote: > On Mon, 19 Aug 2013 16:57:37 +, Steven D'Aprano wrote: > >> def func(x): >> ... >> >> # later >> save_func = func >> func = lambda x, y: do_stuff(x, 3*y)-4 result = >> something_that_calls_func() >> func = save_func >> >> >> Nasty,

Re: Importing variables non-deterministic?

2013-08-19 Thread Steven D'Aprano
On Mon, 19 Aug 2013 16:57:37 +, Steven D'Aprano wrote: > def func(x): > ... > > # later > save_func = func > func = lambda x, y: do_stuff(x, 3*y)-4 result = > something_that_calls_func() > func = save_func > > > Nasty, horrible code, yes? But it's nasty and horrible because "func" is >

Re: Importing variables non-deterministic?

2013-08-19 Thread Steven D'Aprano
On Mon, 19 Aug 2013 09:32:53 +0100, Chris Angelico wrote: > Python does have constants. It just doesn't have interpreter support for > them. Same as private members, in fact. "Constant by convention". I wish Python had stronger support for enforcing constantness, to whit, some way to say "you c

Re: Importing variables non-deterministic?

2013-08-19 Thread Steven D'Aprano
On Mon, 19 Aug 2013 10:16:36 +0200, Antoon Pardon wrote: > Op 19-08-13 09:45, Dave Angel schreef: >> Antoon Pardon wrote: >> >>> Op 17-08-13 17:01, Steven D'Aprano schreef: And here you re-import the name "y" from struct_global. That rebinds the current module's "y" with whatever v

Re: Importing variables non-deterministic?

2013-08-19 Thread Chris Angelico
On Mon, Aug 19, 2013 at 3:55 PM, Antoon Pardon wrote: > Pity enough they chose a > way that didn't allow programmers to protect names they thought > important enough to do so too. As of Python 3, we can redefine something that used to be a keyword, which is even stronger than a constant. def pri

Re: Importing variables non-deterministic?

2013-08-19 Thread Antoon Pardon
Op 19-08-13 14:33, Dave Angel schreef: > Antoon Pardon wrote: > >> Op 19-08-13 11:18, Chris Angelico schreef: > >>> The issue >>> was regarding imports, and it's perfectly safe to import a constant, >>> even if the interpreter doesn't protect you from then being a total >>> idiot and changing

Re: Importing variables non-deterministic?

2013-08-19 Thread Dave Angel
Antoon Pardon wrote: > Op 19-08-13 11:18, Chris Angelico schreef: >> The issue >> was regarding imports, and it's perfectly safe to import a constant, >> even if the interpreter doesn't protect you from then being a total >> idiot and changing it. > > Python doesn't have constants, so you sta

Re: Importing variables non-deterministic?

2013-08-19 Thread Antoon Pardon
Op 19-08-13 11:18, Chris Angelico schreef: > On Mon, Aug 19, 2013 at 10:03 AM, Antoon Pardon > wrote: >> This is irrelevant. That some context defines a constant, and that you >> can use a variable with the same name as a constant in python, doesn't >> contradict the statement that python (as a la

Re: Importing variables non-deterministic?

2013-08-19 Thread Peter Otten
Chris Angelico wrote: > On Mon, Aug 19, 2013 at 10:03 AM, Antoon Pardon > wrote: >> This is irrelevant. That some context defines a constant, and that you >> can use a variable with the same name as a constant in python, doesn't >> contradict the statement that python (as a language) doesn't has

Re: Importing variables non-deterministic?

2013-08-19 Thread Chris Angelico
On Mon, Aug 19, 2013 at 10:03 AM, Antoon Pardon wrote: > This is irrelevant. That some context defines a constant, and that you > can use a variable with the same name as a constant in python, doesn't > contradict the statement that python (as a language) doesn't has > constants. There is nothing

Re: Importing variables non-deterministic?

2013-08-19 Thread Antoon Pardon
Op 19-08-13 10:32, Chris Angelico schreef: > On Mon, Aug 19, 2013 at 9:16 AM, Antoon Pardon > wrote: >> Op 19-08-13 09:45, Dave Angel schreef: >>> Antoon Pardon wrote: I think you are overstating your case. Classes and functions are variables too and in general nobody seems to have a pro

Re: Importing variables non-deterministic?

2013-08-19 Thread Chris Angelico
On Mon, Aug 19, 2013 at 9:16 AM, Antoon Pardon wrote: > Op 19-08-13 09:45, Dave Angel schreef: >> Antoon Pardon wrote: >>> I think you are overstating your case. Classes and functions are >>> variables too and in general nobody seems to have a problem with them >>> being global. >>> >> >> It's glo

Re: Importing variables non-deterministic?

2013-08-19 Thread Antoon Pardon
Op 19-08-13 09:45, Dave Angel schreef: > Antoon Pardon wrote: > >> Op 17-08-13 17:01, Steven D'Aprano schreef: >>> >>> And here you re-import the name "y" from struct_global. That rebinds the >>> current module's "y" with whatever value struct_global.y has *now*, >>> rather than a second (or a m

Re: Importing variables non-deterministic?

2013-08-19 Thread Dave Angel
Antoon Pardon wrote: > Op 17-08-13 17:01, Steven D'Aprano schreef: >> >> And here you re-import the name "y" from struct_global. That rebinds the >> current module's "y" with whatever value struct_global.y has *now*, >> rather than a second (or a minute, or an hour) earlier when the first >> i

Re: Importing variables non-deterministic?

2013-08-19 Thread Antoon Pardon
Op 17-08-13 17:01, Steven D'Aprano schreef: > > And here you re-import the name "y" from struct_global. That rebinds the > current module's "y" with whatever value struct_global.y has *now*, > rather than a second (or a minute, or an hour) earlier when the first > import took place. Obviously a

Re: Importing variables non-deterministic?

2013-08-17 Thread Steven D'Aprano
On Sat, 17 Aug 2013 07:25:43 -0700, tmellman wrote: > I have this file that has this: > > from struct_global import y > from struct_global import x The import of x appears to be irrelevant, so I'll ignore it. Here you import y from the struct_global module. This creates a new name y in

Importing variables non-deterministic?

2013-08-17 Thread tmellman
I have this file that has this: from struct_global import y from struct_global import x and this usage (a few lines later in a class method definition in the same file): if y == x: If I stop there in pdb, I can observe this: (Pdb) p x 66 (Pdb) p y -1