When I need classes?

Rustom Mody rustompmody at gmail.com
Tue Jan 12 22:36:47 EST 2016


On Sunday, January 10, 2016 at 1:00:13 PM UTC+5:30, Arshpreet Singh wrote:
> Hello Friends, I am quite new to OOP(object oriented Programming), I did some projects with python which includes Data-Analysis, Flask Web Development and some simple scripts. 
> 
> I have only one question which is bothering me most of the time, When I will get the need to use Classes in Python? Or in other way is there any real-life example where you can tell me this problem/solution is kind of impossible in Python without Classes?

I think the answers so far dont cover two complementary sides to this question:

1. Python the LANGUAGE, is rather even-handed in paradigm choice: Choose OO, imperative, functional or whatever style pleases/suits you
2. Python LIBRARIES however need to make committing choices.  Users of those 
then need to align with these.

egs 
1. Majority of basic python is functional; eg stuff in os module

2. Some things need object creation and method call
eg for re-s you need to know about and to use re objects, match objects etc

3. Then there are things that are naturally used by inheriting and extending
eg Basehttpserver is typically used via inheritance
To use these you need to know basic OO

4. Then there may be things whose natural usage needs multiple inheritance
[cant think of examples]

So as others have said, in principle you dont need to go beyond 1.
Unfortunately when you are using non-trivial libraries you are a user both of
python and the library and so the library-author's paradigm choices are a given
for you



More information about the Python-list mailing list