Subclassing Python's dict

2009-08-05 Thread Sergey Simonenko

Hi,

I subclass builtin 'dict' in my application and experience some problems  
with it.


The whole issue is that I should redefine 'setdefault' and 'update'  
methods after redefining '__setitem__' or/and '__delitem__',
otherwise 'update' and 'setdefault' ignore redefined '__setitem__' and use  
builtin dict's one so dict looks kinda like a black box.


Another guy have reported me that he experiences similar problems with  
subclassing builtin 'list'.


Kind regards, Sergey.

--
Написано в почтовом клиенте браузера Opera: http://www.opera.com/mail/

--
http://mail.python.org/mailman/listinfo/python-list


Re: Subclass dynamically

2009-08-18 Thread Sergey Simonenko
On Sat, 08 Aug 2009 11:12:30 -0600, Robert Dailey   
wrote:


How can you subclass a class from an object?..


Hey,

I have a class that I want to have a different base class depending on
a parameter that I pass to its __init__method. For example
(pseudocode):

class MyDerived( self.base ):
  def __init__( self, base ):
self.base = base


Something like that... and then I would do this:

foo = MyDerived( MyBase() )

Note I'm using Python 3.1 on Windows. Thanks in advance.



--
Kind regards, Sergey Simonenko.

--
http://mail.python.org/mailman/listinfo/python-list


Re: How to improve this code?

2009-09-18 Thread Sergey Simonenko

elements_present = lambda seq, match: any(((x in match) for x in seq))

On Mon, 14 Sep 2009 19:08:59 -0600, Oltmans  wrote:


Hello,

Is there someway I can improve the following code(pythonically)?
(Copying from IDLE)
match=[1,2,3,4,5]

def elementsPresent(aList):
result=False
if not aList:
return False
for e in aList:
if e in match:
result=True
else:
result = False
return result
 elementsPresent([6,7,8,9,5]) # should return True because 5 is
present in list named match.

Is there somehow I can improve code in elementsPresent()? I'm not a
very good programmer but I sense that idea of using a variable named
'result' inside elementsPresent() doesn't sound very good. Any ideas
will be highly appreciated.

Thanks,
Oltmans



--
Kind regards, Sergey Simonenko.

--
http://mail.python.org/mailman/listinfo/python-list