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


Groups > comp.lang.python > #79968 > unrolled thread

Classes

Started bySeymore4Head <Seymore4Head@Hotmail.invalid>
First post2014-10-30 16:16 -0400
Last post2014-10-31 14:56 -0400
Articles 8 on this page of 68 — 20 participants

Back to article view | Back to comp.lang.python


Contents

  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

Page 4 of 4 — ← Prev page 1 2 3 [4]


#80061

FromChris Angelico <rosuav@gmail.com>
Date2014-11-01 08:36 +1100
Message-ID<mailman.15372.1414791689.18130.python-list@python.org>
In reply to#80058
On Sat, Nov 1, 2014 at 8:24 AM,  <sohcahtoa82@gmail.com> wrote:
> I've never heard of the Circle-Ellipse problem, and my first instinct to Rob's post was to ask, why would you want to sub-class Rectangle into a Square class?  A square is just a special case of a Rectangle.  Attempting that kind of sub-classing would just cause problems.  The only thing you gain is a slight optimization in calculating perimeter by turning two multiplications and an addition into a single multiplication which really wouldn't have an effect on performance unless you were doing that calculation millions of times per second.
>

Yep. A square is indeed a special case of rectangle (and a circle is a
special case of ellipse), so it would make sense to have an
"is_square()" method (or isSquare or squarep or whatever you want to
call it). The hairiness of subclassing either to make the other means
it's an unideal example.

In fact, I would say the Python @property decorator is less well
suited to an inheritance situation than to a chronological change.
"This used to be a simple attribute, now it has
validation/formatting/logging/whatever." But it's hard to come up with
an example to illustrate this cleanly for a student. Personally, I'd
be inclined to skip properties altogether; learn about them later,
much later, and only if you actually need them.

ChrisA

[toc] | [prev] | [next] | [standalone]


#80042

FromGrant Edwards <invalid@invalid.invalid>
Date2014-10-31 17:43 +0000
Message-ID<m30ho7$bbh$2@reader1.panix.com>
In reply to#80033
On 2014-10-31, Seymore4Head <Seymore4Head@Hotmail.invalid> wrote:
> On Sat, 01 Nov 2014 04:06:44 +1100, Steven D'Aprano

>>Let's make the class a bit easier to use, at the expense of doing a bit more
>>work up front:
>>
>>class MyClass:
>>    def __init__(self, value, message):
>>        self.value = value
>>        self.message = message
>>
>>obj = MyClass(23.0, "hello world")
>>print(obj.value)
>>print(obj.message)
>>
>>
>>The __init__ method is automatically called when you call the class as if it
>>were a function. Because the __init__ method has two arguments (plus the
>>special "self" argument), you have to call the class with two arguments.
>>They get used as the value and message respectively.
>>
>>Or we can give it getters and setters:
>>
>>class MyClass:
>>    def set_value(self, value):
>>        self.value = value
>>    def get_value(self):
>>        return self.value
>>    def set_message(self, message):
>>        self.message = message
>>    def get_message(self):
>>        return self.message
>>
>>obj = MyClass()
>>obj.set_value(23.0)
>>obj.set_message("hello world")
>>print(obj.get_value())
>>print(obj.get_message())
>>
>>
>>If you're thinking that's a lot of extra work for not much benefit, 99.99%
>>of the time you're right.
>
> I agree it is more work.  But more work means more practice. I need
> more practice figuring out how these commands work.

Except you're practicing doing things the "wrong" way.  If you want to
learn Java, then use Java.  If you want to learn Python, then don't
write Java.

-- 
Grant Edwards               grant.b.edwards        Yow! HOORAY, Ronald!!
                                  at               Now YOU can marry LINDA
                              gmail.com            RONSTADT too!!

[toc] | [prev] | [next] | [standalone]


#80017

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-10-31 14:11 +0000
Message-ID<mailman.15355.1414764692.18130.python-list@python.org>
In reply to#80001
On 31/10/2014 09:05, ast wrote:
>
> "Seymore4Head" <Seymore4Head@Hotmail.invalid> a écrit dans le message de
> news:51755at03r0bidjqh3qf0hhpvjr8756ill@4ax.com...
>> class pet:
>>    def set_age(self,age):
>>        self.age=age
>>    def get_age(self):
>>        return self.age
>> pax=pet
>> pax.set_age(4)
>>
>> Traceback (most recent call last):
>>  File "C:\Functions\test.py", line 18, in <module>
>>    pax.set_age(4)
>> TypeError: set_age() missing 1 required positional argument: 'age'
>>
>> I am trying to pass 4 as the age.  Obviously I am doing it wrong.
>>
>
> Hi
>
> I am a beginner too, but I find it strange that your
> pet class has no __init__ method to construct
> instances

__init__ initialises instances, __new__ constructs them

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#80026

