Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80065

Re: Classes

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'class,': 0.07; 'none:': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'width': 0.09; 'def': 0.12; 'windows': 0.15; '"python': 0.16; '(self):': 0.16; '>on': 0.16; 'equal.': 0.16; 'length,': 0.16; 'message- id:@4ax.com': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:Classes': 0.16; "where's": 0.16; 'wrote:': 0.18; 'print': 0.22; 'url:home': 0.24; 'mention': 0.26; 'pass': 0.26; 'skip:_ 20': 0.27; 'header:X -Complaints-To:1': 0.27; 'rest': 0.29; '(c)': 0.29; '2009': 0.29; '-0700,': 0.31; 'enforce': 0.31; 'class': 0.32; 'skip:c 30': 0.32; 'fri,': 0.33; 'skip:_ 10': 0.34; 'but': 0.35; 'charset:us-ascii': 0.36; 'to:addr:python-list': 0.38; 'skip:- 10': 0.38; 'use.': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'called': 0.40; 'skip:2 20': 0.60; 'length': 0.61; 'confirm': 0.64; 'side': 0.67; 'reserved.': 0.68; 'square': 0.74; 'received:108': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: Classes
Date Fri, 31 Oct 2014 18:57:31 -0400
Organization IISS Elusive Unicorn
References <51755at03r0bidjqh3qf0hhpvjr8756ill@4ax.com> <545350c3$0$23449$426a74cc@news.free.fr> <bj575ahusmihp1fpm58gmcr2eg0g8k21o6@4ax.com> <5453c1a6$0$12981$c3e8da3$5496439d@news.astraweb.com> <7pg75alj1qn97hlirk81f7nqd265emgu05@4ax.com> <20141031104319.02e1ca6f@rg.highlandtechnology.com> <cik75a5rjdg19jn7dacfqk6esdprbn71gi@4ax.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host adsl-108-79-221-33.dsl.klmzmi.sbcglobal.net
X-Newsreader Forte Agent 6.00/32.1186
X-No-Archive YES
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15375.1414796262.18130.python-list@python.org> (permalink)
Lines 89
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1414796262 news.xs4all.nl 2959 [2001:888:2000:d::a6]:55643
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80065

Show key headers only | View raw


On Fri, 31 Oct 2014 14:18:44 -0400, Seymore4Head
<Seymore4Head@Hotmail.invalid> declaimed the following:

>On Fri, 31 Oct 2014 10:43:19 -0700, Rob Gaddi
><rgaddi@technologyhighland.invalid> wrote:
>
>
>>Define a Square class, subclassed from Rectangle.  Use getters/setters
>>to enforce that the length and width must be equal.  Confirm that
>>length and width remain locked, and that perimeter() and area() work
>>correctly.
>
>class Rectangle:
>    def __init__(self,length,width):
>        self.length=length
>        self.width=width
>    def area(self):
>        return self.length*self.width
>    def perimeter(self):
>        return 2*self.length+2*self.width
>class Square(Rectangle):
>    def set_side (self):
>        if self.length!=self.width:
>           
	Where's the rest of that -- not to mention you called it "set_side" but
never pass a side into it for use.
 
-=-=-=-=-=-=-=-

class Rectangle(object):
    def __init__(self, length, width=None):
        self.length = length
        if width is None:
            self.width = length
        else:
            self.width = width
    def area(self):
        return self.length * self.width
    def perimeter(self):
        return 2 * (self.length + self.width)

class Square(Rectangle):
    def __init__(self, side):
        self.side = side
    def _getLength(self):
        return self.side
    def _getWidth(self):
        return self.side
    def _setLength(self, vlu):
        self.side = vlu
    def _setWidth(self, vlu):
        self.side = vlu
    length = property(_getLength, _setLength)
    width = property(_getWidth, _setWidth)

aRect = Rectangle(2, 4)
print aRect.length, aRect.width, aRect.area(), aRect.perimeter()
aRect.length = 9
print aRect.length, aRect.width, aRect.area(), aRect.perimeter()


aSqr = Square(3)
print aSqr.side, aSqr.length, aSqr.width, aSqr.area(), aSqr.perimeter()
aSqr.length = 4
print aSqr.side, aSqr.length, aSqr.width, aSqr.area(), aSqr.perimeter()
aSqr.width = 5
print aSqr.side, aSqr.length, aSqr.width, aSqr.area(), aSqr.perimeter()
aSqr.side = 7
print aSqr.side, aSqr.length, aSqr.width, aSqr.area(), aSqr.perimeter()

