On 7/14/2010 8:31 AM Corey Richardson said...
I was under the impression that when you define a function, it doesn't
try to evaluate anything yet. If I had called the function before I
defined the variable, I would understand, but I haven't.


The difference is in understanding what's executed and what's deferred.

Consider the following:

#-----Start File test.py-----
def test():
  print "in def test"

class Test:
  print "in class Test"
  def __init__(self):
    print "in class Test.__init__"

print "in __main__"

test()
t = Test()

#-----End File test.py-----

Output:

in class Test
in __main__
in def test
in class Test.__init__

-----------------

As you can see, the print statements at the class level are executing when encountered, but the prints in defs only when executed.

HTH,

Emile


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to