FromSeymore4Head <Seymore4Head@Hotmail.invalid>
Date2014-10-31 12:49 -0400
Message-ID<rbf75ah9l1jp9e72gqr0ncu7bau8cnt22o@4ax.com>
In reply to#80001
On Fri, 31 Oct 2014 10:05:03 +0100, "ast" <nomail@invalid.com> wrote:

>
>"Seymore4Head" <Seymore4Head@Hotmail.invalid> a écrit dans le message de 
>news:51755at03r0bidjqh3qf0hhpvjr8756ill@4ax.com...
>> class pet:
>>    def set_age(self,age):
>>        self.age=age
>>    def get_age(self):
>>        return self.age
>> pax=pet
>> pax.set_age(4)
>>
>> Traceback (most recent call last):
>>  File "C:\Functions\test.py", line 18, in <module>
>>    pax.set_age(4)
>> TypeError: set_age() missing 1 required positional argument: 'age'
>>
>> I am trying to pass 4 as the age.  Obviously I am doing it wrong.
>>
>
>Hi
>
>I am a beginner too, but I find it strange that your
>pet class has no __init__ method to construct
>instances 

What material have you used to take you up to classes?

[toc] | [prev] | [next] | [standalone]


#80050

From"ast" <nomail@invalid.com>
Date2014-10-31 19:31 +0100
Message-ID<5453d568$0$2316$426a74cc@news.free.fr>
In reply to#80026
"Seymore4Head" <Seymore4Head@Hotmail.invalid> a écrit dans le message de 
news:rbf75ah9l1jp9e72gqr0ncu7bau8cnt22o@4ax.com...

> What material have you used to take you up to classes?

It's a french classroom on the web
http://openclassrooms.com/courses/apprenez-a-programmer-en-python 

[toc] | [prev] | [next] | [standalone]


#80051

FromSeymore4Head <Seymore4Head@Hotmail.invalid>
Date2014-10-31 14:36 -0400
Message-ID<ril75adef2oicd7a75vj0ue6uh1g8sk919@4ax.com>
In reply to#80050
On Fri, 31 Oct 2014 19:31:01 +0100, "ast" <nomail@invalid.com> wrote:

>
>"Seymore4Head" <Seymore4Head@Hotmail.invalid> a écrit dans le message de 
>news:rbf75ah9l1jp9e72gqr0ncu7bau8cnt22o@4ax.com...
>
>> What material have you used to take you up to classes?
>
>It's a french classroom on the web
>http://openclassrooms.com/courses/apprenez-a-programmer-en-python 

I am going to try to learn Python before I learn French, so I won't be
going there.  :)

Thanks

[toc] | [prev] | [next] | [standalone]


#80052

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2014-10-31 14:41 -0400
Message-ID<mailman.15369.1414780877.18130.python-list@python.org>
In reply to#80050
On Fri, Oct 31, 2014 at 2:31 PM, ast <nomail@invalid.com> wrote:
>
> "Seymore4Head" <Seymore4Head@Hotmail.invalid> a écrit dans le message de
> news:rbf75ah9l1jp9e72gqr0ncu7bau8cnt22o@4ax.com...
>
>> What material have you used to take you up to classes?
>
>
> It's a french classroom on the web
> http://openclassrooms.com/courses/apprenez-a-programmer-en-python
> --
> https://mail.python.org/mailman/listinfo/python-list

My suggestion for a free tutorial is Learn Python the Hard Way.

You won't learn by cutting and pasting.  You have to type it in
yourself.  It will make you learn more because every typo you make
will lead you to a new discovery


-- 
Joel Goldstick
http://joelgoldstick.com

[toc] | [prev] | [next] | [standalone]


#80055

FromSeymore4Head <Seymore4Head@Hotmail.invalid>
Date2014-10-31 14:56 -0400
Message-ID<gnm75aloaa6i123pfid896hoas0fhlnfko@4ax.com>
In reply to#80052
On Fri, 31 Oct 2014 14:41:08 -0400, Joel Goldstick
<joel.goldstick@gmail.com> wrote:

>On Fri, Oct 31, 2014 at 2:31 PM, ast <nomail@invalid.com> wrote:
>>
>> "Seymore4Head" <Seymore4Head@Hotmail.invalid> a écrit dans le message de
>> news:rbf75ah9l1jp9e72gqr0ncu7bau8cnt22o@4ax.com...
>>
>>> What material have you used to take you up to classes?
>>
>>
>> It's a french classroom on the web
>> http://openclassrooms.com/courses/apprenez-a-programmer-en-python
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>
>My suggestion for a free tutorial is Learn Python the Hard Way.
>
>You won't learn by cutting and pasting.  You have to type it in
>yourself.  It will make you learn more because every typo you make
>will lead you to a new discovery

I have watched a few of those videos.  And I do have the PDF.  I will
give it a closer look.
Thanks

[toc] | [prev] | [standalone]


Page 4 of 4 — ← Prev page 1 2 3 [4]

Back to top | Article view | comp.lang.python


csiph-web