On Sat, May 12, 2012 at 9:10 AM, Ethan Furman wrote:
>
> Firstly, __slots__ is a tuple.
I object: conceptually, the "slots" of a class are set in stone, but
the `__slots__` attribute of a class object is just an attribute, and
any iterable (as long as it yields valid identifier names) can be used
> p.s. Is Python seeing a lot of use at Ubisoft or is this just for personal
> interest (or
> perhaps both)?
We do use Python a fair bit, mostly for build systems and data mining, but also
because it's the built-in script language for Motionbuilder.
--
http://mail.python.org/mailman/listinfo/py
Karl Knechtel wrote:
On Thu, May 10, 2012 at 9:33 AM, Andreas Tawn wrote:
And there's also something like...
return "\n".join((": ".join((str(k), str(self.__dict__[k]))) for k in
self.__dict__))
which is a nice length, but I lose control of the order of the attributes and
the formatting is
On Thu, May 10, 2012 at 9:33 AM, Andreas Tawn wrote:
> And there's also something like...
>
> return "\n".join((": ".join((str(k), str(self.__dict__[k]))) for k in
> self.__dict__))
>
> which is a nice length, but I lose control of the order of the attributes and
> the formatting is fixed. It al
On 11May2012 15:40, Mark Lawrence wrote:
| On 11/05/2012 15:32, Andreas Tawn wrote:
| > It's also helpful to not have to display every attribute, of which there
may be dozens.
|
| Do I detect a code smell here?
Not necessarily. (Well, yeah, "dozens" may indicate time to partition
stuff.) My "O"
> >> It's also helpful to not have to display every attribute, of which
> >> there may be dozens.
> >
> > Do I detect a code smell here?
> >
> I think so, Murphy's law dictates that the attribute you're interested in
> will not be
> displayed anyway.
That's what __repr__'s for.
--
http://mail.py
> > It's also helpful to not have to display every attribute, of which there
> > may be
> dozens.
>
> Do I detect a code smell here?
Possibly. I'll often try to subdivide into several simpler types, but sometimes
that makes the code more complex than it needs to be.
--
http://mail.python.org/m
Mark Lawrence wrote:
On 11/05/2012 15:32, Andreas Tawn wrote:
It's also helpful to not have to display every attribute, of which
there may be dozens.
Do I detect a code smell here?
I think so, Murphy's law dictates that the attribute you're interested
in will not be displayed anyway.
JM
-
On 11/05/2012 15:32, Andreas Tawn wrote:
It's also helpful to not have to display every attribute, of which there may be
dozens.
Do I detect a code smell here?
--
Cheers.
Mark Lawrence.
--
http://mail.python.org/mailman/listinfo/python-list
> I have no idea why using __repr__ versus __str__ would make any difference in
> the
> order of the attributes. They're going to come out in the order you specify,
> regardless of what you name your method. If you don't like the arbitrary
> order you
> get from the dictionary, then either sort
On 05/11/2012 07:16 AM, Andreas Tawn wrote:
>>
>> This is a very interesting solution.
>>
>> I think it might be better suited (for my purpose) to __repr__ rather than
>> __str__, mostly because I still lose control of the order the attributes
>> appear.
I have no idea why using __repr__ versus
> This issue bit me once too often a few months ago, and now I have a class
> called
> "O" from which I often subclass instead of from "object".
> Its main purpose is a friendly __str__ method, though it also has a friendly
> __init__.
>
> Code:
>
> class O(object):
> ''' A bare objec
On 10May2012 15:33, Andreas Tawn wrote:
| Say I've got a class...
|
| class test(object):
| def __init__(self):
| self.foo = 1
| self.bar = 2
| self.baz = 3
|
| I can say...
|
| def __str__(self):
|return "foo: {0}\nbar: {1}\nbaz: {2}".format(self.foo, self.bar,
On Fri, May 11, 2012 at 1:15 AM, Andreas Tawn wrote:
> I considered the triple quote string one, but it's not very PEP 8 compatible
> in a real class because it includes the indentation in the formatted string.
Yeah, that is an annoying side effect. My personal view is that code
should be writte
> On Thu, May 10, 2012 at 11:33 PM, Andreas Tawn
> wrote:
> > Say I've got a class...
> >
> > class test(object):
> > def __init__(self):
> > self.foo = 1
> > self.bar = 2
> > self.baz = 3
> >
> > I can say...
> >
> > def __str__(self):
> > return "foo: {0}\nbar: {1}\nbaz
On Thu, May 10, 2012 at 11:33 PM, Andreas Tawn wrote:
> Say I've got a class...
>
> class test(object):
> def __init__(self):
> self.foo = 1
> self.bar = 2
> self.baz = 3
>
> I can say...
>
> def __str__(self):
> return "foo: {0}\nbar: {1}\nbaz: {2}".format(self.foo, self
Say I've got a class...
class test(object):
def __init__(self):
self.foo = 1
self.bar = 2
self.baz = 3
I can say...
def __str__(self):
return "foo: {0}\nbar: {1}\nbaz: {2}".format(self.foo, self.bar, self.baz)
and everything's simple and clean and I can vary the f
17 matches
Mail list logo