What's better about Ruby than Python?

Andrew Dalke adalke at mindspring.com
Tue Aug 19 19:10:22 EDT 2003


Alexander Schmolck, responding to me:
> > from Q import X
> >
> > class X:
> >     def amethod(self): return 'ah, now THIS is better!'
> >
> > Should it refine the X in the local namespace or make a new
> > class?
>
> I'd say redefine X in the local namespace. Have you spotted a problem with
it?

I'm thinking about problems like this

# module a.py
class X:
  def a(self): print "qwerty"

# module b.py
from a import X

def redo():
    global X
    class X:
        def a(self): print "asdfg"

# interactively
from b import X, redo

x = X()
redo()
print x.a()
print X().a()


Does the interactive loading of X get a copy of b.X,
which is a copy of a.X?

Because of the 'global X',  will the redefinition
of X in redo() change the module definition?
What's the output from the print statements?

In short, it would be the only thing in Python which
rebinds a local variable in-place, and I don't have
good feelings about the consequences.

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list