Marc Christiansen <[EMAIL PROTECTED]> wrote: > James T. Dennis <[EMAIL PROTECTED]> scribis: >> In fact I realized, after reading through tempfile.py in /usr/lib/... >> that the following also doesn't "work" like I'd expect:
>> # foo.py >> tst = "foo" >> def getTst(arg): > If I change this line: >> return "foo-%s" % arg > to: > return "%s-%s" % (tst, arg) >> # bar.py >> import foo >> foo.tst = "bar" >> print foo.getTst("testing") >> foo-testing <<<----- NOT "bar-testing" > Then "python bar.py" prints "bar-testing". > 0:[EMAIL PROTECTED]:/tmp> cat foo.py > tst = "foo" > def getTst(arg): > return "%s-%s" % (tst,arg) > 0:[EMAIL PROTECTED]:/tmp> cat bar.py > import foo > foo.tst = "bar" > print foo.getTst("testing") > 0:[EMAIL PROTECTED]:/tmp> python bar.py > bar-testing > And regarding the tempfile.template problem, this looks like a bug. > Because all functions in tempfile taking a prefix argument use "def > function(... , prefix=template, ...)", only the value of template at > import time matters. > Adia?, Marc I suppose my real sample code was def getTst(arg=tst): Oddly I've never come across that (the fact that defaulted arguments are evaluated during function definition) in my own coding and I guess there are two reasons for that: I try to avoid global variables and I usually use defaulted variables of the form: def (foo=None): if foo is None: foo = self.default_foo -- Jim Dennis, Starshine: Signed, Sealed, Delivered -- http://mail.python.org/mailman/listinfo/python-list