Re: [Tutor] Subclassing logging.Handler?

2016-07-06 Thread Alex Hall
On Wed, Jul 6, 2016 at 1:01 PM, Alex Hall wrote: > Regarding this project: I've gone ahead and tried a variant of it. I > wanted to log to an HTML file, since those are much easier to look at with > a screen reader and so I could get used to the concepts involved. Here's > what I've come up with

Re: [Tutor] Subclassing logging.Handler?

2016-07-06 Thread Alex Hall
Regarding this project: I've gone ahead and tried a variant of it. I wanted to log to an HTML file, since those are much easier to look at with a screen reader and so I could get used to the concepts involved. Here's what I've come up with so far. I'll ask the question, then paste the code. I'm get

[Tutor] Subclassing logging.Handler?

2016-07-06 Thread Alex Hall
Hey list, Another day, another Python experiment. I'm wondering what methods I'd have to implement in a custom subclass of logger.Handler. Currently, the recurring jobs I have written log their events to a file each time they run. That's fine, but it doesn't let me keep easily-sorted/searched reco

Re: [Tutor] Subclassing Exceptions

2012-01-09 Thread Chris Fuller
On Friday 06 January 2012, Steven D'Aprano wrote: > Chris Fuller wrote: > class Foo(SyntaxError): > > ... def __init__(self, a,b,c): > > ... self.args = (a,b,c) > > ... > > > raise Foo(1,2,3) > > > > Traceback (most recent call last): > > File "", line 1, in > > > > __main__.Foo:

Re: [Tutor] Subclassing Exceptions

2012-01-07 Thread Lie Ryan
On 01/07/2012 03:56 PM, Steven D'Aprano wrote: Chris Fuller wrote: You probably shouldn't inherit from SyntaxError, since it represents syntax errors in the Python code being interpreted or compiled. Any syntax error in your own data structures should be independent of SyntaxError. I'd say a s

Re: [Tutor] Subclassing Exceptions

2012-01-06 Thread Steven D'Aprano
Devin Jeanpierre wrote: Inheriting from SyntaxError doesn't work! When I create a new exception, I generally subclass from the built-in exception it most resembles, in case there was some reason to also catch it via an ancestor. But I'm not sure if that is really all that useful an idea in prac

Re: [Tutor] Subclassing Exceptions

2012-01-06 Thread Steven D'Aprano
Chris Fuller wrote: class Foo(SyntaxError): ... def __init__(self, a,b,c): ... self.args = (a,b,c) ... raise Foo(1,2,3) Traceback (most recent call last): File "", line 1, in __main__.Foo: None Inheriting from SyntaxError doesn't work! When I create a new exception, I generally sub

Re: [Tutor] Subclassing Exceptions

2012-01-06 Thread Devin Jeanpierre
> Inheriting from SyntaxError doesn't work! When I create a new exception, I > generally subclass from the built-in exception it most resembles, in case > there was some reason to also catch it via an ancestor. But I'm not sure if > that is really all that useful an idea in practice. How do you

[Tutor] Subclassing Exceptions

2012-01-06 Thread Chris Fuller
I had an interesting experience today. Python 2.7.1 (r271:86832, Nov 28 2010, 19:31:37) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class Foo(Exception): ... def __init__(self, a,b,c): ... self.args = (a,b,c) ... >>> raise Foo(1,2,3) Traceb

Re: [Tutor] Subclassing object

2010-01-17 Thread Alan Gauld
"Robert" wrote I have been wondering about this "New-style Class" subject along this line: so, *theoretically speaking*, in EXISTING, pre-P3K code, if one changes everywhere where it's coded "class someClass()" to "class someClass(object)", it should not break the programs, right ? More co

Re: [Tutor] Subclassing object

2010-01-17 Thread Robert
On Sun, Jan 17, 2010 at 12:47 PM, Robert wrote: > On Sun, Jan 17, 2010 at 11:25 AM, Alan Gauld > wrote: >> In older versions of Python it made a difference whether you used object >> or not. Using object gave you a "new style" class which has several extra >> features, without you got an "old st

Re: [Tutor] Subclassing object

2010-01-17 Thread Alan Gauld
"Timo Vanwynsberghe" wrote I read that it is advised to subclass object. Is it really necessary? I mean, everything works, why should I add it to my code? In older versions of Python it made a difference whether you used object or not. Using object gave you a "new style" class which has s

[Tutor] Subclassing object

2010-01-17 Thread Timo Vanwynsberghe
I read that it is advised to subclass object. Is it really necessary? I mean, everything works, why should I add it to my code? Cheers, Timo ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/ma

Re: [Tutor] Subclassing list

