Re: Sudden doubling of nearly all messages

2012-07-22 Thread Alan Ristow

On 07/21/2012 12:48 PM, Dave Angel wrote:

Has anybody else noticed the sudden double-posting of nearly all
messages in the python mailing list?

[snip]

I'm using Thunderbird 14.0 on Linux 11.04, with mail configured for
non-digest mode.  I read the messages in threaded mode.

I'm pretty sure it is Thunderbird-related -- I have had this issue 
before as well. Unfortunately, I cannot remember how I solved it. It 
seems like there was a particular box that needed to be checked or 
unchecked in the IMAP settings for the mail server, but I can't be sure 
anymore.


Alan
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pydev configuration

2012-05-09 Thread Alan Ristow

On 05/09/2012 01:16 PM, hamiljf wrote:

I suppose this is the nearest thread... editor configuration and all.
I'm using PyDev in a MyEclipse environment and it works fine, except for one
tiny but horrible niggle.

The editor function I can't find is block indent/exdent... like you can
block comment/uncomment it would be really handy to be able to do the same
with indentation.  I cannot believe the function isn't there, but I cannot
find it.


Select the code block you want to indent and hit Tab. To do the reverse, 
hit Shift-Tab.


Alan
--
http://mail.python.org/mailman/listinfo/python-list


Making helper methods more concise

2012-04-16 Thread Alan Ristow
Hi all,

I have defined a class that includes a number of helper methods that
are useful to me, but pretty redundant. Something like so, where I
maintain a list of tuples:

class A(object):
def __init__(self):
self.listing = []

# This method does the work.
def append_text(self, text, style):
self.listing.append((text, style))

# The rest of the methods are just helpers.
def append_paragraph(self, text):
self.append_text(text, 'Paragraph')

def append_header(self, text):
self.append_text(text, 'Header')

def append_title(self, text):
self.append_title(text, 'Title')

obj = A()
obj.append_title('On Learning Something New About Python')
obj.append_header('A Question Is Posed')
obj.append_paragraph('Where is lorem ipsum when you need it?')


To me, this code is simple, clear, and easy to maintain, but
incredibly redundant. That's fine, I have no problem with that, but it
got me thinking: Is there a way to make the code more concise?

I know that concise is not necessarily better, but I am asking
primarily to educate myself rather than to improve this particular
piece of code -- the code only inspired the question. I'm trying to
wrap my head around decorators (aside from the simplest ones) and
metaclasses at the moment, so feel free to throw those sorts of
solutions into the mix if something like that would be appropriate.

Thanks,

Alan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Common LISP-style closures with Python

2012-02-05 Thread Alan Ristow

On 02/05/2012 05:19 AM, Antti J Ylikoski wrote:


Yes, I do know that, but then it would not be a closure :-)


Forgive me if this is terribly naive, but what is the advantage of using 
a closure as opposed to, say, some other function that returns the same 
value in the same context, but is not a closure?


Alan

-- 
http://mail.python.org/mailman/listinfo/python-list


Advice requested on class design

2010-04-28 Thread Alan Ristow
Hi all,

I am relatively new to Python, though not to programming in general, and
using Python 2.6. I have a design problem that I cannot quite decide how to
handle and I am hoping for some advice.

I would like to have three classes, ClassA, ClassB, and ClassC, that are
essentially the same, the only difference being that each class has a
different range of valid values for its properties. Thus, the obvious
solution is to create a base class, then subclass from that and include the
required error-checking during initialization and when property values
change. The base class might look something like this:

class BaseClass(object):
def __init__(self, arg1, arg2):
self.a = arg1
self.b = arg2

@property
def a(self):
return self.a

@a.setter
def a(self, new_a):
self.a = new_a

@property
def b(self):
return b

@b.setter
def b(self, new_b):
self.b = new_b

And ClassA might look something like this:

class ClassA(BaseClass):
def __init__(self, arg1, arg2):
assert arg1  0 and arg2  100
BaseClass.__init__(self, arg1, arg2)

@a.setter
def a(self, new_a):
assert new_a  0
self.a = new_a

@b.setter
def b(self, new_b):
assert new_b  100
self.b = new_b

However, instead of rewriting my validation code in several different
places, I would prefer to write it one time and keep it in one place. I can
write a function or method that I call each time I need to do validation,
which is the approach I would take in most languages. However, since I am
basically writing several small variations on one theme, it seems like in
Python this might be an ideal application for decorators and/or metaclasses.

So my question is, what is the most sensible way to write a set of classes
such as these in Python? I am not afraid to experiment with decorators or
metaclasses -- indeed, I would love to learn more about them -- but in this
particular project I do not want to use them just for the sake of learning
to use them. If there is a good reason to use them, I am all for it, though.

All advice appreciated,

Thanks,

Alan
-- 
http://mail.python.org/mailman/listinfo/python-list