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

 
Developer Updates  
Free Website Content 
 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: starstarstarstarstar / 34
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    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
     

       

    PYTHON ARTICLES

    - Tuples and Other Python Object Types
    - The Dictionary Python Object Type
    - String and List Python Object Types
    - Introducing Python Object Types
    - Mobile Programming using PyS60: Advanced UI ...
    - Nested Functions in Python
    - Python Parameters, Functions and Arguments
    - Python Statements and Functions
    - Statements and Iterators in Python
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - SSH with Twisted





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT