Re: an oop question

2022-11-05 Thread Julieta Shem
r...@zedat.fu-berlin.de (Stefan Ram) writes: > Julieta Shem writes: >>r...@zedat.fu-berlin.de (Stefan Ram) writes: >>>Later, I looked at a book in a bookstore; it was a book >>>about programming by Barbara Liskov that came out after the >>>LSP was already mentioned often, and as far as I could

Re: an oop question

2022-11-04 Thread Julieta Shem
Greg Ewing writes: > On 4/11/22 1:29 am, Julieta Shem wrote: >> Perhaps I can reduce the >> class Pair to just being a pair as we know it, made of two things, then >> we create a class called Sequence, which is really a composition of >> Pairs, comes with a length method and we derive Stack from

Re: an oop question

2022-11-04 Thread Greg Ewing
On 5/11/22 4:25 am, Chris Angelico wrote: Maybe it's one of those terms that is useless for actual coding (because practicality beats purity), but good for discussions? I'm not sure it's much good for discussions, either. I don't really care whether a language is "purely OO" or not, whatever

Re: an oop question

2022-11-04 Thread Chris Angelico
On Sat, 5 Nov 2022 at 02:18, Greg Ewing wrote: > > On 4/11/22 12:50 am, Chris Angelico wrote: > > In Python, everything is an object. Doesn't that equally mean that > > Python is purely OOP? > > Depends on what you mean by "purely oop". To me it suggests

Re: an oop question

2022-11-04 Thread Chris Angelico
On Sat, 5 Nov 2022 at 02:21, Greg Ewing wrote: > > > r...@zedat.fu-berlin.de (Stefan Ram) writes [that Barbara Liskov said]: > > > >> |If for each object o1 of type S there is an object o2 of > >> |type T such that for all programs P defined in terms of T, > >> |the behavior of P is unchanged

Re: an oop question

2022-11-04 Thread Greg Ewing
On 4/11/22 7:51 am, Julieta Shem wrote: (The empty documentation seems to satisfy the principle.) All the more reason to document your classes! More seriously, there's always at least a (possibly fuzzily) implied contract, because of the names you choose for things if nothing else. -- Greg

Re: an oop question

2022-11-04 Thread Greg Ewing
r...@zedat.fu-berlin.de (Stefan Ram) writes [that Barbara Liskov said]: |If for each object o1 of type S there is an object o2 of |type T such that for all programs P defined in terms of T, |the behavior of P is unchanged when o1 is substituted for o2 |then S is a subtype of T. That seems

Re: an oop question

2022-11-04 Thread Greg Ewing
On 4/11/22 12:50 am, Chris Angelico wrote: In Python, everything is an object. Doesn't that equally mean that Python is purely OOP? Depends on what you mean by "purely oop". To me it suggests a language in which dynamically-dispatched methods are the only form of code. Python

Re: an oop question

2022-11-04 Thread Greg Ewing
On 4/11/22 1:29 am, Julieta Shem wrote: Perhaps I can reduce the class Pair to just being a pair as we know it, made of two things, then we create a class called Sequence, which is really a composition of Pairs, comes with a length method and we derive Stack from it. That sounds better. But be

Re: an oop question

2022-11-03 Thread Weatherby,Gerard
https://www.oreilly.com/library/view/beginning-c-30/9780470261293/9780470261293_a_short_history_of_object-oriented_progr.html -- https://mail.python.org/mailman/listinfo/python-list

Re: an oop question

2022-11-03 Thread Alan Gauld
On 03/11/2022 18:29, Chris Angelico wrote: > On Fri, 4 Nov 2022 at 05:21, Julieta Shem wrote: >> >> Chris Angelico writes: >> >>> On Thu, 3 Nov 2022 at 21:44, Alan Gauld wrote: >>>> Also Python is not a purely OOP language, in that you can write >

Re: an oop question

2022-11-03 Thread Julieta Shem
r...@zedat.fu-berlin.de (Stefan Ram) writes: > Julieta Shem writes: >>I'll definitely look up the Liskov >>substitution principle and try to understand it. > > I found the LSP to be very confusing: > > First, it's was hard for me to actually get a clear