-=-=-=-=-=-=-=-=-
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Wulfraed\Documents>cd "Python Progs"

C:\Users\Wulfraed\Documents\Python Progs>property2.py
2 4 8 12
9 4 36 26
3 3 3 9 12
4 4 4 16 16
5 5 5 25 20
7 7 7 49 28

C:\Users\Wulfraed\Documents\Python Progs>
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Classes   Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-30 16:16 -0400
  Re: Classes sohcahtoa82@gmail.com - 2014-10-30 13:33 -0700
    Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-30 17:00 -0400
  Re: Classes Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-10-30 13:34 -0700
    Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-30 17:00 -0400
  Re: Classes Larry Hudson <orgnut@yahoo.com> - 2014-10-30 14:28 -0700
    Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-30 17:34 -0400
      Re: Classes sohcahtoa82@gmail.com - 2014-10-30 18:21 -0700
      Re: Classes alister <alister.nospam.ware@ntlworld.com> - 2014-10-31 09:59 +0000
        Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 10:07 -0400
  Re: Classes   "ast" <nomail@invalid.com> - 2014-10-31 10:05 +0100
    Re: Classes   "ast" <nomail@invalid.com> - 2014-10-31 10:18 +0100
      Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-10-31 20:21 +1100
    Re: Classes   Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 10:05 -0400
      Re: Classes Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-31 08:47 -0600
        Re: Classes Grant Edwards <invalid@invalid.invalid> - 2014-10-31 15:49 +0000
          Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 12:31 -0400
            Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-11-01 03:37 +1100
              Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 12:47 -0400
                Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-11-01 04:02 +1100
                Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 13:31 -0400
                Re: Classes Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-10-31 12:39 -0500
                Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 13:57 -0400
                Re: Classes Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-10-31 10:40 -0700
                Re: Classes Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-11-01 11:17 +1300
                Re: Classes Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-01 12:06 +1100
                Re: Classes Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-01 00:12 -0600
                Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-11-01 17:32 +1100
                Re: Classes Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-11-03 00:32 +1300
            Re: Classes Dave Angel <davea@davea.name> - 2014-10-31 13:20 -0400
            Re: Classes Marko Rauhamaa <marko@pacujo.net> - 2014-10-31 19:35 +0200
            Re: Classes Grant Edwards <invalid@invalid.invalid> - 2014-10-31 17:40 +0000
            Re: Classes Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-31 18:26 -0400
              Re: Classes Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-01 12:09 +1100
      Re: Classes   Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-01 04:06 +1100
        Re: Classes   Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 13:18 -0400
          Re: Classes Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-10-31 10:43 -0700
            Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 14:18 -0400
              Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 14:42 -0400
              Re: Classes Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-31 18:57 -0400
                Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 19:22 -0400
                Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 19:32 -0400
                Re: Classes Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-11-01 12:00 -0400
                Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-11-01 12:42 -0400
                Re: Classes Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-02 09:50 +0000
                Re: Classes Tim Delaney <timothy.c.delaney@gmail.com> - 2014-11-02 21:32 +1100
                Re: Classes Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-02 12:27 +0000
                Re: Classes Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-11-02 11:31 -0500
                Re: Classes Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-03 03:12 +0000
                Re: Classes Dan Sommers <dan@tombstonezero.net> - 2014-11-03 06:29 +0000
                Re: Classes Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-04 01:10 +0000
                Re: Classes Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-11-04 18:30 +1300
                Re: Classes Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-11-03 08:50 -0500
                Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-11-04 02:34 +1100
                Re: Classes Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-03 07:47 -0700
                Re: Classes Larry Hudson <orgnut@yahoo.com> - 2014-11-02 14:03 -0800
            Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-11-01 07:51 +1100
              Re: Classes sohcahtoa82@gmail.com - 2014-10-31 14:24 -0700
                Re: Classes Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-10-31 14:40 -0700
                Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-11-01 08:56 +1100
                Re: Classes Chris Angelico <rosuav@gmail.com> - 2014-11-01 08:36 +1100
          Re: Classes Grant Edwards <invalid@invalid.invalid> - 2014-10-31 17:43 +0000
    Re: Classes Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-31 14:11 +0000
    Re: Classes   Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 12:49 -0400
      Re: Classes   "ast" <nomail@invalid.com> - 2014-10-31 19:31 +0100
        Re: Classes   Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 14:36 -0400
        Re: Classes Joel Goldstick <joel.goldstick@gmail.com> - 2014-10-31 14:41 -0400
          Re: Classes Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-31 14:56 -0400

csiph-web