2011/8/31 Yaşar Arabacı :
> @Ian: Thanks for you comments. I indeed didn't need the _sozcuk attribute at
> all, so I deleted it. My class's addition and multiplication works without
> overwriting __add__ and __mul__ because, this class uses unicode's __add__
> and __mul__ than creates a new kelime
27;s instance,
instead of unicode's
31 Ağustos 2011 20:11 tarihinde Ian Kelly yazdı:
> 2011/8/31 Yaşar Arabacı :
> > I made a class like this (I shortened it just to show the point), what do
> > you think about it, do you think it is the python way of subclassing str
> (or
2011/8/31 Yaşar Arabacı :
> I made a class like this (I shortened it just to show the point), what do
> you think about it, do you think it is the python way of subclassing str (or
> unicode in this case)
You don't need the _sozcuk attribute at all here. It's just the same
On 8/31/2011 7:43 AM, Yaşar Arabacı wrote:
Hİ,
I originally posted my question to here:
http://stackoverflow.com/q/7255655/886669 Could you people please look
at it and enlighten me a little bit? I would appreciate an answer either
from here or at stackoverflow.
I believe two people already ga
I made a class like this (I shortened it just to show the point), what do
you think about it, do you think it is the python way of subclassing str (or
unicode in this case)
# -*- coding:utf-8 -*-class kelime(unicode):
def __init__(self,sozcuk):
self._sozcuk = sozcuk
def
Hİ,
I originally posted my question to here:
http://stackoverflow.com/q/7255655/886669 Could you people please look at it
and enlighten me a little bit? I would appreciate an answer either from here
or at stackoverflow. Thanks in advance.
--
http://yasar.serveblog.net/
--
http://mail.python.org
On Wed, Nov 10, 2010 at 8:14 PM, not1xor1 (Alessandro) <"
"@libero.it> wrote:
> Il 09/11/2010 03:18, Lawrence D'Oliveiro ha scritto:
>
>> How exactly does
>>
>> a.f(b, c)
>>
>> save time over
>>
>> f(a, b, c)
>
> unfortunately in real world you have:
>
> objId = objId.method(args)
>
> vs.
>
Il 09/11/2010 03:18, Lawrence D'Oliveiro ha scritto:
How exactly does
a.f(b, c)
save time over
f(a, b, c)
unfortunately in real world you have:
objId = objId.method(args)
vs.
objId = moduleName.method(objId, args)
I know you can use "from moduleName import *", but IMHO that pro
In message <87lj52kwln.fsf@metalzone.distorted.org.uk>, Mark Wooding
wrote:
> One option is to implement a subclass which implements the additional
> protocol.
This is why I think object orientation ruins your ability to think properly.
For “protocol” read “function”. If you want to impleme
Lawrence D'Oliveiro writes:
> In message <87lj52kwln.fsf@metalzone.distorted.org.uk>, Mark Wooding
> wrote:
>
> > One option is to implement a subclass which implements the additional
> > protocol.
>
> This is why I think object orientation ruins your ability to think
> properly. For “proto
rantingrick writes:
> One thing i love about Python is the fact that it can please almost
> all the "religious paradigm zealots" with it's multiple choice
> approach to programming. However some of the features that OOP
> fundamentalists hold dear in their heart are not always achievable in
> a c
On Nov 8, 8:18 pm, Lawrence D'Oliveiro wrote:
> In message <5dlbo.1024$w8@twister2.libero.it>, not1xor1 (Alessandro)
> wrote:
>
> > I'm already using plain functions, but thought that wrapping most of
> > them in a str subclass would let me save some time and yield cleaner
> > and more managea
In message <5dlbo.1024$w8@twister2.libero.it>, not1xor1 (Alessandro)
wrote:
> I'm already using plain functions, but thought that wrapping most of
> them in a str subclass would let me save some time and yield cleaner
> and more manageable code
How exactly does
a.f(b, c)
save time over
es I've to
modify my script accordingly
I'm already using plain functions, but thought that wrapping most of
them in a str subclass would let me save some time and yield cleaner
and more manageable code
If you insist on subclassing str, there's no such hook; you'll ha
rings
as parameters is obviously a simpler, and probably more performant,
approach.
If you insist on subclassing str, there's no such hook; you'll have to
override all the methods yourself.*
Cheers,
Chris
--
*Well, you could override only the __special__ methods and
__getattri
Hi,
I'd like to know what is the best way to subclass str
I need to add some new methods and that each method (both new and str
ones) return my new type
For instance I've seen I can do:
class mystr(str):
def between(self, start, end):
i = self.index(start) + len(start)
j = se
On 23 Jun 2005 21:27:20 -0700, "Paul McGuire" <[EMAIL PROTECTED]> wrote:
>Dang, that class should be:
>
>class PaddedStr(str):
>def __new__(cls,s,l,padc=' '):
>if l > len(s):
>s2 = "%s%s" % (s,padc*(l-len(s)))
>return str.__new__(cls,s2)
>else:
>
In article <[EMAIL PROTECTED]>,
"Paul McGuire" <[EMAIL PROTECTED]> wrote:
...
> This reminds me of some maddening O-O discussions I used to
> have at a former place of employment, in which one developer cited
> similar behavior for not having Square inherit from Rectangle - calling
> Square.setWid
Look at the related post, on keeping key-key pairs in a dictionary.
Based on our discussion in this thread, I created a subclass of dict
called SymmetricDict, that, when storing symDict["A"] = 1, implicitly
saves the backward looking symDict[1] = "A".
I chose to inherit from dict, in part just to
In article <[EMAIL PROTECTED]>,
"Paul McGuire" <[EMAIL PROTECTED]> wrote:
[ ... lots of interesting discussion removed ... ]
> Most often, I see "is-a" confused with "is-implemented-using-a". A
> developer decides that there is some benefit (reduced storage, perhaps)
> of modeling a zip code usi
>From purely Python terms, there is a distinction that one of these
classes (PaddedStr) is immutable, while the other is not. Python only
permits immutable objects to act as dictionary keys, so this would one
thing to differentiate these two approaches.
But on a more abstract, implementation-inde
Donn Cave wrote:
> Left unexplained is ``true "is-a" relationships''. Sounds
> like an implicit contradiction -- you can't implement
> something that truly is something else. Without that, and
> maybe a more nuanced replacement for "is-implemented-using-a",
> I don't see how you could really be s
Dang, that class should be:
class PaddedStr(str):
def __new__(cls,s,l,padc=' '):
if l > len(s):
s2 = "%s%s" % (s,padc*(l-len(s)))
return str.__new__(cls,s2)
else:
return str.__new__(cls,s)
-- Paul
--
http://mail.python.org/mailman/listin
Brent wrote:
> I'd like to subclass the built-in str type. For example:
You'd like to build this weird-looking semi-mutable object as a
perceived solution to what problem? Perhaps an alternative is a class of
objects which have a "key" (your current string value) and some data
attributes? Mayb
In article <[EMAIL PROTECTED]>,
Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> On Thu, 23 Jun 2005 12:25:58 -0700, Paul McGuire wrote:
>
> > But if you are subclassing str just so that you can easily print your
> > objects, look at implementing the __str_
On Thu, 23 Jun 2005 12:25:58 -0700, Paul McGuire wrote:
> But if you are subclassing str just so that you can easily print your
> objects, look at implementing the __str__ instance method on your
> class. Reserve inheritance for true "is-a" relationships. Often,
> inherita
My first thought is "make sure that subclassing str is really what you
want to do." Here is a place where I have a subclass of str that
really is a special kind of str:
class PaddedStr(str):
def __new__(cls,s,l,padc=' '):
if l > len(s):
s2 = &q
I'd like to subclass the built-in str type. For example:
--
class MyString(str):
def __init__(self, txt, data):
super(MyString,self).__init__(txt)
self.data = data
if __name__ == '__main__':
s1 = MyString("some text", 100)
--
but I get the error:
Traceback (most rec
28 matches
Mail list logo