Re: an oop question

2022-11-03 Thread Julieta Shem
> So this clearly violates the Open-Closed-Principle! > > 3. Comments > > So, this would suggest to use procedural programming when > one foresees the need to add more object-specific procedures > later and object-oriented programming when one foresees the > ne

Re: an oop question

2022-11-03 Thread Chris Angelico
On Fri, 4 Nov 2022 at 05:21, Julieta Shem wrote: > > Chris Angelico writes: > > > On Thu, 3 Nov 2022 at 21:44, Alan Gauld wrote: > >> Also Python is not a purely OOP language, in that you can write > >> functional and procedural code in Python if you wish. I

Re: an oop question

2022-11-03 Thread Julieta Shem
Chris Angelico writes: > On Thu, 3 Nov 2022 at 21:44, Alan Gauld wrote: >> Also Python is not a purely OOP language, in that you can write >> functional and procedural code in Python if you wish. In >> Smalltalk thats notionally impossible because everything >> is an

Re: an oop question

2022-11-03 Thread Julieta Shem
Greg Ewing writes: > On 3/11/22 1:37 pm, Julieta Shem wrote: >> The code for computing the length of a Pair (which is really a linked >> list) happens to be the same for computing the length of a Stack. > > I would question whether that should be a method of Pair at all, > since it's not the

Re: an oop question

2022-11-03 Thread Julieta Shem
r...@zedat.fu-berlin.de (Stefan Ram) writes: > Julieta Shem writes: >>That's very interesting. Would you share the complete thread of e-mail? >>I would love to read it word for word. > > Yes, with pleasure! A quotation from my corresponding web page: > > (For technical reasons, the web page

Re: an oop question

2022-11-03 Thread Chris Angelico
On Thu, 3 Nov 2022 at 21:44, Alan Gauld wrote: > Also Python is not a purely OOP language, in that you can write > functional and procedural code in Python if you wish. In > Smalltalk thats notionally impossible because everything > is an object. And all programming statements

Re: an oop question

2022-11-03 Thread Weatherby,Gerard
From: Python-list on behalf of Alan Gauld Date: Thursday, November 3, 2022 at 6:45 AM To: Julieta Shem , python-list@python.org Subject: Re: an oop question *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** On 03/11/2022 00:25

Re: an oop question

2022-11-03 Thread Alan Gauld
On 03/11/2022 00:25, Julieta Shem wrote: >> |OOP to me means only messaging, local retention and protection and >> |hiding of state-process, and extreme late-binding of all things. > > I'm wondering how Python fails to satisfy his definition. Python doesn't do any form of data

Re: an oop question

2022-11-02 Thread Julieta Shem
r...@zedat.fu-berlin.de (Stefan Ram) writes: > Greg Ewing writes: >>I don't see any overlap between these at the conceptual level. > > It might come from early LISP dialects. In early LISPs, the > only basic means to combine data into a larger assembly of > data was the dotted pair and

Re: an oop question

2022-11-02 Thread Greg Ewing
On 3/11/22 1:37 pm, Julieta Shem wrote: The code for computing the length of a Pair (which is really a linked list) happens to be the same for computing the length of a Stack. I would question whether that should be a method of Pair at all, since it's not the length of the pair itself, but the

Re: an oop question

2022-11-02 Thread Julieta Shem
Alan Gauld writes: > On 01/11/2022 17:58, Julieta Shem wrote: [...] >>> IS-A relationship, so Stack inheriting Pair would mean that a Stack >>> was a Pair. That is not really true. >> >> That's another interesting observation. I do not have much >> understanding of how to really think of

Re: [correction]an oop question

2022-11-02 Thread Julieta Shem
Dennis Lee Bieber writes: > On 2 Nov 2022 09:56:28 GMT, r...@zedat.fu-berlin.de (Stefan Ram) declaimed > the following: > > >> Now, in the next program, I have removed the subclassings, >> there is no inheritance from the base class "Language" >> anymore. Yet the polymorphism in "f" still

Re: an oop question

