Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > [newbie] Looking for a good introduction to object orientedprogramming with Python

Reply
Thread Tools

[newbie] Looking for a good introduction to object orientedprogramming with Python

 
 
Jean Dubois
Guest
Posts: n/a
 
      08-04-2012
I'm looking for a good introduction to object oriented programming
with Python. I am looking for an introduction which only refers to
Python. I have seen introductions where the authors make comparisons
to other languages such as C++ and Java, but as I don't know these
languages that doesn't help me further much, it rather confuses me. I
also found an introduction in which the author started by telling that
"object oriented programming is weird", such a statement did stop me
reading further as I think an author should at least believe in the
topic he is going to present as being logical.
If someone here has a link or title to such an intro, I'd appreciate
that very much

regards,
Jean
p.s. People who don't like my style of asking questions, please
neglect this message
 
Reply With Quote
 
 
 
 
shearichard@gmail.com
Guest
Posts: n/a
 
      08-05-2012
One reason you may be having difficulty is that unlike some languages (C++/Java) object-orientation is not a be all and end all in Python, in fact youcould work with Python for a long time without really 'doing it' at all (well other than calling methods/properties on existing API's). Having said that here's what I would suggest ...

Could do worse than this :

http://www.diveintopython.net/object...ork/index.html

and this

http://docs.python.org/tutorial/classes.html

read together.

Judging by your question this is a probably a little advanced for now but you could bookmark it for the future:

http://www.catonmat.net/blog/learnin...ideo-lectures/

Here's the corresponding PDF to go with the video:

http://assets.en.oreilly.com/1/event...esentation.pdf

 
Reply With Quote
 
 
 
 
Jean Dubois
Guest
Posts: n/a
 
      08-05-2012
On 5 aug, 02:11, shearich...@gmail.com wrote:
> One reason you may be having difficulty is that unlike some languages (C++/Java) object-orientation is not a be all and end all in Python, in fact you could work with Python for a long time without really 'doing it' at all (well other than calling methods/properties on existing API's). Having saidthat here's what I would suggest ...
>
> Could do worse than this :
>
> http://www.diveintopython.net/object...ork/index.html
>
> and this
>
> http://docs.python.org/tutorial/classes.html
>
> read together.
>
> Judging by your question this is a probably a little advanced for now butyou could bookmark it for the future:
>
> http://www.catonmat.net/blog/learnin...terns-through-...
>
> Here's the corresponding PDF to go with the video:
>
> http://assets.en.oreilly.com/1/event...hon%20Patterns...


Thanks a lot for this information, I'll check it out the following
days

best regards,
Jean
 
Reply With Quote
 
Jean Dubois
Guest
Posts: n/a
 
      08-05-2012
On 5 aug, 02:11, shearich...@gmail.com wrote:
> One reason you may be having difficulty is that unlike some languages (C++/Java) object-orientation is not a be all and end all in Python, in fact you could work with Python for a long time without really 'doing it' at all (well other than calling methods/properties on existing API's). Having saidthat here's what I would suggest ...
>
> Could do worse than this :
>
> http://www.diveintopython.net/object...ork/index.html
>

This example seems to tell you need the concept of dictionaries to
explain object oriented programming, is this really necessary?
> and this
>
> http://docs.python.org/tutorial/classes.html

Unfortunately, the trouble with this explanation is exactly what made
me ask the original question: it starts from concepts in c++ making it
very hard to understand for someone who does not know that language
already.
>
> read together.
>
> Judging by your question this is a probably a little advanced for now butyou could bookmark it for the future:
>
> http://www.catonmat.net/blog/learnin...terns-through-...
>
> Here's the corresponding PDF to go with the video:
>
> http://assets.en.oreilly.com/1/event...hon%20Patterns...

Can someone here on this list give a trivial example of what object
oriented programming is, using only Python?

thanks in advance
Jean
 
Reply With Quote
 
Mark Lawrence
Guest
Posts: n/a
 
      08-05-2012
On 05/08/2012 19:04, Jean Dubois wrote:
> On 5 aug, 02:11, shearich...@gmail.com wrote:
>> One reason you may be having difficulty is that unlike some languages (C++/Java) object-orientation is not a be all and end all in Python, in fact you could work with Python for a long time without really 'doing it' at all (well other than calling methods/properties on existing API's). Having said that here's what I would suggest ...
>>
>> Could do worse than this :
>>
>> http://www.diveintopython.net/object...ork/index.html
>>

> This example seems to tell you need the concept of dictionaries to
> explain object oriented programming, is this really necessary?
>> and this
>>
>> http://docs.python.org/tutorial/classes.html

> Unfortunately, the trouble with this explanation is exactly what made
> me ask the original question: it starts from concepts in c++ making it
> very hard to understand for someone who does not know that language
> already.
>>
>> read together.
>>
>> Judging by your question this is a probably a little advanced for now but you could bookmark it for the future:
>>
>> http://www.catonmat.net/blog/learnin...terns-through-...
>>
>> Here's the corresponding PDF to go with the video:
>>
>> http://assets.en.oreilly.com/1/event...hon%20Patterns...

> Can someone here on this list give a trivial example of what object
> oriented programming is, using only Python?
>
> thanks in advance
> Jean
>


Try this http://www.voidspace.org.uk/python/articles/OOP.shtml ???

--
Cheers.

Mark Lawrence.

 
Reply With Quote
 
Roy Smith
Guest
Posts: n/a
 
      08-05-2012
In article
<8f1b60a5-0411-4aae-9ee6->,
Jean Dubois <> wrote:

> Can someone here on this list give a trivial example of what object
> oriented programming is, using only Python?


OOP seems to mean different things to different people. What OOP means
to you is usually a strong function of whatever OOP language you learned
first. That being said, I think the fundamental, universal, core
principle of OOP is that an object contains some data, and some code
that knows how to do something with that data.

So, to give you a simple (but real-life) example, the system I'm working
in now has User objects. A user is a pretty complicated class, but
here's some simple methods from it:

def __eq__(self, other):
return isinstance(other, (User, AnonymousUser)) \
and self.user_id == other.user_id

def __unicode__(self):
return self.username

def __repr__(self):
return '<User %d: %r>' % (self.user_id, self.username)

This defines a few basic behaviors for User objects.

First, it defines how to tell if something is equal to a given User
object. The something must itself be a User (ignore the minor
complication about AnonymousUser for the moment), and it must have the
same user_id as this one. I could easily imagine lots of other possible
ways two users could be considered equal (same username, for example),
but we're using user_id. This means I can write:

if user1 == user2:
print "they're the same"

and I don't have to worry about (or even know about) the details. In
fact, sometime long after I've written that code, somebody could define
some new kind of HighSecurityUser which tests for equality by comparing
the scanned retina images for both of them. My code wouldn't have to
change; it would magically just start enforcing retina matching.

Likewise, I can write:

print user

or

logger.warning("%r did something interesting", user)

and I don't have to know anything about how to print a User. The User
knows how to print itself.
 
Reply With Quote
 
Mark Lawrence
Guest
Posts: n/a
 
      08-05-2012
On 05/08/2012 19:43, Ifthikhan Nazeem wrote:
[top posting fixed]
>
> On Sun, Aug 5, 2012 at 8:28 PM, Mark Lawrence <>wrote:
>
>> On 05/08/2012 19:04, Jean Dubois wrote:
>>
>>> On 5 aug, 02:11, shearich...@gmail.com wrote:
>>>
>>>> One reason you may be having difficulty is that unlike some languages
>>>> (C++/Java) object-orientation is not a be all and end all in Python, in
>>>> fact you could work with Python for a long time without really 'doing it'
>>>> at all (well other than calling methods/properties on existing API's).
>>>> Having said that here's what I would suggest ...
>>>>
>>>> Could do worse than this :
>>>>
>>>> http://www.diveintopython.net/**object_oriented_framework/**index.html<http://www.diveintopython.net/object_oriented_framework/index.html>
>>>>
>>>> This example seems to tell you need the concept of dictionaries to
>>> explain object oriented programming, is this really necessary?
>>>
>>>> and this
>>>>
>>>> http://docs.python.org/**tutorial/classes.html<http://docs.python.org/tutorial/classes.html>
>>>>
>>> Unfortunately, the trouble with this explanation is exactly what made
>>> me ask the original question: it starts from concepts in c++ making it
>>> very hard to understand for someone who does not know that language
>>> already.
>>>
>>>>
>>>> read together.
>>>>
>>>> Judging by your question this is a probably a little advanced for now
>>>> but you could bookmark it for the future:
>>>>
>>>> http://www.catonmat.net/blog/**learn...thon-design-**
>>>> patterns-through-.<http://www.catonmat.net/blog/learning-python-design-patterns-through-.>
>>>> ..
>>>>
>>>> Here's the corresponding PDF to go with the video:
>>>>
>>>> http://assets.en.oreilly.com/**1/eve...al%20Python%**
>>>> 20Patterns.<http://assets.en.oreilly.com/1/event/45/Practical%20Python%20Patterns.>
>>>> ..
>>>>
>>> Can someone here on this list give a trivial example of what object
>>> oriented programming is, using only Python?
>>>
>>> thanks in advance
>>> Jean
>>>
>>>

>> Try this http://www.voidspace.org.uk/**python/articles/OOP.shtml<http://www.voidspace.org.uk/python/articles/OOP.shtml>???
>>
>> --
>> Cheers.
>>
>> Mark Lawrence.
>>
>> --
>> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>>

>
> I would recommend Bruce Eckel's Thining in Python. Check it out here
> http://www.mindview.net/Books/TIPython/
>
>


I'd forgotten about that so thanks for the reminder.

--
Cheers.

Mark Lawrence.

 
Reply With Quote
 
dncarac@gmail.com
Guest
Posts: n/a
 
      08-05-2012
I found Mark Lutz's book Learning Python had two or three chapters on object oriented programming from starting principles to more involved Python object programming. It helped me immensely.
 
Reply With Quote
 
Mark Lawrence
Guest
Posts: n/a
 
      08-05-2012
On 05/08/2012 20:46, lipska the kat wrote:

[snip]

> There is a book you could try, it's a bit dry and I read it when I can't
> sleep, about 30 mins usually does it
> It's called Design Patterns by Gamma, Helm, Johnson and Vlissides
> ISBN 0-201-63361-2.
> They do use C++ code in examples but as they say, this is just a
> convenience and shouldn't colour your view of the subject
> I still read the introduction and get something out of it after several
> years. You should be able to implement the patterns in Python
> although I must admit I haven't tried that yet
>


Please no, that's the worst possible book for someone trying to learn
OOD in Python. It's mostly if not completely irrelevant, jumping
through hoops that you don't need in Python because of its dynamic
nature. Start with the factory pattern and I hope you'll understand why
I say this. Search for "design patterns alex martelli" and you'll get
all you need and more.

> lipska
>
>
>


--
Cheers.

Mark Lawrence.

 
Reply With Quote
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      08-05-2012
On Sun, 5 Aug 2012 11:04:36 -0700 (PDT), Jean Dubois
<> declaimed the following in
gmane.comp.python.general:

> Unfortunately, the trouble with this explanation is exactly what made
> me ask the original question: it starts from concepts in c++ making it
> very hard to understand for someone who does not know that language
> already.


Then maybe you are asking the wrong question...

Don't look for Object-Oriented Programming -- since the first widely
popular OOP language was C++ (Smalltalk was earlier, but rather
specialized, whereas C++ started as a preprocessor for C).

Rather look for Object-Oriented Analysis and Design (OOAD). An OOAD
textbook /should/ be language neutral and, these days, likely using the
constructs/notation of UML [which derived from a merger of two or three
separate proposals for OOAD tools]

An OOAD text should cover, besides Classes, Use Cases, state
diagrams, and lots of other things...

The short view of a Class is that it is a means of encapsulating the
methods (functions/operations) of an object along with the attributes
(data) of a specific instance of the class.

A Radio Class would define methods to change the volume, power
state, tuning, and band. These methods are common to all radios. But an
instance of a radio doesn't share its volume level with all other
instances of the Radio class.


OOP is more a style/philosophy of programming by using "objects".
Ada 95 is an OOP language but didn't have the
"object.method(parameters)" syntax (one had to use "method(object,
parameters", but the language could determine which of similar named
methods was meant based upon the type of "object" and the types of the
parameters).
--
Wulfraed Dennis Lee Bieber AF6VN
HTTP://wlfraed.home.netcom.com/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OT: Good introduction to CPU/Memory terms Seeker C Programming 19 06-30-2006 07:42 PM
Seeking a good C introduction book Xiaoshen Li C Programming 1 11-08-2005 12:27 AM
Is there any good introduction books on C++multithread programming QQ C++ 3 05-17-2005 11:35 PM
Is There a Good Introduction to or Reference Concerning . . . . mimus DVD Video 14 03-08-2005 02:34 AM
looking for a good introduction to OOP Darren Dale Python 4 11-24-2004 03:37 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57