Re: Applying a function recursively

2011-09-10 Thread hetchkay
> > I suspect, if you can be explicit about the goal you're aiming for with > this code, a better design can be found that doesn't require all those > polymorphism-breaking type checks. > It is difficult to explain what I am trying to do, but let me try. I am mapping data from one hierarchy into an

Applying a function recursively

2011-09-10 Thread hetchkay
Hi, I want to apply a "convert" function on an object as follows: If the object is of MyType type, invoke the passed in function. If the object is a dictionary, apply on the keys and values of the dictionary recursively. If the object is a set, list or tuple, apply on each element recursively. Else

question on namedtuple

2010-04-01 Thread hetchkay
Hi, For purposes I don't want to go into here, I have the following code: def handleObj(obj): if isinstance(obj, MyType): return obj.handle() elif isinstance(obj, (list, tuple, set)): return obj.__class__(map (handleObj, obj)) elif isinstance(obj, dict): return obj.__class__((h

Re: 2.6 and sys.exit()

2009-11-12 Thread hetchkay
On Nov 13, 10:28 am, hetchkay wrote: > On Nov 13, 9:50 am, John Yeung wrote: > > > > > On Nov 12, 11:22 pm, r wrote: > > > > On Nov 12, 10:07 pm, hetchkay wrote: > > > > I have the following in exit.py: > > > > import sys >

Re: 2.6 and sys.exit()

2009-11-12 Thread hetchkay
On Nov 13, 9:50 am, John Yeung wrote: > On Nov 12, 11:22 pm, r wrote: > > > > > On Nov 12, 10:07 pm, hetchkay wrote: > > > I have the following in exit.py: > > > import sys > > > sys.exit(0) > > > > I now try 'python -i exit.py&#x

Re: 2.6 and sys.exit()

2009-11-12 Thread hetchkay
Hello, Thanks for your help. I know what SystemExit is. In 2.5 as well SystemExit is raised when sys.exit() is called. For example: try: import sys sys.exit(0) except SystemExit: print "system exit raised" raise But I don't understand why the interpreter does not exit in 2.6 but does exi

2.6 and sys.exit()

2009-11-12 Thread hetchkay
Hello, I have the following in exit.py: import sys sys.exit(0) I now try 'python -i exit.py': In 2.5, the script exits as I would expect. In 2.6, the following error is printed: Traceback (most recent call last): File "exit.py", line 2, in sys.exit(0) SystemExit: 0 >>> I couldn't find