2009-06-18 Thread Kent Johnson
On Thu, Jun 18, 2009 at 9:48 PM, Luis N wrote: >>> I get an error "TypeError: 'rounding' is an invalid keyword argument >>> for this function" on my list subclass. >>> >>> How might I subclass list without this error? >>> >>> This is the code: >>> >>> class SeriesList(list): >>>    def __new__(cls

Re: [Tutor] Subclassing list

2009-06-18 Thread Luis N
On Fri, Jun 19, 2009 at 12:56 AM, bob gailer wrote: > > Luis N wrote: >> >> I get an error "TypeError: 'rounding' is an invalid keyword argument >> for this function" on my list subclass. >> >> How might I subclass list without this error? >> >> This is the code: >> >> class SeriesList(list): >>  

Re: [Tutor] Subclassing list

2009-06-18 Thread bob gailer
Luis N wrote: I get an error "TypeError: 'rounding' is an invalid keyword argument for this function" on my list subclass. How might I subclass list without this error? This is the code: class SeriesList(list): def __new__(cls, *args, **kwargs): series_list = list.__new__(cls, *arg

[Tutor] Subclassing list

2009-06-18 Thread Luis N
I get an error "TypeError: 'rounding' is an invalid keyword argument for this function" on my list subclass. How might I subclass list without this error? This is the code: class SeriesList(list): def __new__(cls, *args, **kwargs): series_list = list.__new__(cls, *args) serie

Re: [Tutor] subclassing strings

2008-01-08 Thread Eric Abrahamsen
Thanks both of you, that cleared a lot of things up. On Jan 9, 2008, at 11:49 AM, Kent Johnson wrote: > > No, you can't access the actual byte array from Python and you can't > damage it. I don't know a lick of C and probably never will, but I do like to know what it is, exactly, that I don't

Re: [Tutor] subclassing strings

2008-01-08 Thread Kent Johnson
Tiger12506 wrote: > PS. Anyone who's interested. A significant study of C has brought me to > these conclusions. > immutable -> implemented with static buffer > mutable -> implemented with linked list > Anyone know a little more detail? Certainly not true of Python. I don't know of any standard Py

Re: [Tutor] subclassing strings

2008-01-08 Thread Kent Johnson
Eric Abrahamsen wrote: > When I create a string like so: > > x = 'myvalue' > > my understanding is that this is equivalent to: > > x = str('myvalue') > > and that this second form is more fundamental: the first is a > shorthand for the second. The second does nothing that the first doesn't

Re: [Tutor] subclassing strings

2008-01-08 Thread Tiger12506
Ahh. Excellent questions. > I'm playing around with subclassing the built-in string type, and > realizing there's quite a bit I don't know about what's going on with > the built-in types. When I create a string like so: > > x = 'myvalue' > > my understanding is that this is equivalent to: > > x =

[Tutor] subclassing strings

2008-01-08 Thread Eric Abrahamsen
I'm playing around with subclassing the built-in string type, and realizing there's quite a bit I don't know about what's going on with the built-in types. When I create a string like so: x = 'myvalue' my understanding is that this is equivalent to: x = str('myvalue') and that this second f

Re: [Tutor] Subclassing vs. stand alone functions

2007-06-16 Thread chrispython
Thanks again, this is exactly the kind of info I need to make the jump from procedural to OO design. I bookmarked your site for reference. On Saturday, June 16, 2007, at 09:30AM, "Kent Johnson" <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] wrote: >> Hi there, >> >> I am new to Python and tryin

Re: [Tutor] Subclassing vs. stand alone functions

2007-06-16 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > Hi there, > > I am new to Python and trying to get my head around the OO stuff. I > guess my question is - when do you go with subclassing vs. making a > standalone function? > Let's say you want to load a dictionary. Do I create a function that > accepts some argument

Re: [Tutor] Subclassing vs. stand alone functions

2007-06-16 Thread Alan Gauld
<[EMAIL PROTECTED]> wrote >>Just so you know, my day gig is maintaining a 30 year old COBOL app >>and >>writing custom RPGLE - http://en.wikipedia.org/wiki/RPGLE - on an >>IBM i5. >>So that's where I am coming from. Thats probably one of the hardest places to learn OOP from. COBOL, more than an

Re: [Tutor] Subclassing vs. stand alone functions

2007-06-15 Thread chrispython
I am new to Python and trying to get my head around the OO stuff. I guess my question is - when do you go with subclassing vs. making a standalone function? OK, I'll take a slightly different approach than the other answers so far. First: procedural and OO styles of programming are diffrent

Re: [Tutor] Subclassing vs. stand alone functions

2007-06-15 Thread Alan Gauld
<[EMAIL PROTECTED]> wrote > I am new to Python and trying to get my head around > the OO stuff. I guess my question is - when do you go > with subclassing vs. making a standalone function? OK, I'll take a slightly different approach than the other answers so far. First: procedural and OO st

Re: [Tutor] Subclassing vs. stand alone functions

2007-06-15 Thread Senthil_OR
[EMAIL PROTECTED] wrote: > > Let's say you want to load a dictionary. Do I create a function that > accepts some argument (say a file name) and returns a dictionary, or > do I subclass dict and override the __init__ and __setitem__ > functions to make 'self-loading' dictionary? It seems the end r

Re: [Tutor] Subclassing vs. stand alone functions

2007-06-15 Thread Jorgen Bodde
Hi, Basically you write a (sub)class when you want to preserve state information of your instance. If the functionality in question lives longer then the scope of the function, and will be called from different methods to obtain the same information and state of the functionality at that time, it

[Tutor] Subclassing vs. stand alone functions

2007-06-15 Thread chrispython
Hi there, I am new to Python and trying to get my head around the OO stuff. I guess my question is - when do you go with subclassing vs. making a standalone function? Let's say you want to load a dictionary. Do I create a function that accepts some argument (say a file name) and returns a dict

Re: [Tutor] Subclassing data attributes

2005-11-04 Thread Jan Eden
Hi Kent, Kent Johnson wrote on 04.11.2005: > >OK I'll try again. I still don't understand why you don't like using >straight class attributes - is it to keep the size of the class >namespace smaller? > Yes, and to distinguish between different kinds of attributes in the main script. In the end, i

Re: [Tutor] Subclassing data attributes

2005-11-04 Thread Kent Johnson
Jan Eden wrote: > Not exactly. My current setup bundles all data attributes in a single > module Data containing a single class for each object. So in my main > module (Show), I define:> > class Page(Data.Page): > ... > > and Data contains: > > class Base: > children = 'xyz' > childr

Re: [Tutor] Subclassing data attributes

2005-11-03 Thread Kent Johnson
Jan Eden wrote: > Hi, > > the module Data.py stores a number of data attributes. I'd like to structure > the storage of these attributes, either in subclasses or in dictionaries. > > My first attempt was this: > > class A: > templates['attr1'] = 'string' > queries['children'] = ... >

[Tutor] Subclassing data attributes

2005-11-03 Thread Jan Eden
Hi, the module Data.py stores a number of data attributes. I'd like to structure the storage of these attributes, either in subclasses or in dictionaries. My first attempt was this: class A: templates['attr1'] = 'string' queries['children'] = ... class B(A): templates['attr2']

Re: [Tutor] subclassing across multiple modules

2005-03-18 Thread Brian van den Broek
Kent Johnson said unto the world upon 2005-03-18 07:35: Brian van den Broek wrote: Kent Johnson said unto the world upon 2005-03-17 20:44: The multiple inheritance from MyNode and Toolkit.NodeX is a smell. I guess you do this because you want to override methods of Toolkit.Node as well as Toolki

Re: [Tutor] subclassing across multiple modules

2005-03-18 Thread Kent Johnson
Brian van den Broek wrote: Kent Johnson said unto the world upon 2005-03-17 20:44: The multiple inheritance from MyNode and Toolkit.NodeX is a smell. I guess you do this because you want to override methods of Toolkit.Node as well as Toolkit.NodeX, or add methods to both MyNode1 and MyNode2? I

Re: [Tutor] subclassing across multiple modules

2005-03-17 Thread Brian van den Broek
Kent Johnson said unto the world upon 2005-03-17 20:44: Brian van den Broek wrote: A schematic of what I have (with fake names for ease of example) is a base module Toolkit.py and I want to write a module Application.py which specializes the behaviour of the Toolkit.py classes. (I'm using old-st

Re: [Tutor] subclassing across multiple modules

2005-03-17 Thread Kent Johnson
Brian van den Broek wrote: A schematic of what I have (with fake names for ease of example) is a base module Toolkit.py and I want to write a module Application.py which specializes the behaviour of the Toolkit.py classes. (I'm using old-style classes, but don't feel committed to that choice.)

[Tutor] subclassing across multiple modules

2005-03-17 Thread Lloyd Kvam
You want a method in a base class to parse input and create instances of certain derived classes. Your sample code looks like: if some_condition_on_chunk_contents: node = Node1(chunk_contents) else: node = Node2(chunk_contents) I'd suggest changing the method to use a variable to determ

[Tutor] subclassing across multiple modules

2005-03-17 Thread Brian van den Broek
Hi all, I'm uncertain of how to make use of OOP design across multiple modules. (Actually, on reflection, I'm not certain the multiple modules aspect is central.) I'm also uncertain of how to frame the question well, so please bear with me :-) A schematic of what I have (with fake names for eas

Re: [Tutor] SubClassing

2005-02-27 Thread Jeff Shannon
On Fri, 25 Feb 2005 05:54:39 -0200, Ismael Garrido <[EMAIL PROTECTED]> wrote: > def __init__(self, this, that, new): > Parent.__init__(self, this, that) #note self > self.new = new If the paren's init t has a lot of possible arguments, it may be easier to do things this way: class Child(

Re: [Tutor] SubClassing

2005-02-25 Thread Sean Perry
Ismael Garrido wrote: Sean Perry wrote: yep. call 'Parent.__init__(this, that)' then do 'self.new = new' def __init__(self, this, that, new): Parent.__init__(this, that) self.new = new Thanks. Though it should be: def __init__(self, this, that, new): Parent.__init__(self, this, that) #

Re: [Tutor] SubClassing

2005-02-24 Thread Ismael Garrido
Sean Perry wrote: yep. call 'Parent.__init__(this, that)' then do 'self.new = new' def __init__(self, this, that, new): Parent.__init__(this, that) self.new = new Thanks. Though it should be: def __init__(self, this, that, new): Parent.__init__(self, this, that) #note self self.new =

Re: [Tutor] SubClassing

2005-02-24 Thread Sean Perry
Ismael Garrido wrote: Hello My code is like this: class Parent: def __init__(self, bunch, of, variables): self.bunch, self.of, self.variables = bunch, of, variables class Son(Parent): def __init__(self, bunch, of, variables, new): self.bunch, self.of, self.variables, self.new = bu

[Tutor] SubClassing

2005-02-24 Thread Ismael Garrido
Hello My code is like this: class Parent: def __init__(self, bunch, of, variables): self.bunch, self.of, self.variables = bunch, of, variables class Son(Parent): def __init__(self, bunch, of, variables, new): self.bunch, self.of, self.variables, self.new = bunch, of, variables, n

Re: [Tutor] subclassing list -- slicing doesn't preserve type

2005-02-22 Thread Danny Yoo
> > > I'm trying to figure out how to subclass the list built-in. > > > You could do it e.g. like that: > > > > class Mylist (list): > > def __init__(self, seq=None): > > super(self.__class__, self).__init__(seq) > > def __getslice__(self, start, stop): > > return self.__cl

[Tutor] subclassing list -- slicing doesn't preserve type

2005-02-22 Thread Lloyd Kvam
> Message: 2 > Date: Tue, 22 Feb 2005 13:53:44 +0100 > From: [EMAIL PROTECTED] (Karl Pfl?sterer ) > Subject: Re: [Tutor] subclassing list -- slicing doesn't preserve type > To: tutor@python.org > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; char

Re: [Tutor] subclassing list -- slicing doesn't preserve type

2005-02-22 Thread Brian van den Broek
Karl Pflästerer said unto the world upon 2005-02-22 07:53: On 22 Feb 2005, [EMAIL PROTECTED] wrote: I'm trying to figure out how to subclass the list built-in. .>>> class my_list(list): def __init__(self, sequence=None): list.__init__(self, sequence) self.spam = 1

Re: [Tutor] subclassing list -- slicing doesn't preserve type

2005-02-22 Thread Kent Johnson
Brian van den Broek wrote: Hi all, I'm trying to figure out how to subclass the list built-in. .>>> class my_list(list): def __init__(self, sequence=None): list.__init__(self, sequence) self.spam = 1 .>>> mine = my_list((1,2,3,4)) .>>> mine.append(42) .>>>

Re: [Tutor] subclassing list -- slicing doesn't preserve type

2005-02-22 Thread Karl =?iso-8859-1?Q?Pfl=E4sterer?=
On 22 Feb 2005, [EMAIL PROTECTED] wrote: > I'm trying to figure out how to subclass the list built-in. > > .>>> class my_list(list): > def __init__(self, sequence=None): > list.__init__(self, sequence) > self.spam = 1 > > .>>> mine = my_list((1,2,3

[Tutor] subclassing list -- slicing doesn't preserve type

2005-02-22 Thread Brian van den Broek
Hi all, I'm trying to figure out how to subclass the list built-in. .>>> class my_list(list): def __init__(self, sequence=None): list.__init__(self, sequence) self.spam = 1 .>>> mine = my_list((1,2,3,4)) .>>> mine.append(42) .>>> mine [1, 2, 3, 4,