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

Ethan Furman ethan at stoneleaf.us
Wed Feb 6 19:57:38 EST 2013


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)
>           ---- function namespace
>                This is where the cursor is created.  How do I get it
> into the module namespace?

In the class namespace you have something like:

         self.shared_cursor = ...

to get that into the module namespace instead, just remove the 'self':

         shared_cursor = ...

--
~Ethan~




More information about the Python-list mailing list