Re: best way to share an instance of a class among modules?

2013-02-08 Thread Michael Torrie
On 02/07/2013 07:14 PM, Rick Johnson wrote: > So if you want to use "global variables" , (bka: Module level > variables), then simply declare them with a None value like this: > > globalVariable = None This is a nice convention, but at best it's just a helpful notation that helps a programmer kn

Re: best way to share an instance of a class among modules?

2013-02-07 Thread Michael Torrie
On 02/07/2013 07:14 PM, Rick Johnson wrote: > On Wednesday, February 6, 2013 7:36:28 PM UTC-6, Ethan Furman wrote: >> As Michael Torrie pointed out, the 'global' keyword is needed: > > Wrong. The global keyword is in fact NOT needed and something i > consider to be another wart of the language (Py

Re: best way to share an instance of a class among modules?

2013-02-07 Thread Rick Johnson
On Wednesday, February 6, 2013 7:36:28 PM UTC-6, Ethan Furman wrote: > As Michael Torrie pointed out, the 'global' keyword is needed: Wrong. The global keyword is in fact NOT needed and something i consider to be another wart of the language (PyWart on this subject coming soon!). Now, whilst Mi

Re: best way to share an instance of a class among modules?

2013-02-06 Thread Ethan Furman
On 02/06/2013 04:57 PM, Ethan Furman wrote: On 02/06/2013 04:43 PM, c wrote: But the function in the module is also within a *class* so I don't think the function does have access to the module's global namespace. Here's the hierarchy: -- Module namespace class namespace (Database

Re: best way to share an instance of a class among modules?

2013-02-06 Thread Ethan Furman
On 02/06/2013 04:43 PM, c wrote: But the function in the module is also within a *class* so I don't think the function does have access to the module's global namespace. Here's the hierarchy: -- Module namespace class namespace (DatabaseAccess is the name of the class) --

Re: best way to share an instance of a class among modules?

2013-02-06 Thread Michael Torrie
On 02/06/2013 05:45 PM, CM wrote: > But the function in the module is also within a *class* so I don't > think the function does have access to the module's global namespace. > Here's the hierarchy: > > -- Module namespace > class namespace (DatabaseAccess is the name of the class) >

Re: best way to share an instance of a class among modules?

2013-02-06 Thread CM
I was using self correctly, I think; but I should have said that the code in the importing module would be within a class, so self there refers to that class. But that's a side point. I agree that utilities.shared_cursor is visible within the importing module. But the problem below remains for m

Re: best way to share an instance of a class among modules?

2013-02-06 Thread c
On Feb 6, 7:03 pm, Michael Torrie wrote: > On 02/06/2013 03:41 PM, CM wrote: > > > Thank you.  But, I'm sorry, I'm not following this enough to get it to > > work.  Shouldn't it be a little more like this: > > No, not exactly. > > > > > # in utilities module > > shared_cursor =  DatabaseAccess_ins

Re: best way to share an instance of a class among modules?

2013-02-06 Thread Michael Torrie
On 02/06/2013 05:03 PM, Michael Torrie wrote: > Every function in a module has access to the module's global namespace. > And your shared_cursor is there, inside of the utilities reference, > since utilities was imported into your module, "importer." Just to be clear: mod1.py: a=5 -

Re: best way to share an instance of a class among modules?

2013-02-06 Thread Michael Torrie
On 02/06/2013 03:41 PM, CM wrote: > Thank you. But, I'm sorry, I'm not following this enough to get it to > work. Shouldn't it be a little more like this: No, not exactly. > > # in utilities module > shared_cursor = DatabaseAccess_instance #but how? see my question > below... How what? > #

Re: best way to share an instance of a class among modules?

2013-02-06 Thread CM
On Feb 6, 12:04 am, Terry Reedy wrote: > On 2/5/2013 11:40 PM, CM wrote: > > > > > > > > > > > I have recently moved all my SQLite3 database-related functions into a > > class, DatabaseAccess, that lives in a "utilities" module.  When the > > application loads, the namespace of the instance of the

Re: best way to share an instance of a class among modules?

2013-02-05 Thread Terry Reedy
On 2/5/2013 11:40 PM, CM wrote: I have recently moved all my SQLite3 database-related functions into a class, DatabaseAccess, that lives in a "utilities" module. When the application loads, the namespace of the instance of the class is populated with two different cursors for two different datab

best way to share an instance of a class among modules?

2013-02-05 Thread CM
I have recently moved all my SQLite3 database-related functions into a class, DatabaseAccess, that lives in a "utilities" module. When the application loads, the namespace of the instance of the class is populated with two different cursors for two different databases the whole application needs t