how to import

Fedor fedor at mailandnews.com
Tue Nov 5 13:29:14 EST 2002


Hello,

I was somewhat confused by the following:
I try to import mx.DateTime in a module and import mx.ODBC from within
a class in that module.

[test1.py]
#This setup doesn't work:
import mx.DateTime
class A:
    def __init__(self):
        print mx.DateTime.now()
    def test(self):
        print mx.DateTime.now()
        import mx.ODBC
a=A()
#Results in: 2002-11-06 19:22:14.49
a.test()
#Results in: UnboundLocalError: local variable 'mx' referenced before 
assignment

[test2.py]
#However this one does:
import mx.DateTime
class A:
    def __init__(self):
        print mx.DateTime.now()
    def test(self):
        print mx.DateTime.now()
a=A()
#Results in: 2002-11-06 19:22:14.49
a.test()
#Results in: 2002-11-06 19:22:14.49

Can someone help me understand this?

Thanks,

Fedor






More information about the Python-list mailing list