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 >

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

[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

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 stdin, line 1, in module __main__.Foo: None

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

[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) Traceback (most

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

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 stdin, line 1, in module __main__.Foo: None Inheriting from SyntaxError doesn't work! When I create a new exception, I

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

Re: [Tutor] Subclassing object

2010-01-17 Thread Alan Gauld
Timo Vanwynsberghe timo...@gmail.com 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

Re: [Tutor] Subclassing object

2010-01-17 Thread Robert
On Sun, Jan 17, 2010 at 12:47 PM, Robert webtour...@gmail.com wrote: On Sun, Jan 17, 2010 at 11:25 AM, Alan Gauld alan.ga...@btinternet.com 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

Re: [Tutor] Subclassing object

2010-01-17 Thread Alan Gauld
Robert webtour...@gmail.com 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,

[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)

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,

Re: [Tutor] Subclassing list

2009-06-18 Thread Luis N
On Fri, Jun 19, 2009 at 12:56 AM, bob gailer bgai...@gmail.com 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):    def

Re: [Tutor] Subclassing list

2009-06-18 Thread Kent Johnson
On Thu, Jun 18, 2009 at 9:48 PM, Luis Ngloboph...@gmail.com 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,

[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

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 =

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 already

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 Python

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 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 any other

[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

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

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 styles

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 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' children_query =

[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 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

[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

[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

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

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

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)

[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,

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 =

[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, 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,4)) .

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) . mine [1,

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 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