Python Forum
Why do we learn singletons in python?
Thread Rating:
  • 2 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why do we learn singletons in python?
#1
my question here
I just learn singletons and what i know is the main purpose is that you can create a unique instance of a particular type

But what is the real use of it on programming like where do we use it on games, Applications? 
Can you guys give me an examples of how can i use it? 
Thanks
Reply
#2
I use singleton-like classes in games, however i dont do anything to make them restrict the use to one object, i just dont make a second object to begin with. Im thinking stuff like the main controller of the game, or to switch between states of the game. There will only ever be one object of Control or each state, but i dont go out of my way to restrict it. I just never make a second object to begin with.
Recommended Tutorials:
Reply
#3
Think of the singletons in Python, like True/False and None. They are globally available unique values.

Now say you're doing survival analysis on engines. You track the time of failure, but some of them don't fail by the end of the experiment. This is called right-censored data, and is usually assigned a special value. So you might have a special value RightCensored for engines that don't fail, and make it a singleton.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#4
(Apr-09-2017, 09:02 AM)Qubayel Wrote: my question here
I just learn singletons and what i know is the main purpose is that you can create a unique instance of a particular type

But what is the real use of it on programming like where do we use it on games, Applications? 
Can you guys give me an examples of how can i use it? 
Thanks 

Typical use in an application:
  • The program configuration data
  • A database connection (it the app works with one single database)
  • The "display" object
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I really need help, I am new to python, I am using a book that helps me to learn JaprO 5 2,998 Nov-28-2020, 02:30 PM
Last Post: JaprO
  Want to learn Python compilation and virtual machine IJB 3 2,643 Feb-14-2020, 02:59 PM
Last Post: IJB
  What is the bestway to learn Python? PythonRIMD 2 2,414 Jan-11-2020, 04:12 PM
Last Post: joe_momma
  Beginner want to learn python Keenygp 5 3,295 Apr-10-2019, 09:36 AM
Last Post: KevinBrown
  [Python] Learn words' sentiment based on labels Artificious 1 3,046 Jul-05-2018, 10:44 PM
Last Post: Larz60+
  Learn Python 3 the Hard Way oldDog 1 2,970 May-31-2018, 04:50 PM
Last Post: wavic
  Exercise 20, Learn Python 3 the Hard Way Dixon 6 6,072 Feb-26-2018, 04:54 PM
Last Post: snippsat
  best way to learn python? Newtopython123 2 4,829 Jan-25-2018, 01:38 AM
Last Post: league55
  Starting to learn python on a Mac asifhoss 8 8,187 Jan-03-2018, 08:29 PM
Last Post: karaokelove

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020