2022-11-02 Thread Julieta Shem
r...@zedat.fu-berlin.de (Stefan Ram) writes: > Julieta Shem writes: >>Any book recomendations on getting this thing mathematics-clear? > > OOP cannot be mathematics-clear because it is an /attempt/ to > abstract from several different programming languages. > > When

Re: an oop question

2022-11-02 Thread Julieta Shem
Greg Ewing writes: > On 2/11/22 9:54 am, Julieta Shem wrote: >> But we've left behind a more basic requirement --- the Stack >> class wishes for all the methods already written in some class called >> Pair, > > Is that *really* what you want, though? > > To my way of thinking, a Stack and a Pair

Re: [correction]an oop question

2022-11-02 Thread Alan Gauld
On 02/11/2022 20:21, Dennis Lee Bieber wrote: >> shows that in Python we do *not* need subclassing/inheritance >> for polymorphism! >> > To me, that is not really an example of polymorphism, but more an > example of Python's "duck typing". But duck typing is a perfectly good

Re: an oop question

2022-11-02 Thread Alan Gauld
On 01/11/2022 17:58, Julieta Shem wrote: > nowhere in trying to detect in high-precision what is OOP and what is > not. Stefan has given a good answer but essentially OOP is a program that is structured around objects communicating by sending messages to one another. Objects are, i

Re: an oop question

2022-11-02 Thread Greg Ewing
On 2/11/22 9:54 am, Julieta Shem wrote: But we've left behind a more basic requirement --- the Stack class wishes for all the methods already written in some class called Pair, Is that *really* what you want, though? To my way of thinking, a Stack and a Pair are quite different data

Re: an oop question

2022-11-01 Thread Julieta Shem
r...@zedat.fu-berlin.de (Stefan Ram) writes: > r...@zedat.fu-berlin.de (Stefan Ram) writes: >>The crucial feature OOP adds to this is polymorphism ("late binding"). > > If polymorphism is so crucial, the idea of subclasses > has something to it! [...] I wonde

Re: an oop question

2022-11-01 Thread Julieta Shem
r...@zedat.fu-berlin.de (Stefan Ram) writes: > Julieta Shem writes: >>clarify. If I wish for an empty stack, I wish I could just say > Stack() >>Stack() >>and if I wish for a nonempty stack, I'd write > Stack(1, Stack(2, Stack(3, Stack( >>Stack(1, Stack(2, Stack(3, Stack( > >

Re: an oop question

2022-11-01 Thread Weatherby,Gerard
thon-list@python.org Subject: Re: an oop question *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Julieta Shem writes: >clarify. If I wish for an empty stack, I wish I could just say >>>> Stack() >Stack() >and

Re: an oop question

2022-11-01 Thread Julieta Shem
the user think he has something else simply because it has a different name. It is not the user's business to know what things are on the inside. >> So far so good, but when it comes to building a better user interface >> for it I have no idea how to do it. I think one of the purposes of OOP >> i

Re: an oop question

2022-11-01 Thread Julieta Shem
Chris Angelico writes: > On Mon, 31 Oct 2022 at 14:38, Julieta Shem wrote: >> >> Chris Angelico writes: >> >> > The most straight-forward way to represent this concept in an >> > object-oriented way is subclassing. >> > >> > class Stack: >> > ... # put whatever code is common here >> > >>

Re: an oop question

2022-10-31 Thread Alan Gauld
rt of). If you had a stack you could create a Pair from it certainly. > So far so good, but when it comes to building a better user interface > for it I have no idea how to do it. I think one of the purposes of OOP > is to organize code hierarchically so that we can reuse what we wrote. O

Re: an oop question

2022-10-30 Thread Chris Angelico
On Mon, 31 Oct 2022 at 14:38, Julieta Shem wrote: > > Chris Angelico writes: > > > The most straight-forward way to represent this concept in an > > object-oriented way is subclassing. > > > > class Stack: > > ... # put whatever code is common here > > > > class Empty(Stack): > > ... #

Re: an oop question

2022-10-30 Thread Julieta Shem
Chris Angelico writes: > On Mon, 31 Oct 2022 at 09:05, Julieta Shem wrote: >> >> Julieta Shem writes: >> >> [...] >> >> >> . If you should, however, be talking about the new "type hints": >> >> These are static and have "Union", for example, "Union[int, str]" >> >> or "int | str". >> >

