On Fri, Jun 24, 2016 at 1:00 AM, Steven D'Aprano wrote:
> To be precise, for the builtins module specifically, you can *read* the
> value of the variable using just x, but you cannot *assign* to it unless
> you use the fully-qualified name builtins.x.
FWIW, you can execute code in any dict:
On Fri, Jun 24, 2016 at 11:00 AM, Steven D'Aprano wrote:
> To me, a global variable is a variable which is scoped to a level wider than
> any single function, i.e. module scope, or whole-application scope. That
> is, the variable must be visible to more than one function, or more than
> one module
On Wed, 22 Jun 2016 07:24 pm, BartC wrote:
[...]
> But even if it worked, I don't think this two-parter counts as a 'global
> variable' as it is understood. I might as well just create my own G
> module containing:
>
> BDFL="GvR"
>
> and import it in both A and B. Then I can also write G.BD
On 22/06/2016 01:24, Rick Johnson wrote:
On Tuesday, June 21, 2016 at 6:16:09 PM UTC-5, BartC wrote:
I tried using your method but it didn't work:
...you'll find a thread i authored, that includes an object
exposing a global namespace named "G". Details of how to
inject the symbol G are inc
On Tuesday, June 21, 2016 at 6:16:09 PM UTC-5, BartC wrote:
> On 21/06/2016 23:20, Rick Johnson wrote:
> > On Tuesday, June 21, 2016 at 12:15:38 PM UTC-5, Random832 wrote:
>
> > Storing dynamic data to global space is almost always
> > foolish, and I'm a fan of name spaces. But i did not
> > recom
On Tuesday, June 21, 2016 at 5:20:53 PM UTC-5, Rick Johnson wrote:
> py> import sys
> py> def foo():
> ... print 'My name is Foo!'
> py> sys.modules['__builtin__'].__dict__['foo_func'] = foo
> py> foo()
> My name is Foo!
> py> foo = 'bar'
> py> foo
> 'bar'
>
On Tuesday, June 21, 2016 at 5:32:43 PM UTC-5, Chris Angelico wrote:
> On Wed, Jun 22, 2016 at 8:20 AM, Rick Johnson:
> > Then one could have added module-level symbols without all
> > the semantic hubbub.
> >
> > MSFL.foo = 0
> >
> > def iter_foo():
> > MSFL.foo += 1
> >
>
> And d
On 21/06/2016 23:20, Rick Johnson wrote:
On Tuesday, June 21, 2016 at 12:15:38 PM UTC-5, Random832 wrote:
Storing dynamic data to global space is almost always
foolish, and I'm a fan of name spaces. But i did not
recommend such foolish action, i was merely replying to the
assertion that "Pytho
On Wed, Jun 22, 2016 at 8:20 AM, Rick Johnson
wrote:
> Then one could have added module-level symbols without all
> the semantic hubbub.
>
> MSFL.foo = 0
>
> def iter_foo():
> MSFL.foo += 1
>
And don't forget that you would need to call this function as
MSFL.iter_foo(). Module-lev
On Tuesday, June 21, 2016 at 12:15:38 PM UTC-5, Random832 wrote:
> You can put a function or constant there, sure. But if
> you're using it as a variable, you'd have to do that
> *every* time (in which case what's the point)
Well, since the term "variable" has been so abused, using it
in such a n
On Tue, Jun 21, 2016, at 13:04, Rick Johnson wrote:
> On Sunday, June 12, 2016 at 2:08:01 PM UTC-5, BartC wrote:
> > Anyway, it shows Python doesn't have true cross-module globals.
>
> BS! You can inject symbols into sys.modules and achieve a
> true global.
You can put a function or constant th
On Sunday, June 12, 2016 at 2:08:01 PM UTC-5, BartC wrote:
> Anyway, it shows Python doesn't have true cross-module globals.
BS! You can inject symbols into sys.modules and achieve a
true global.
## BEGIN: INTERACTIVE SESSION ##
py> import sys
py> def foo():
... print 'My name
Op 21-06-16 om 12:41 schreef BartC:
> On 21/06/2016 09:08, Antoon Pardon wrote:
>> Op 20-06-16 om 16:53 schreef Steven D'Aprano:
>
>>> You know, there's not actually a rule or law that says you have to
>>> automatically take the contrary position to everything I say.
>>
>> There is also not a rule
On 21/06/2016 09:08, Antoon Pardon wrote:
Op 20-06-16 om 16:53 schreef Steven D'Aprano:
You know, there's not actually a rule or law that says you have to
automatically take the contrary position to everything I say.
There is also not a rule of law that says you have to automatically introdu
Op 20-06-16 om 16:53 schreef Steven D'Aprano:
> On Mon, 20 Jun 2016 11:29 pm, Random832 wrote:
>
>> On Mon, Jun 20, 2016, at 08:15, Steven D'Aprano wrote:
>>> Bart didn't say anyone had defended it. He made an observation:
>>>
>>> "that's a good illustration of why 'y' isn't a name reference to 'x'
On Mon, 20 Jun 2016 11:29 pm, Random832 wrote:
> On Mon, Jun 20, 2016, at 08:15, Steven D'Aprano wrote:
>> Bart didn't say anyone had defended it. He made an observation:
>>
>> "that's a good illustration of why 'y' isn't a name reference to 'x'"
>>
>> which is factually correct. And this does r
On Mon, Jun 20, 2016, at 08:15, Steven D'Aprano wrote:
> Bart didn't say anyone had defended it. He made an observation:
>
> "that's a good illustration of why 'y' isn't a name reference to 'x'"
>
> which is factually correct. And this does refer to the "ducks limp"
> thread.
Except it doesn't.
Op 20-06-16 om 14:15 schreef Steven D'Aprano:
> On Mon, 20 Jun 2016 09:14 pm, Antoon Pardon wrote:
>
>> Op 19-06-16 om 23:20 schreef BartC:
>>> On 19/06/2016 15:35, Antoon Pardon wrote:
Op 12-06-16 om 23:10 schreef BartC:
> On 12/06/2016 20:25, Ned Batchelder wrote:
>> Just as here t
On Mon, 20 Jun 2016 09:14 pm, Antoon Pardon wrote:
> Op 19-06-16 om 23:20 schreef BartC:
>> On 19/06/2016 15:35, Antoon Pardon wrote:
>>> Op 12-06-16 om 23:10 schreef BartC:
On 12/06/2016 20:25, Ned Batchelder wrote:
> Just as here there is no link between x
> and y:
>
>
On Mon, 20 Jun 2016 08:21 pm, BartC wrote:
> On 19/06/2016 18:16, Joel Goldstick wrote:
>
>> People who understand global variables generally avoid using them at
>> all costs.
>
> Then perhaps they don't understand that in Python, top-level functions,
> classes and imports are also globals.
But
Op 19-06-16 om 23:20 schreef BartC:
> On 19/06/2016 15:35, Antoon Pardon wrote:
>> Op 12-06-16 om 23:10 schreef BartC:
>>> On 12/06/2016 20:25, Ned Batchelder wrote:
Just as here there is no link between x
and y:
x = 12
y = x
>>>
>>> (And that's a good illustratio
On 19/06/2016 18:16, Joel Goldstick wrote:
People who understand global variables generally avoid using them at
all costs.
Then perhaps they don't understand that in Python, top-level functions,
classes and imports are also globals.
--
Bartc
--
https://mail.python.org/mailman/listinfo/pytho
On Monday, June 20, 2016 at 5:16:50 AM UTC+12, Joel Goldstick wrote:
> People who understand global variables generally avoid using them at
> all costs.
I use them occasionally.
> People who don't understand why globals create problems
> seem to want to use them, and then become baffled at the pr
On 19/06/2016 15:35, Antoon Pardon wrote:
Op 12-06-16 om 23:10 schreef BartC:
On 12/06/2016 20:25, Ned Batchelder wrote:
Just as here there is no link between x
and y:
x = 12
y = x
(And that's a good illustration of why 'y' isn't a name reference to 'x', referring to
the "...ducks
On Sun, Jun 19, 2016 at 10:35 AM, Antoon Pardon
wrote:
> Op 12-06-16 om 23:10 schreef BartC:
>> On 12/06/2016 20:25, Ned Batchelder wrote:
>>> Just as here there is no link between x
>>> and y:
>>>
>>> x = 12
>>> y = x
>>
>> (And that's a good illustration of why 'y' isn't a name referen
Op 12-06-16 om 23:10 schreef BartC:
> On 12/06/2016 20:25, Ned Batchelder wrote:
>> Just as here there is no link between x
>> and y:
>>
>> x = 12
>> y = x
>
> (And that's a good illustration of why 'y' isn't a name reference to 'x',
> referring to the "...ducks limp" thread. But best n
On 12/06/2016 20:25, Ned Batchelder wrote:
On Sunday, June 12, 2016 at 3:08:01 PM UTC-4, BartC wrote:
On 12/06/2016 00:44, Marcin Rak wrote:
from Test import some_function, my_print
from Test import test_var
some_function()
my_print()
print(test_var)
*
On Sunday, June 12, 2016 at 3:08:01 PM UTC-4, BartC wrote:
> On 12/06/2016 00:44, Marcin Rak wrote:
> > Hi to all.
> >
> > I have the following file named Solver.py:
> > *
> > from Test import some_function, my_print
> > from Test import test_var
> >
> > some
On 12/06/2016 00:44, Marcin Rak wrote:
Hi to all.
I have the following file named Solver.py:
*
from Test import some_function, my_print
from Test import test_var
some_function()
my_print()
print(test_var)
*
and I h
On Sat, Jun 11, 2016, at 23:15, Lawrence D’Oliveiro wrote:
> On Sunday, June 12, 2016 at 11:51:11 AM UTC+12, Random832 wrote:
> > Importing a variable from a module copies its value into your own
> > module's variable.
>
> Every name in Python is a variable, and can be assigned to to change its
>
On Sat, Jun 11, 2016, at 23:15, Lawrence D’Oliveiro wrote:
> On Sunday, June 12, 2016 at 11:51:11 AM UTC+12, Random832 wrote:
> > Importing a variable from a module copies its value into your own
> > module's variable.
>
> Every name in Python is a variable, and can be assigned to to change its
>
Much thanks to all for their time, but Ned in particular...I learned something
new about Python!!
On Saturday, 11 June 2016 22:48:32 UTC-5, Ned Batchelder wrote:
> On Saturday, June 11, 2016 at 11:38:33 PM UTC-4, Steven D'Aprano wrote:
> > On Sun, 12 Jun 2016 11:26 am, Random832 wrote:
> >
> >
On Sunday, June 12, 2016 at 11:51:11 AM UTC+12, Random832 wrote:
> Importing a variable from a module copies its value into your own
> module's variable.
Every name in Python is a variable, and can be assigned to to change its value
at any time.
--
https://mail.python.org/mailman/listinfo/python
On Saturday, June 11, 2016 at 11:38:33 PM UTC-4, Steven D'Aprano wrote:
> On Sun, 12 Jun 2016 11:26 am, Random832 wrote:
>
> > On Sat, Jun 11, 2016, at 20:09, MRAB wrote:
> >> Not true. Importing doesn't copy the value.
> >>
> >> Importing a name creates a new name in the local scope that refers
On Saturday, June 11, 2016 at 8:13:50 PM UTC-4, Marcin Rak wrote:
> On Saturday, 11 June 2016 19:09:29 UTC-5, MRAB wrote:
> > On 2016-06-12 00:50, Random832 wrote:
> > > On Sat, Jun 11, 2016, at 19:44, Marcin Rak wrote:
> > >> So my question is, how the heck is it possible that I get 5 as the last
On Sun, 12 Jun 2016 11:26 am, Random832 wrote:
> On Sat, Jun 11, 2016, at 20:09, MRAB wrote:
>> Not true. Importing doesn't copy the value.
>>
>> Importing a name creates a new name in the local scope that refers to
>> the same object that the imported name referred to.
MRAB is correct here.
>
On Sat, Jun 11, 2016, at 20:12, Marcin Rak wrote:
> What about variables that are user defined classes? Are they referenced
> or copied?
It will reference the same object, but if the variable is reassigned in
the original module it will still not update the imported variable.
--
https://mail.pyt
On Sat, Jun 11, 2016, at 20:09, MRAB wrote:
> Not true. Importing doesn't copy the value.
>
> Importing a name creates a new name in the local scope that refers to
> the same object that the imported name referred to.
Yes, the value of a variable is a reference to an object. Can we not
have anot
On Saturday, 11 June 2016 19:09:29 UTC-5, MRAB wrote:
> On 2016-06-12 00:50, Random832 wrote:
> > On Sat, Jun 11, 2016, at 19:44, Marcin Rak wrote:
> >> So my question is, how the heck is it possible that I get 5 as the last
> >> value printed? the global test_var (global to Test.py) I set to 44 w
On Saturday, 11 June 2016 18:51:11 UTC-5, Random832 wrote:
> On Sat, Jun 11, 2016, at 19:44, Marcin Rak wrote:
> > So my question is, how the heck is it possible that I get 5 as the last
> > value printed? the global test_var (global to Test.py) I set to 44 when I
> > ran some_function()??? does
On 2016-06-12 00:50, Random832 wrote:
On Sat, Jun 11, 2016, at 19:44, Marcin Rak wrote:
So my question is, how the heck is it possible that I get 5 as the last
value printed? the global test_var (global to Test.py) I set to 44 when I
ran some_function()??? does anyone have a clue they could thr
On Sat, Jun 11, 2016, at 19:44, Marcin Rak wrote:
> So my question is, how the heck is it possible that I get 5 as the last
> value printed? the global test_var (global to Test.py) I set to 44 when I
> ran some_function()??? does anyone have a clue they could throw my way?
Importing a variable fr
Hi to all.
I have the following file named Solver.py:
*
from Test import some_function, my_print
from Test import test_var
some_function()
my_print()
print(test_var)
*
and I have the following Test.py:
**
43 matches
Mail list logo