Re: Subclassing str object

2011-08-31 Thread Ian Kelly
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

Re: Subclassing str object

2011-08-31 Thread 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 instance with return value of thos

Re: Subclassing str object

2011-08-31 Thread Ian Kelly
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 as the value of the uni

Re: Subclassing str object

2011-08-31 Thread Terry Reedy
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

Re: Subclassing str object

2011-08-31 Thread 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) # -*- coding:utf-8 -*-class kelime(unicode): def __init__(self,sozcuk): self._sozcuk = sozcuk def __getattr

Re: subclassing str

2010-11-10 Thread Chris Rebert
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. >

Re: subclassing str

2010-11-10 Thread not1xor1 (Alessandro)
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

Re: subclassing str

2010-11-10 Thread Lawrence D'Oliveiro
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

Re: subclassing str

2010-11-10 Thread Mark Wooding
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

Re: subclassing str

2010-11-09 Thread Mark Wooding
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

Re: subclassing str

2010-11-08 Thread rantingrick
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

Re: subclassing str

2010-11-08 Thread Lawrence D'Oliveiro
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

Re: subclassing str

2010-11-07 Thread not1xor1 (Alessandro)
Il 07/11/2010 07:41, Chris Rebert wrote: You could subclass UserString instead of str; all of UserString's methods seem to ensure that instances of the subclass rather than just plain strs or UserStrings are returned. See http://docs.python.org/library/userdict.html#UserString.UserString I'll

Re: subclassing str

2010-11-06 Thread Chris Rebert
On Sat, Nov 6, 2010 at 10:43 PM, not1xor1 (Alessandro) <" "@libero.it> wrote: > 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):