[issue29881] Add a new private API clear private variables, which are initialized once, at Python shutdown

2018-09-19 Thread STINNER Victor
Change by STINNER Victor : -- resolution: -> out of date stage: -> resolved status: open -> closed ___ Python tracker ___ ___

[issue29881] Add a new private API clear private variables, which are initialized once, at Python shutdown

2017-09-05 Thread STINNER Victor
STINNER Victor added the comment: My PR 780 doesn't support multiple Python interpreters in the same process. To support that, we need a more advanced solution. For example, add an hash table in the interpreter structure using the variable memory address as the key. Maybe we can move step by

[issue29881] Add a new private API clear private variables, which are initialized once, at Python shutdown

2017-04-12 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: What if use the term "singleton"? It includes "initialize once" and "finalize at shutdown" meanings. _Py_INIT_SINGLETON() or _Py_SET_SINGLETON()? -- ___ Python tracker

[issue29881] Add a new private API clear private variables, which are initialized once, at Python shutdown

2017-04-12 Thread STINNER Victor
STINNER Victor added the comment: I dislike _Py_SET_FINALIZED and _Py_SET_ONCE name. I prefer to mention an "initialization" because it's a common pattern in programming and it is known that it only requires to be done once. _PY_ONCEVAR_INIT() macro is unusual: it only evaluate the second

[issue29881] Add a new private API clear private variables, which are initialized once, at Python shutdown

2017-04-11 Thread Louie Lu
Changes by Louie Lu : -- nosy: +louielu ___ Python tracker ___ ___ Python-bugs-list mailing

[issue29881] Add a new private API clear private variables, which are initialized once, at Python shutdown

2017-04-10 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Can you move forward this issue Victor? I'm very interesting in it. It is worth to advertise this API on Python-Dev. _PyArg_Parser also can utilize this API. -- ___ Python tracker

[issue29881] Add a new private API clear private variables, which are initialized once, at Python shutdown

2017-03-31 Thread Nick Coghlan
Nick Coghlan added the comment: _PY_SET_FINALIZED is only one letter longer than _PY_ONCEVAR_INIT and the same length as the originally proposed _PY_STATICVAR_INIT. Since it shouldn't be anywhere near as common as _Py_SETREF, I'm also okay in general with trading a bit of brevity for

[issue29881] Add a new private API clear private variables, which are initialized once, at Python shutdown

2017-03-30 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I agree with your rationale Nick, but _Py_SET_FINALIZED is a little too long and highlight only the second function of the macro. I don't have good name. -- ___ Python tracker

[issue29881] Add a new private API clear private variables, which are initialized once, at Python shutdown

2017-03-30 Thread Nick Coghlan
Nick Coghlan added the comment: I'm +1 for _Py_SET_FINALIZED with the semantics Serhiy suggests, and +0 for _Py_SET_ONCE. My rationale for that preference is that _Py_SET_ONCE is a misnomer in the presence of * multiple Py_Initialize/Py_Finalize cycles; and/or * _Py_SETREF calls that replace

[issue29881] Add a new private API clear private variables, which are initialized once, at Python shutdown

2017-03-30 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Ping. My suggestion is to rename _PY_ONCEVAR_INIT to _Py_SET_ONCE and make it returning the value. And apply this to more static and global variables. -- ___ Python tracker

[issue29881] Add a new private API clear private variables, which are initialized once, at Python shutdown

2017-03-23 Thread Nick Coghlan
Nick Coghlan added the comment: For module level variables, I'd expect this API to need to be used in tandem with switching the module over to PEP 489 multi-phase initialization. By calling the new API in their _Py_mod_exec slot implementation, extension modules should be able to handle

[issue29881] Add a new private API clear private variables, which are initialized once, at Python shutdown

2017-03-23 Thread Nick Coghlan
Nick Coghlan added the comment: The main potential benefit I see to keeping the special variable declaration is that it may help avoid a certain category of error: calling _Py_ONCE_VAR_INIT on a stack local pointer reference (which would leave the global array with a reference to nonsense).

[issue29881] Add a new private API clear private variables, which are initialized once, at Python shutdown

