On Mon, Oct 5, 2009 at 4:41 PM, David Perlman wrote:
> I fixed this by changing it to "mods=None" and then setting it in the body
> of the __init__ method. Works fine now.
That is the correct fix.
> My question is, is this just a quirky misbehavior, or is there a principled
> reason why the co
> def __init__(self, time, mods=[], dur=None, format='%1.2f'):
> :
> The mods that were added to the first instance of oneStim also appear in the
> second, newly created instance!
>
> It appears that what is happening here is that the __init__() method is
> being parsed by the interpreter
On Mon, Oct 5, 2009 at 3:41 PM, David Perlman wrote:
> OK, I thought I had this one fixed but it was weirder than I thought. I
> think I understand what's going on, but I wanted to check with the experts
> here.
>
> I have the following class definition, which does not subclass anything:
>
> cla
David Perlman wrote:
OK, I thought I had this one fixed but it was weirder than
I thought. I think I understand what's going on, but I wanted to check
with the experts here.
I have the following class definition, which does not subclass
anything:
class oneStim:
def __init__(
OK, I thought I had this one fixed but it was weirder than I thought.
I think I understand what's going on, but I wanted to check with the
experts here.
I have the following class definition, which does not subclass anything:
class oneStim:
def __init__(self, time, mods=[], dur=None, fo
Yeah, this seems to be the best answer in this situation. :)
On Sep 10, 2009, at 4:17 PM, Kent Johnson wrote:
I would skip the cleverness of trying to subclass string. You can use
str(z).rjust(20) as above, or use string formatting:
'%20s' % z
--
-dave---
On Thu, Sep 10, 2009 at 4:51 PM, David Perlman wrote:
> Well, here's what I am really doing:
>
> class oneStim(str):
> def __init__(self, time, mods=[], dur=None, format='%1.2f'):
> self.time=time
> self.mods=mods
> self.dur=dur
> self.format=format
This is a bit od
tutor-bounces+christopher.henk=allisontransmission@python.org wrote on
09/10/2009 04:13:23 PM:
> I'm not sure why I'm getting an error at the end here:
>
> >>> class dummy:
> ... def __init__(self,dur=0):
> ... self.dur=dur
> ...
> >>> z=dummy(3)
> >>> z.dur
> 3
> >>> z=d
> When you sub "int" for "str", it seems to work. Is there a reason
> you're not just subclassing "object"? I believe doing so would give
> you the best of both worlds.
>
Of course, I should qualify the above -- the "str" subclass inherits
very different methods than "int" or "object".
http://doc
Well, here's what I am really doing:
class oneStim(str):
def __init__(self, time, mods=[], dur=None, format='%1.2f'):
self.time=time
self.mods=mods
self.dur=dur
self.format=format
def __cmp__(self,other):
return cmp(self.time,other.time)
def _
class dummy2(str):
> ... def __init__(self,dur=0):
> ... self.dur=dur
> ...
z=dummy2(3)
z.dur
> 3
>
> So far so good. But:
>
z=dummy2(dur=3)
> Traceback (most recent call last):
> File "", line 1, in
> TypeError: 'dur' is an invalid keyword argument for this f
11 matches
Mail list logo