Python
  Home arrow Python arrow Object Orientation in Python
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Rational Software Development Conference
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PYTHON

Object Orientation in Python
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 30
    2005-02-14

    Table of Contents:
  • Object Orientation in Python
  • Another Way to Understand Object Orientation
  • Classes in Python
  • More About Creating Classes

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    PCmover - $15 Off with Coupon Code CJPH7Q

    Object Orientation in Python
    (Page 1 of 4 )

    Python is a very object-oriented language, which makes it easy to work with. For those of you who may not be familiar with the concept of object-oriented programming languages, Peyton provides a complete, easy-to-understand explanation, and then gives a number of examples that illustrate how object orientation works in Python.

     

    It seems that everywhere you go, you hear the term "object orientation" in relation to programming. However, it is a concept that many newcomers don't understand, especially if they are starting in languages that feature little or no object orientation.

    In this article, we'll take a look at what object orientation is, the benefits it provides programmers and its impact on the programming community.

     

    Object Orientation 101

     

    Before we talk about what object orientation is, let's talk about what object orientation isn't. Object orientation isn't a simple string spat out sending a greeting to the world. Object orientation isn't a variable  modified by an external function, either. Think of a basic variable in, say, PHP. It's just a container and nothing more. It doesn't have a shape. It doesn't have mass. It doesn't have a color. It's just a void. (I have nothing against PHP, by the way, and I am aware that PHP is indeed object-oriented to an extent. This is merely an example.)

     

    Now we'll dive into what object orientation is. Object orientation is all about, obviously, objects. These objects have their own data and their own methods that act on the data. For example, let's look this code:

     

    aFile = open ( 'someFile.txt', 'w' )

     

    The variable aFile is an object. Why? First of all, it has its own attributes which describe it:

     

    aFile.closed

    aFile.encoding

    aFile.mode

    aFile.name

    aFile.newlines

    aFile.softSpace

     

    It also has its own methods. Methods are similar to functions, but they belong to objects and perform actions to the object's data:

     

    aFile.close()

    aFile.flush()

    aFile.fileno()

    aFile.isatty()

    aFile.next()

    aFile.read()

    aFile.readline()

    aFile.readlines()

    aFile.xreadlines()

    aFile.seek()

    aFile.tell()

    aFile.truncate()

    aFile.write()

    aFile.writelines()

     

    More Python Articles
    More By Peyton McCullough


       · I thought this was a well written article - thanks for the contribution.
       · This is a great article for someone with no object oriented experience. I suggest...
       · Thanks for the input! :)Anyone else?
       · PeytonWhy dont you write a series on this topic for us. Id love to see it....
       · This was by far one of the easiest to follow tutotials on object oriented...
       · I've been reding all your recent articles. It's good work - Thanks for...
       · Thanks!
       · Although this article is quite interesting, it may bring confusion between class and...
       · The examples are irritating rather than funny. Fix those (by making them concrete)...
       · This program don't work.>>> aa =SomeClass()>>> aa.SomeNumber()Traceback...
       · <a href="{link1}">{text1}</a>, <a href="{link2}">{text2}</a>
       · <a href="{link1}">{text1}</a>, <a href="{link2}">{text2}</a>
     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway