Difference in Python and Ruby interactive shells

Sybren Stuvel sybrenUSE at YOURthirdtower.com.imagination
Tue Apr 4 10:31:05 EDT 2006


dmh2000 enlightened us with:
> When you want to change something, you can edit those same source
> files outside the environment and reload them from within the
> interactive environment. But, here is the difference: with Python,
> when you reload the source file (module in Python terms), it seems
> that your existing variables stay bound to the implementations from
> the old version of the module.

IMO this is the only proper way of doing things. A variable points to
something in memory. When a module is reloaded, that thing in memory
is still there - because it is referenced, it does not get garbage
collected.

> Ruby interactive shell (irb.exe)
>
> C:\home\dh0072\rq>irb
>
> # load a local file b.py for test
>
> irb(main):001:0> load "b.rb"
>=> true
>
> # instantiate an object and call a method
>
> irb(main):002:0> x = B.new
>=> #
> irb(main):003:0> x.p
> B
>=> nil
>
> # edit b.py offline to change method 'p' to do something different then
> reload
>
> irb(main):004:0> load "b.rb"
>=> true
> irb(main):005:0> x.p
> BBBB
>=> nil
>
> # binding of variable 'x' IS changed. points to new version

IMHO this is nasty. An assignment has already been performed.
Reloading some module should not (again, IMHO) change anything that
happened before it was reloaded.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
                                             Frank Zappa



More information about the Python-list mailing list