2017-03-23 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Some code (_PyUnicode_FromId, bool_repr, create_filter) could be simpler if make _PY_ONCEVAR_INIT returning the value (NULL in case of error). The signature of _PY_ONCEVAR_INIT() is the same as of _Py_SETREF(). If var == NULL both `_PY_ONCEVAR_INIT(var,

[issue29881] Add a new private API clear private variables, which are initialized once, at Python shutdown

2017-03-23 Thread STINNER Victor
STINNER Victor added the comment: I modified more modules to use the new API. I'm not sure that using the API in modules is safe. It's safe to use the API in functions which begins with trying to initialize the variable. In such case, if the variable is cleared, calling the function later

[issue29881] Add a new private API clear private variables, which are initialized once, at Python shutdown

2017-03-23 Thread STINNER Victor
Changes by STINNER Victor <victor.stin...@gmail.com>: -- title: Add a new private API for "static C variables" (_PyStaticVar) to clear them at exit -> Add a new private API clear private variables, which are initialized once,

Private variables

2010-09-01 Thread Rasjid Wilcox
Hi all, I am aware the private variables are generally done via convention (leading underscore), but I came across a technique in Douglas Crockford's book Javascript: The Good Parts for creating private variables in Javascript, and I'd thought I'd see how it translated to Python. Here is my

Re: Private variables

2010-09-01 Thread Ryan Kelly
On Thu, 2010-09-02 at 11:10 +1000, Rasjid Wilcox wrote: Hi all, I am aware the private variables are generally done via convention (leading underscore), but I came across a technique in Douglas Crockford's book Javascript: The Good Parts for creating private variables in Javascript, and I'd

Re: Private variables

2010-09-01 Thread Ryan Kelly
On Thu, 2010-09-02 at 12:06 +1000, Ryan Kelly wrote: On Thu, 2010-09-02 at 11:10 +1000, Rasjid Wilcox wrote: Hi all, I am aware the private variables are generally done via convention (leading underscore), but I came across a technique in Douglas Crockford's book Javascript: The Good

Re: Private variables

2010-09-01 Thread Rasjid Wilcox
On 2 September 2010 12:22, Ryan Kelly r...@rfk.id.au wrote: On Thu, 2010-09-02 at 12:06 +1000, Ryan Kelly wrote: On Thu, 2010-09-02 at 11:10 +1000, Rasjid Wilcox wrote: Hi all, I am aware the private variables are generally done via convention (leading underscore), but I came across

Re: Changing the private variables content

2009-07-23 Thread Ethan Furman
Ryniek90 wrote: Got it: exec('self.' + attr + '=\'' + val + '\'') That worked. I think it'll do what you want now ;) Ching-Yun Xavier Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com mailto:cont...@xavierho.com Website:

Re: Changing the private variables content

2009-07-23 Thread Ethan Furman
Or, in other words, what Steven D'Aprano had already said. Guess I should read the whole thread before madly posting! :) ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list

Re: Re: Changing the private variables content

2009-07-22 Thread Ryniek90
Temat: Re: Changing the private variables content Od: Gary Herron gher...@islandtraining.com Data: Tue, 21 Jul 2009 14:14:44 -0700 Do: Ryniek90 rynie...@gmail.com Do: Ryniek90 rynie...@gmail.com Kopia: python-list

Re: Re: Changing the private variables content

2009-07-22 Thread Xavier Ho
On Wed, Jul 22, 2009 at 10:29 PM, Ryniek90 rynie...@gmail.com wrote: Thanks for hint, but looks like i can't do what i want. That's because def _SetVar(self, attr, val): self.attr = val doesn't work as you might think. However, I tried to replace it with: val('self.' +

Re: Re: Changing the private variables content

2009-07-22 Thread Xavier Ho
val('self.' + attr + '=\'' + val + '\'') Obviously that was eval, not val. Also it doesn't work without the escaped single quotes, either. -- http://mail.python.org/mailman/listinfo/python-list

Re: Re: Changing the private variables content

2009-07-22 Thread Xavier Ho
Got it: exec('self.' + attr + '=\'' + val + '\'') That worked. I think it'll do what you want now ;) Ching-Yun Xavier Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ --

Re: Changing the private variables content

2009-07-22 Thread MRAB
Ryniek90 wrote: Temat: Re: Changing the private variables content Od: Gary Herron gher...@islandtraining.com Data: Tue, 21 Jul 2009 14:14:44 -0700 Do: Ryniek90 rynie...@gmail.com Do: Ryniek90 rynie...@gmail.com Kopia

Re: Changing the private variables content

2009-07-22 Thread Xavier Ho
What is the point of the _SetVar method? So you can set any variable in that class, I guess? -- http://mail.python.org/mailman/listinfo/python-list

Re: Changing the private variables content

2009-07-22 Thread Steven D'Aprano
On Wed, 22 Jul 2009 14:29:20 +0200, Ryniek90 wrote: When i use this class in Python IDLE, i've got this error: ... Traceback (most recent call last): File pyshell#60, line 1, in module mod.print_module('socket') File pyshell#57, line 48, in print_module module_open =

Re: Changing the private variables content

2009-07-22 Thread Ryniek90
Got it: exec('self.' + attr + '=\'' + val + '\'') That worked. I think it'll do what you want now ;) Ching-Yun Xavier Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com mailto:cont...@xavierho.com Website: http://xavierho.com/

Re: Changing the private variables content

2009-07-22 Thread Dave Angel
Ryniek90 wrote: snip It looks like private variable have specific naure, that prevent from traditional editing them. Still searching for some tuts about private methods and variables. There's no tutorial on private variables for good reason: Private variables have no special

Re: Changing the private variables content

2009-07-22 Thread Jean-Michel Pichavant
Steven D'Aprano wrote: On Wed, 22 Jul 2009 14:29:20 +0200, Ryniek90 wrote: When i use this class in Python IDLE, i've got this error: ... Traceback (most recent call last): File pyshell#60, line 1, in module mod.print_module('socket') File pyshell#57, line 48, in

Re: Changing the private variables content

2009-07-22 Thread Piet van Oostrum
? Is that you idea of `private variables'? Or do you think that *args does magical things? Private method which walks through default Python installation directories, and search for prefered module. #walking thru all directories available in path _user_search_path

