473,324 Members | 2,581 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,324 software developers and data experts.

Make instance global -- possbile?


Rather new to OOP in Python...

I'm writing an app where several objects need to access and change the
state of ONE instance.

I could of course instantiate the instance and then pass it along the
objects, but that's cumbersome, especially as it would need to be
"passed through" classes that don't really need it.

I would be happy if I could just instantiate the object in the main
module and declare it global, but classes are in different modules so
I guess that won't work.

Have looked a bit into singletons -- is that the way to go?

Mar 5 '07 #1
1 1687
On Mar 5, 10:00 pm, ero...@gmail.com wrote:
Rather new to OOP in Python...

I'm writing an app where several objects need to access and change the
state of ONE instance.

I could of course instantiate the instance and then pass it along the
objects, but that's cumbersome, especially as it would need to be
"passed through" classes that don't really need it.

I would be happy if I could just instantiate the object in the main
module and declare it global, but classes are in different modules so
I guess that won't work.

Have looked a bit into singletons -- is that the way to go?
Put your 'global' stuff into a module and use import?

--
Arnaud

Mar 5 '07 #2

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

Similar topics

34
by: SeeBelow | last post by:
I see the value of a class when two or more instances will be created, but Python programmers regularly use a class when there will only be one instance. What is the benefit of this? It has a...
4
by: Krice | last post by:
Is it possible that construction of a global instance can fail? I'm suspecting this because the program seems to crash before main(). Is it a better practice to declare a pointer for the object...
1
by: Poewood | last post by:
I have created control array classes for buttons and textboxes and affixed them to a form class. In VB I can easily create a module with fuctions that can be accessed from any class. How can I do...
1
by: localhost | last post by:
In the Application_OnStart, I make some data calls and place the results in the HTTP cache. Sometimes, the database is not available when the application starts up, so I want to sleep for 20...
8
by: Thomas Coleman | last post by:
Ok, I've obviously discovered that Global.aspx has been completely changed in ..NET 2.0. However, I haven't figured out how to declare a constant that's available to any page in my application...
3
by: Adam | last post by:
We have a web site that uses .vb for the web pages and .cs for a class module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does work with .NET 1.1. When trying to access a page...
1
by: otto | last post by:
I have a technical question about WebServices. I have a solution with several projects (.exe and .dll). Each project have references to several webservices. I want to know if is possible to create...
0
by: swartzbill2000 | last post by:
I have a global instance of a MyDataSet and a global instance of a MDI child form containing a DataGridView. In the designer, it looks like an instance of the DataSet got added to the form and the...
13
by: JohnQ | last post by:
Why would anyone write: class SomeThing // class littered with non-domain single-instancing code :( { private: SomeThing(); static SomeThing* pInstance_; public: static SomeThing*...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.