What's better about Ruby than Python?

Andrew Dalke adalke at mindspring.com
Wed Aug 20 01:10:22 CEST 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

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()
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.

                    dalke at dalkescientific.com

More information about the Python-list mailing list