473,387 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

static class variables and module scope

I have a singleton object that works perfectly from inside my main .py
file. However, when I want to access the object that backs the
singleton from another file ( either from an execfile() or thru my
telnet listener ), it appears the underlying object is reset to null,
resulting in a duplicate object being created.

I figure I am doing something painfully stupid, but for the life of me,
I can't see it.

Here is my singleton wrapper:

class SingletonWrapper:
__instance = None
def __init__ ( self, user = None, password = None ):
if SingletonWrapper.__instance is None:
SingletonWrapper.__instance = ImplSingletonWrapper ( user, password )
def instance ( self ):
return SingletonWrapper.__instance

In my ImplSingletonWrapper class, I print out that I am creating a new
object when its constructor is called. Inside the owner file, it is
only called once , but if I do SingletonWrapper().instance() from
anohter module, it makes a new object, and id() reports different ids.

I banged my head against this yesterday, and today doesn't seem to be
going any better, any ideas out there?

--
ch***@acheris.net | Fight Censorship, Boycott Wal-Mart
Now is the winter of your discontent! - Stewie
Jul 18 '05 #1
0 1205

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Datta Patil | last post by:
Hi , #include<stdio.h> func(static int k) /* point2 : why this is not giving error */ { int i = 10 ; // static int j = &i ; /* point 1: this will give compile time error */ return k; } /*...
2
by: JackRazz | last post by:
I'm trying to serialize a class using the binary formatter without serializing the 'static pastFirstCall as Boolean' variable. Normally private (module-scope) variables are serialized unless the...
2
by: JackRazz | last post by:
I'm trying to serialize a class using the binary formatter without serializing the 'static pastFirstCall as Boolean' variable. Normally private (module-scope) variables are serialized unless the...
9
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang...
2
by: Nagrik | last post by:
Dear Group, The book of Bjarne Stroustrup in chapter 5.4.4 says the following "The word static is one of the most overused words in C and C++. For static data members it has both of the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.