Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101464
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2016-01-10 22:45 -0800 |
| References | <c0bb7499-c359-4010-aac2-270d1b82a47d@googlegroups.com> <mailman.3.1452438172.3151.python-list@python.org> |
| Message-ID | <dcc532c3-c8ab-45f0-8fea-ef1fe8ad6af3@googlegroups.com> (permalink) |
| Subject | Re: When I need classes? |
| From | Arshpreet Singh <arsh840@gmail.com> |
On Sunday, 10 January 2016 20:33:20 UTC+5:30, Michael Torrie wrote: > This way I can import functions defined in this script into another > script later if I want. > > If I find I need to share state between functions, and if I find that I > might need to have multiple situations of shared state possibly at the > same time, then I will refactor the script into a class. Despite the > apparent shame of using global variables, if I need to share state > between functions, but I cannot ever foresee a time when I'll need to > have multiple instances of that state, I have a case in Flask-Oauth2 where one function returns Username, Email ID and Authorised Token. So I can make that function Global and access EMail,username and Authorised token from any other Script. Or I can make it class? >then I'll just use a module-level > global variable and continue to use normal functions, rather than define > a class. In the parlance of OOP, this use case would be referred to as > a "singleton" and a python module (a script) is a form of singleton > already, even without using classes. Is it also true that Classes(OOP) help to optimise code(uses less memory) rather than just doing things with functions.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
When I need classes? Arshpreet Singh <arsh840@gmail.com> - 2016-01-09 23:29 -0800
Re: When I need classes? Michael Torrie <torriem@gmail.com> - 2016-01-10 08:02 -0700
Re: When I need classes? Arshpreet Singh <arsh840@gmail.com> - 2016-01-10 22:45 -0800
Re: When I need classes? Cameron Simpson <cs@zip.com.au> - 2016-01-11 18:27 +1100
Re: When I need classes? Steven D'Aprano <steve@pearwood.info> - 2016-01-11 02:39 +1100
Re: When I need classes? Bernardo Sulzbach <mafagafogigante@gmail.com> - 2016-01-10 15:48 -0200
Re: When I need classes? Arshpreet Singh <arsh840@gmail.com> - 2016-01-10 22:24 -0800
Re: When I need classes? Arshpreet Singh <arsh840@gmail.com> - 2016-01-10 22:28 -0800
Re: When I need classes? Travis Griggs <travisgriggs@gmail.com> - 2016-01-11 15:45 -0800
Re: When I need classes? Mike S <mscir@yahoo.com> - 2016-01-13 22:27 -0800
Re: When I need classes? Michael Torrie <torriem@gmail.com> - 2016-01-11 16:59 -0700
Re: When I need classes? Bernardo Sulzbach <mafagafogigante@gmail.com> - 2016-01-11 22:53 -0200
Re: When I need classes? Chris Angelico <rosuav@gmail.com> - 2016-01-12 12:28 +1100
Re: When I need classes? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-01-13 10:01 +1300
Re: When I need classes? Bernardo Sulzbach <mafagafogigante@gmail.com> - 2016-01-12 19:08 -0200
Re: When I need classes? Ian Kelly <ian.g.kelly@gmail.com> - 2016-01-12 17:18 -0700
Re: When I need classes? Steven D'Aprano <steve@pearwood.info> - 2016-01-13 12:33 +1100
Re: When I need classes? Rustom Mody <rustompmody@gmail.com> - 2016-01-12 19:36 -0800
Re: When I need classes? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-01-13 16:27 +1100
Re: When I need classes? Rustom Mody <rustompmody@gmail.com> - 2016-01-12 22:31 -0800
Re: When I need classes? Rustom Mody <rustompmody@gmail.com> - 2016-01-13 08:33 -0800
Re: When I need classes? Rick Johnson <rantingrickjohnson@gmail.com> - 2016-01-14 10:00 -0800
csiph-web