Re: an oop question

2022-10-30 Thread dn
On 31/10/2022 09.22, Stefan Ram wrote: Giorgio Pastore writes: You may find useful to learn about the possibilities of using Python tools to implement a stack data structure and its manipulation methods. A good introduction is at https://realpython.com/how-to-implement-python-stack/ I

Re: an oop question

2022-10-30 Thread Weatherby,Gerard
the same interface create an abstract base class and derive both of them from it. https://docs.python.org/3/library/abc.html From: Python-list on behalf of Julieta Shem Date: Sunday, October 30, 2022 at 5:51 PM To: python-list@python.org Subject: an oop question *** Attention

Re: an oop question

2022-10-30 Thread Chris Angelico
On Mon, 31 Oct 2022 at 09:05, Julieta Shem wrote: > > Julieta Shem writes: > > [...] > > >> . If you should, however, be talking about the new "type hints": > >> These are static and have "Union", for example, "Union[int, str]" > >> or "int | str". > > > > I ended up locating such features

Re: an oop question

2022-10-30 Thread Giorgio Pastore
ot; Nice. This means that I can solve my stack-union problem by writing a procedure --- say stack(...) --- that sometimes gives me Empty() and sometimes gives me Stack(). I think that Stefan Ram's suggestion provides a solution to the problem of the stack, but not in a real OOP flavor. You may f

Re: an oop question

2022-10-30 Thread Julieta Shem
t;.format(self.first, str(self.rest)) def __repr__(self): return str(self) [...] >>> Stack() Stack() >>> Stack(1, Stack()) Stack(1, Stack()) That's it. That's what I was looking for. However, I don't really like the OOP approach here because of what's going to happe

Re: an oop question

2022-10-30 Thread Julieta Shem
r...@zedat.fu-berlin.de (Stefan Ram) writes: > Julieta Shem writes: >>My desire seems to imply that I need a union-like data structure. > > You only need to worry about such things in languages with > static typing. For example, to have a function that can > sometimes return an int value

an oop question

2022-10-30 Thread Julieta Shem
I have a question about a particular case I'm working on. I'm studying OOP. To ask the question, I'm going to have to introduce you my context here, so you'll need to bear with me. If you'd like to see the question right away, go to the section ``My difficulty in encapsulating a union

Re: on implementing a toy oop-system

2022-09-29 Thread Meredith Montgomery
r...@zedat.fu-berlin.de (Stefan Ram) writes: [...] >>>However, to evaluate a method call such as "o.m( a, a1, ... )", >>>currying does not necessarily have to be used. One can as well >>>determine the function to be used for "m" from the type of "o" >>>and then call that function with

Re: on implementing a toy oop-system

