Sam Ruby wrote:

Consider the following code:

  def f(x): return len(x)
  for i in [0,1]:
    print f("foo")
    f = lambda x: x.upper()

No, don't. Consider the following code instead:

    def f(x): return len(x)
    for i in [0,1]:
      print f("foo")
      len = lambda x: x.upper()

Key difference is the last line. In this example, there is only one definition for f, one that will call whatever function is defined as "len" at the time of the call.

- Sam Ruby

Reply via email to