Changing the private variables content

2009-07-21 Thread Ryniek90
Hi. I'm writing some class, and decided to use inside private method and some private variables. While with method i haven't got any problem's with variables i have. Maybe some example. A class with private method and private variable: class Secret(object): # def __init__(self

Re: Changing the private variables content

2009-07-21 Thread Gary Herron
Ryniek90 wrote: Hi. I'm writing some class, and decided to use inside private method and some private variables. While with method i haven't got any problem's with variables i have. Maybe some example. A class with private method and private variable: class Secret(object): # def

Re: Changing the private variables content

2009-07-21 Thread David Stanek
On Tue, Jul 21, 2009 at 6:00 PM, Rhodri Jamesrho...@wildebst.demon.co.uk wrote: On Tue, 21 Jul 2009 21:55:18 +0100, Ryniek90 rynie...@gmail.com wrote: Hi. I'm writing some class, and decided to use inside private method and some private variables. While with method i haven't got any problem's

Re: private variables

2007-01-09 Thread Bruno Desthuilliers
belinda thom a écrit : Hello, In what version of python were private variables added? Which private variables ? -- http://mail.python.org/mailman/listinfo/python-list

Re: private variables

2007-01-09 Thread belinda thom
On Jan 9, 2007, at 12:20 AM, Bruno Desthuilliers wrote: belinda thom a écrit : Hello, In what version of python were private variables added? Which private variables ? Haha. The ones that are provided for convenience (via name mangling) that aren't really private if you wish to violate

Re: private variables

2007-01-09 Thread Gabriel Genellina
At Tuesday 9/1/2007 04:38, belinda thom wrote: I knew it was a beehive, but I had hoped someone would know which version they were released, so I can put the proper statement into my tutorial (e.g. In version foo, Python provided some support for private variables...). I've been avoiding

private variables

2007-01-08 Thread belinda thom
Hello, In what version of python were private variables added? Thanks, --b -- http://mail.python.org/mailman/listinfo/python-list

Re: private variables

2007-01-08 Thread Thomas Ploch
belinda thom schrieb: Hello, In what version of python were private variables added? Thanks, --b With this question you stepped into a bee hive. :-) Read the 'Why less emphasis on private data?' thread. But I can't tell you, when this so called 'private variables' were added

Re: private variables