2022-09-29 Thread Meredith Montgomery
r...@zedat.fu-berlin.de (Stefan Ram) writes: > Meredith Montgomery writes: >>The code below works, but you can see it's kinda ugly. I wish I could >>uncurry a procedure, but I don't think this is possible. (Is it?) > > from functools import partial > from operator import add > add5 = partial(

Re: on implementing a toy oop-system

2022-09-28 Thread Meredith Montgomery
Meredith Montgomery writes: > r...@zedat.fu-berlin.de (Stefan Ram) writes: > >> Meredith Montgomery writes: >>>Is that at all possible somehow? Alternatively, how would you do your >>>toy oop-system? >> >> Maybe something along those lines: >

Re: on implementing a toy oop-system

2022-09-23 Thread Meredith Montgomery
Chris Angelico writes: > On Sat, 24 Sept 2022 at 07:52, Meredith Montgomery > wrote: >> >> def Counter(name = None): >> o = {"name": name if name else "untitled", "n": 0} >> def inc(o): >> o["n"] += 1 >> return o >> o["inc"] = inc >> def get(o): >> return o["n"] >>

Re: on implementing a toy oop-system

2022-09-23 Thread Chris Angelico
On Sat, 24 Sept 2022 at 07:52, Meredith Montgomery wrote: > > def Counter(name = None): > o = {"name": name if name else "untitled", "n": 0} > def inc(o): > o["n"] += 1 > return o > o["inc"] = inc > def get(o): > return o["n"] > o["get"] = get > return o > Want a neat

Re: on implementing a toy oop-system

2022-09-23 Thread Meredith Montgomery
r...@zedat.fu-berlin.de (Stefan Ram) writes: > Meredith Montgomery writes: >>Is that at all possible somehow? Alternatively, how would you do your >>toy oop-system? > > Maybe something along those lines: > > from functools import partial > > def counter_c

Re: on implementing a toy oop-system

2022-09-06 Thread Meredith Montgomery
r...@zedat.fu-berlin.de (Stefan Ram) writes: > Meredith Montgomery writes: >>Is that at all possible somehow? Alternatively, how would you do your >>toy oop-system? > > Maybe something along those lines: > > from functools import partial > > def counter_c

on implementing a toy oop-system

2022-09-06 Thread Meredith Montgomery
procedure of the Counter closure, so it's that dictionary that's being mutated. My /inherit/ procedure is not able to bring that procedure into the Car dictionary. Is that at all possible somehow? Alternatively, how would you do your toy oop-system? (*) Full code below from random import ran

Re: oop issue

2022-05-23 Thread Avi Gross via Python-list
ten find out someone is given a homework assignment ... -Original Message- From: Tola Oj To: python-list@python.org Sent: Mon, May 23, 2022 4:54 pm Subject: oop issue i just finished learning oop as a beginner and trying to practice with it but i ran into this typeerror issue, help p

Re: oop issue

2022-05-23 Thread Peter Otten
On 23/05/2022 22:54, Tola Oj wrote: i just finished learning oop as a beginner and trying to practice with it but i ran into this typeerror issue, help please. Traceback (most recent call last): File "c:\Users\ojomo\OneDrive\Desktop\myexcel\oop_learn.py\myExperiment.py\mainMain.py"

oop issue

2022-05-23 Thread Tola Oj
i just finished learning oop as a beginner and trying to practice with it but i ran into this typeerror issue, help please. Traceback (most recent call last): File "c:\Users\ojomo\OneDrive\Desktop\myexcel\oop_learn.py\myExperiment.py\mainMain.py", line 36, in

Re: oop issue

2022-05-23 Thread MRAB
On 2022-05-23 20:36, Tola Oj wrote: i am trying to print this code but it keeps giving me this typeerror, please help. the csv file format i am trying to change into a list is in a different module. class invest_crypto: crypto_current_rate = 0.05 client_list = [] def

oop issue

2022-05-23 Thread Tola Oj
i am trying to print this code but it keeps giving me this typeerror, please help. the csv file format i am trying to change into a list is in a different module. class invest_crypto: crypto_current_rate = 0.05 client_list = [] def __init__(self, name, surname, amount_Deposited,

[issue400841] Add 'parallel for-oop': for x in a; y in b; z in c: <...>

2022-04-10 Thread admin
Change by admin : ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue400841] Add 'parallel for-oop': for x in a; y in b; z in c: <...>

2022-04-10 Thread admin
Change by admin : -- github: None -> 32598 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

python oop learning communication between function inside a class

2020-09-17 Thread pascal z via Python-list
Hello, I would like to know how possible it is to call a member function from a class and pass it a variable Example: class Application(tk.Frame): """docstring for .""" def __init__(self, parent): super(Application, self).__init__(parent) self.parent = parent

Re: Help with oop

2020-02-23 Thread DL Neil via Python-list
def add_item(self, item_object):  if len(self.inventory) <= self.capacity:  self.inventory.append(item_object)  return True  else:  print("Reached max capacity")  return False on behalf of DL Neil via Python-list *Sent:* Sunday, February 23, 2020 4:41:54 PM *To:* python-li

Re: Help with oop

2020-02-23 Thread DL Neil via Python-list
On 22/02/20 10:45 PM, S Y wrote: How can I use remove,add and verify methods in class oop. Which has tuple with allowed values inside class. Like two classes cart and inventory Please show the code you have so-far. What are you removing, adding, and verifying? Are you aware of the Python

Help with oop

2020-02-22 Thread S Y
How can I use remove,add and verify methods in class oop. Which has tuple with allowed values inside class. Like two classes cart and inventory Get Outlook for iOS<https://aka.ms/o0ukef> -- https://mail.python.org/mailman/listinfo/python-list

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-07 Thread Gregory Ewing
Oscar Benjamin wrote: In Python the original exception message plus traceback is often very informative (to a programmer!) about the problem. That's okay, exception chaining preserves the whole traceback if you want to dig down that far. Catching and reraising can mean that you end up

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-06 Thread Oscar Benjamin
On Tue, 5 Nov 2019 at 21:52, Gregory Ewing wrote: > > Peter J. Holzer wrote: > > On 2019-11-04 18:18:39 -0300, Luciano Ramalho wrote: > > > > Or maybe don't catch it here at all but just let it bubble up until it > > hits a level where dealing with it makes sense from the user's point of > > view

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-05 Thread Gregory Ewing
Peter J. Holzer wrote: On 2019-11-04 18:18:39 -0300, Luciano Ramalho wrote: In addition, as Rob said, it is usually a bad idea to wrap several lines of code in a single try/except block I disagree with this. While it is sometimes useful to wrap a single line, in my experience it rarely is.

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-05 Thread Rob Gaddi
On 11/5/19 11:52 AM, Peter J. Holzer wrote: On 2019-11-04 18:18:39 -0300, Luciano Ramalho wrote: In addition, as Rob said, it is usually a bad idea to wrap several lines of code in a single try/except block I disagree with this. While it is sometimes useful to wrap a single line, in my

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-05 Thread Peter J. Holzer
On 2019-11-04 18:18:39 -0300, Luciano Ramalho wrote: > In addition, as Rob said, it is usually a bad idea to wrap several > lines of code in a single try/except block I disagree with this. While it is sometimes useful to wrap a single line, in my experience it rarely is. The scope of the try ...

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-05 Thread Chris Angelico
On Tue, Nov 5, 2019 at 8:46 PM R.Wieser wrote: > > Chris, > > > "Control flow" is anything that changes the order that your code runs. > > My apologies, I should have said "a control flow mechanism" /in this > context/ (though I assumed that as implicite, as I quoted the text from the > OP). > >

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-05 Thread R.Wieser
Chris, > "Control flow" is anything that changes the order that your code runs. My apologies, I should have said "a control flow mechanism" /in this context/ (though I assumed that as implicite, as I quoted the text from the OP). Case in point, the __init__ code (of a class object) can result

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-04 Thread Chris Angelico
On Tue, Nov 5, 2019 at 6:26 PM R.Wieser wrote: > > It is considered totally OK to use exception handling as a control > > flow mechanism in Python. > > I'm not sure what exactly you mean with "a control flow mechanism", but as > several methods throw exceptions themselves I will have no choice in

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-04 Thread R.Wieser
Luciano, > In this context, what I mean by that quote is to say that Python > never forces you to wrap anything in try/except blocks. True. But /not/ doing it means that the casted exeption in the __init__ block will just abort the whole program - in a user unfriendly way. And thats normally

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-04 Thread Luciano Ramalho
On Mon, Nov 4, 2019 at 5:52 PM R.Wieser wrote: > I was thinking of (the needed) wrapping of the "newObject = classObject()" > line in such a try..except block (to capture the re-casted exception). I > take it that that that means that the full contents of the __init__ block > are wrapped too.

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-04 Thread R.Wieser
Rob, > That's why if you for instance, open a serial port in an __init__ routine, > and something fails, you want to catch the exception there in __init__, > explicitly close that serial port, and reraise the exception. Otherwise > that port still has an object open against it until Python

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-04 Thread Rob Gaddi
On 11/4/19 10:59 AM, R.Wieser wrote: Rob, Returning None will specifically NOT accomplish the thing you want; nothing ever checks the return value of __init__. I thought to have read that when you return a none from it the object itself would return a placeholder singleton. Raise an

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-04 Thread R.Wieser
Luciano, > """A failed __init__ should raise an appropriate exception. A bare > return or returning None is what any __init__ is expected to do in the > normal case, so it signals success.""" Ah, that settles it than. Somehow I thought that a return (of "none") there indicated an error result,

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-04 Thread R.Wieser
Rob, > Returning None will specifically NOT accomplish the thing you want; > nothing ever checks the return value of __init__. I thought to have read that when you return a none from it the object itself would return a placeholder singleton. > Raise an exception. Yeah, that was what I was

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-04 Thread Rob Gaddi
On 11/4/19 10:36 AM, Luciano Ramalho wrote: Sorry, I responded only to the OP. My response: """A failed __init__ should raise an appropriate exception. A bare return or returning None is what any __init__ is expected to do in the normal case, so it signals success.""" Actually, the Python

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-04 Thread Luciano Ramalho
Sorry, I responded only to the OP. My response: """A failed __init__ should raise an appropriate exception. A bare return or returning None is what any __init__ is expected to do in the normal case, so it signals success.""" Actually, the Python interpreter *does* check the return of __init__.

Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-04 Thread Rob Gaddi
On 11/4/19 7:32 AM, R.Wieser wrote: Hello all, The whole question: How should I handle failed initialisation code inside the __init__ of an object ? I've seen an example doing a plain "return" (of the value "none""), but have no idea if that is all it takes. Also, I wonder what happens to the

OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-04 Thread R.Wieser
Hello all, The whole question: How should I handle failed initialisation code inside the __init__ of an object ? I've seen an example doing a plain "return" (of the value "none""), but have no idea if that is all it takes. Also, I wonder what happens to the object itself. Does it still

Re: OOP - iterable class: how to delete one of its objects ?

2019-11-04 Thread R.Wieser
Rhodri, > Yes, it can. That's why you want to create a finalizer to tidy up. AFAIKS in my case there is nothing to cleanup. As far as I understood the WeakSet will automagically purge the reference whe the object it references is destroyed. I could also try to do it in in the __del__ method

Re: OOP - iterable class: how to delete one of its objects ?

2019-11-04 Thread Rhodri James
On 02/11/2019 06:30, R.Wieser wrote: Rhodri, Use weak references. A WeakSet (https://docs.python.org/3/library/weakref.html#weakref.WeakSet) is probably what you want. Most likely!As a fresh freshling in regard to python I was not even aware that a "copy object, but do not increment the

Re: OOP - iterable class: how to delete one of its objects ?

2019-11-02 Thread R.Wieser
Rhodri, > Use weak references. A WeakSet > (https://docs.python.org/3/library/weakref.html#weakref.WeakSet) is > probably what you want. Most likely!As a fresh freshling in regard to python I was not even aware that a "copy object, but do not increment the reference count" existed.

Re: OOP - iterable class: how to delete one of its objects ?

2019-11-02 Thread R.Wieser
Dennis, > In __init__() you are adding "self" to a classwide list. So in > your __del__() you need to remove the instance from the > same list. Something :-) Thats the problem: __del__ only gets called when the object is destroyed - which will never happen when the "instances" list still

Re: OOP - iterable class: how to delete one of its objects ?

2019-11-02 Thread R.Wieser
Chris, > Have a method to explicitly purge the instance. I was thinking of that too but decided against it, as it would mean that my objects would need to be handled specially - which is not quite what I'm looking for. To be honest, I was thinking of/hoping that there would be a method which

Re: OOP - iterable class: how to delete one of its objects ?

2019-11-01 Thread Chris Angelico
On Sat, Nov 2, 2019 at 6:21 AM R.Wieser wrote: > > Hello all, > > I've created a class from which I can iterate all its instanciated objects > (using an "instances" list).The problem is that I now cannot seem to > delete an object anymore, AFAIK as a copy of its "self" is still inside the >

Re: OOP - iterable class: how to delete one of its objects ?

2019-11-01 Thread Rhodri James
On 01/11/2019 19:15, R.Wieser wrote: Hello all, I've created a class from which I can iterate all its instanciated objects (using an "instances" list).The problem is that I now cannot seem to delete an object anymore, AFAIK as a copy of its "self" is still inside the "instances" list.

OOP - iterable class: how to delete one of its objects ?

2019-11-01 Thread R.Wieser
Hello all, I've created a class from which I can iterate all its instanciated objects (using an "instances" list).The problem is that I now cannot seem to delete an object anymore, AFAIK as a copy of its "self" is still inside the "instances" list. Object in question: - - - - - - - - - -

Re: How can I make a sentinel value NOT be initialized in a class/method - OOP?

2017-01-14 Thread Erik
[Replying to direct email. David - please respond to the list so that you can receive other people's suggestions also] Hi David, On 14/01/17 15:30, David D wrote: > 1) No this is not homework, I am doing this all on my own. In that case I apologise - I gave you the benefit of the doubt

Re: How can I make a sentinel value NOT be initialized in a class/method - OOP?

2017-01-13 Thread sohcahtoa82
On Friday, January 13, 2017 at 2:27:04 PM UTC-8, David D wrote: > I am testing out some basic Object Oriented Programming in Python. The > basics: > > -User enters a name > -While loop with a sentinel value of "quit" will continue entering names > until the sentinel value is reached > -The

Re: How can I make a sentinel value NOT be initialized in a class/method - OOP?

2017-01-13 Thread Ian Kelly
On Jan 13, 2017 3:33 PM, wrote: The issue I am having is that when i enter the sentinel value of QUIT, it gets initialized as the name and printed out. How can I get around this? I hope this makes sense. Hard to say for certain without seeing your code, but the most

Re: How can I make a sentinel value NOT be initialized in a class/method - OOP?

2017-01-13 Thread Erik
Hi, On 13/01/17 22:26, daviddsch...@gmail.com wrote: The issue I am having is that when i enter the sentinel value of QUIT, it gets initialized as the name and printed out. How can I get around this? If I understand the question correctly (which looks like it's just a re-worded homework

How can I make a sentinel value NOT be initialized in a class/method - OOP?

2017-01-13 Thread daviddschool
I am testing out some basic Object Oriented Programming in Python. The basics: -User enters a name -While loop with a sentinel value of "quit" will continue entering names until the sentinel value is reached -The object is created with the inputted value (NAME and until a sentinel value is

[issue27290] Turn heaps library into a more OOP data structure?

2016-06-10 Thread James Lu
James Lu added the comment: Even a wrapper class would be helpful, it's simply more pythonic. On Fri, Jun 10, 2016 at 6:02 PM, Raymond Hettinger wrote: > > Raymond Hettinger added the comment: > > The main reason is that there would be very little benefit. Lists are a

[issue27290] Turn heaps library into a more OOP data structure?

2016-06-10 Thread Raymond Hettinger
Raymond Hettinger added the comment: The main reason is that there would be very little benefit. Lists are a very efficient data structure and the heap manipulations are also very cheap. -- assignee: -> rhettinger nosy: +rhettinger resolution: -> rejected status: open -> closed

[issue27290] Turn heaps library into a more OOP data structure?

2016-06-10 Thread James Lu
New submission from James Lu: The heapq library uses a list or other mutable sequence time to represent a heap. Since Python is a highly OOP language, why not make heaps their own data type? -- components: Library (Lib) messages: 268159 nosy: James.Lu priority: normal severity: normal

Re: Classic OOP in Python

2015-11-12 Thread jongiddy
On Thursday, 18 June 2015 12:21:29 UTC+1, Jason P. wrote: > > I'm aware of duck typing. The point in using interfaces is to be explicit > about the boundaries of a system. > > Quite a red "Growing Object-Oriented Software, Guided by Tests", by the way. > In fact interfaces are key components

Re: Classic OOP in Python

2015-06-21 Thread Laura Creighton
Ah, turns out there was an entry. I updated it. Laura -- https://mail.python.org/mailman/listinfo/python-list

Re: Classic OOP in Python

2015-06-20 Thread Mark Lawrence
On 19/06/2015 00:01, Laura Creighton wrote: In a message of Thu, 18 Jun 2015 11:50:28 +0100, Mark Lawrence writes: Throw in http://clonedigger.sourceforge.net/ as well and you've a really awesome combination. Mark Lawrence I didn't know about that one. Hey thank you, Mark. Looks great. It

  1   2   3   4   5   6   7   8   >