Hi all,
I'm trying to create a new instance from an existing instance with attributes
of the new instance allowed to be overwritten by keyword parameters. I'm
guessing I'm not doing this in the most efficient manner.
class Spam:
def __init__(self, a, b):
self.a = a
self.b =
Alan Gauld wrote:
> Since a class is effectively a disguised dictionary I'm not sure why you
> want to do this? If you just want to access the method by name then why
> not just call getattr(spam,'get_mean')?
Thanks for the feedback and, yes, this makes sense. My use case was when the
statistic
Hi list,
I'm trying to understand how to use a class-level dictionary to act as a switch
for class methods. In the contrived example below, I have the statistic name
as the key and the class method as the value.
class Statistics(object):
STAT = {
'MEAN': get_mean,
'SUM': ge
Hi all,
We work with a python package (ESRI geoprocessor) that only releases their
packages tied to specific minor version of Python (e.g. 2.5). We are
predominantly working with 2.6, but have Python 2.5 installed as well.
When we want to call modules that use the geoprocessor package, we are
Hi all,
Consider the following classes where PositiveX should constrain the attribute
_x to be positive and SmallX should further constrain the attribute _x to be
less than 10.
class PositiveX(object):
def __init__(self):
self._x = 1
@property
def x(self):
return sel
Hi James,
James Mills wrote:
> Rather than present you with what I think (subjective)
> might be a "good solution", why don't you look up in the
> python documentation how you define methods and
> what you can do with them (parameters-wise).
>
> I'll summarize:
>
> def foo(self, a, b, c):
>.
Sorry for what is probably a poor subject line ...
Generally, I'm trying to understand the best way to set up an object's __init__
if there are some required parameters and other parameters that can be
specified in a number of ways. As an example, I'm working on an envelope class
that describe
Hi all,
Is there a guideline on where instance member variables should be set within a
class? That is, is it a bad idea to set self variables within private member
functions rather than returning them to the enclosing caller? Or should I
avoid calls to internal functions from other member fun
Hi all,
In the 2nd edition of Python Cookbook, Mark Lutz writes the intro to Chapter 2
(Files) and gives the following example of polymorphism for file like objects
(adapted for brevity):
def firstword(line):
print line.split()[0]
def scanner(fileobject, linehandler):
for line in fileo
Steven D'Aprano wrote:
> Other than using numpy, probably the simplest solution is to just
> subclass tuple and give it named properties and whatever other methods
> you want. Here's a simple version:
>
> class Point(tuple):
> [snip]
>
> What it doesn't give you (yet!) is:
>
> * distance between
Steven D'Aprano wrote:
> It would surprise me greatly if numpy didn't already have such a class.
Yes, that is the first place I went looking, but I couldn't find such a class.
I found one project using numpy for geometry objects (geometry-simple,
http://code.google.com/p/geometry-simple/), but
Hi Steven,
Steven D'Aprano wrote:
> Every time you change the interface of inherited methods, you probably
> shouldn't.
>
> Firstly, it probably breaks the Liskov Substitution Principle. The LSP
> says, essentially, if you subclass A to make B, you should be able to
> use a B anywhere you can use
Bob Gailer wrote:
> class PointND(list):
>def __init__(self, *a_list):
> super(PointND, self).__init__(a_list)
>
>def getSet(ix):
> def chklen(self):
>if len(self) < ix + 1:
> raise AttributeError
> def get(self):
>chklen(self)
>return self[i
Wayne Werner wrote:
> class Point2D(PointND):
> def __init__(self, x = 0, y = 0):
> super(Point2D, self).__init__([x,y])
> self.x = 0
> self.y = 0
>
> though you wouldn't be able to directly modify the values, or you'll
> lose the distance function. You'd have to creat
Hi all,
I often struggle with object design and inheritance. I'd like opinions on how
best to design a Point class to be used in multiple circumstances.
I typically deal with geographic (either 2D or 3D) data, yet there are
occasions when I need n-dimensional points as well. My thought was to
Norman Khine wrote:
> basically i have two tables:
>
> id, url
> 24715L, 'http://aqoon.local/muesli/2-muesli-tropical-500g.html'
> 24719L, 'http://aqoon.local/muesli/2-muesli-tropical-500g.html'
>
> id, tid,
> 1, 24715L
> 2, 24719L
>
> so i want to first update t(2)'s tid to t(1)'s id for each d
16 matches
Mail list logo