2007-01-08 Thread Ravi Teja
belinda thom wrote: Hello, In what version of python were private variables added? Thanks, --b Short answer - 1.5 (or - so long ago that it doesn't matter anymore) Long answer - There are no true private variables in Python. Just private variables names by convention. See Python docs

Re: private variables

2007-01-08 Thread belinda thom
I knew it was a beehive, but I had hoped someone would know which version they were released, so I can put the proper statement into my tutorial (e.g. In version foo, Python provided some support for private variables...). I've been avoiding getting stung b/c I see both sides and have

Re: private variables a.k.a. name mangling (WAS: What is print? A function?)

2005-01-25 Thread Simon Brunning
On Mon, 24 Jan 2005 12:17:13 -0600, Philippe C. Martin [EMAIL PROTECTED] wrote: I use __for private variables because I must have read on net it was the way to do so - yet this seems to have changed - thanks: http://www.network-theory.co.uk/docs/pytut/tut_77.html Nope, that's still

Re: private variables a.k.a. name mangling (WAS: What is print? A function?)

2005-01-25 Thread michele . simionato
Name mangling is there to keep you from accidentally hiding such an attribute in a subclass, but how often is this really a danger? Can someone give me an example of where __-mangling really solved a problem for them, where a simple leading underscore wouldn't have solved the same problem? Look

Re: private variables a.k.a. name mangling (WAS: What is print? A function?)

2005-01-25 Thread Philippe C. Martin
Well I _was_ a bit slow on that one ! So I will happily stick to the double underscore. Regards, Philippe Le mardi 25 janvier 2005 10:28 +, Simon Brunning a crit : On Mon, 24 Jan 2005 12:17:13 -0600, Philippe C. Martin [EMAIL PROTECTED] wrote: I use __for private variables

Re: private variables a.k.a. name mangling (WAS: What is print? A function?)

2005-01-25 Thread Richie Hindle
[Toby] The problem occured because the double-underscore mangling uses the class name, but ignores module names. A related project already had a class named C derived from B (same name - different module). Yikes! A pretty bizarre case, but nasty when it hits. I guess the

Re: private variables a.k.a. name mangling (WAS: What is print? A function?)

2005-01-25 Thread Steven Bethard
Toby Dickenson wrote: I have a counterexample. Consider refactoring a class from class B(A): etc into class C(A): etc class B(C): etc Usage of some double-undescore attributes moved from B to the new intermediate base class C. Unit tests on B still passed, so that change

private variables a.k.a. name mangling (WAS: What is print? A function?)

2005-01-24 Thread Steven Bethard
Philippe C. Martin wrote: class Debug_Stderr: __m_text = '' __m_log_text = None __m_dbg = None __m_refresh_count = 0 rant I don't see the benefit in 99.9% of cases for making class variables like this private. If you don't want people to use them, simply use the standard

RE: Why I use private variables (WAS: RE:private variables a.k.a. name mangling?)

2005-01-24 Thread Philippe C. Martin
The real reason behind my using private variables is so they do not appear in the epydoc generated documentation and confuse my users. Regards, Philippe -- *** Philippe C. Martin SnakeCard LLC www.snakecard.com *** -- http://mail.python.org

RE: Why I use private variables (WAS: RE:private variables a.k.a. name mangling?)

2005-01-24 Thread Jeremy Bowers
On Mon, 24 Jan 2005 15:35:11 -0600, Philippe C. Martin wrote: The real reason behind my using private variables is so they do not appear in the epydoc generated documentation and confuse my users. You mean single or double underscores? I just checked and at least epydoc 2.1 doesn't include

RE: Why I use private variables (WAS: RE:private variables a.k.a. name mangling?)

2005-01-24 Thread Philippe C. Martin
I used double underscore because I thought it was the correct way to name private variables/methods - I will have to change those to single underscore since that it the current methodology. A private variable to me: 1) is internal to the processing of a class and needs not be accessed by external

Re: Why I use private variables (WAS: RE:private variables a.k.a. name mangling?)

2005-01-24 Thread Steven Bethard
Philippe C. Martin wrote: I used double underscore because I thought it was the correct way to name private variables/methods - I will have to change those to single underscore since that it the current methodology. A private variable to me: 1) is internal to the processing of a class and needs