triple quoted strings as comments

2006-01-30 Thread dmh2000
I recently complained elsewhere that Python doesn't have multiline
comments. i was told to use triple quoted strings to make multiline
comments. My question is that since a triple quoted string is actually
a language construct, does it use cause a runtime construction of a
string which is then discarded, or is the runtime smart enough to see
that it isn't used and so it doesn't construct it?

example

def fun(self):
  """doc comment
  comment line 2
  """

  x = 1
  y = 2

  """does this triple quoted string used as a  comment
  cause something to happen at runtime beyond
  just skipping over it? Such as allocation of memory for a string
  or worse yet garbage collection? or not?
  """
  z = x + y

...

dave howard

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


Difference in Python and Ruby interactive shells

2006-04-04 Thread dmh2000
I am experimenting with the interactive interpreter environments of
Python and Ruby and I ran into what seems to be a fundamental
difference. However I may be doing something wrong in Python. Please
comment and correct me if I am wrong

In both languages, you can start up the interactive interpreter
('python' and 'irb'), load source files and do stuff, like create
objects and call their methods. 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. In Ruby, after a
reload, your existing variables point to the new implementation. At
least, that is what happens with classes and their methods.  This means
that in Python, if you have an application built up interactively, with
references to objects, data structures pointing to objects, etc., you
would have to reconstruct that application to get the new
implementation. With Ruby, when you load the new implementation, you
get it immediately.

here is a simple example:

---
Python interactive shell (python.exe)

C:\home\dh0072\rq>python
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.

# load a local file b.py for test

>>> import b

# instantiate an object and call a method

>>> x = b.B()
>>> x.p()
B

# edit b.py offline to change method 'p' to do something different then
reload

>>> reload(b)

>>> x.p()
B

# binding of variable 'x' IS NOT changed. points to old version

>>> y = b.B()
>>> y.p()
B

# new instance of 'b' points to new version

>>>
---
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

=> nil

# binding of variable 'x' IS changed. points to new version

irb(main):006:0> y = B.new
=> #
irb(main):007:0> y.p

=> nil

#  new instance of 'b' points to new version

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


Re: Difference in Python and Ruby interactive shells

2006-04-06 Thread dmh2000
Thanks all for the responses. Extra kudos to Steve J and Michele S.
that cleared it up for me.

the context of my question comes from reading up on Lisp in "Loving
Lisp - the Savy Programmer's Secret Weapon",
http://www.markwatson.com/opencontent/lisp_lic.htm, where the author
described building up a large system during test, that took a long to
to load. He was showing one reason why a dynamic language was more
productive than a statically compiled language.

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