2021-01-31 05:13:21 +03:00
|
|
|
def printPackage(p):
|
|
|
|
let s = repr(p)
|
|
|
|
let a,b,c,d = s.split(' ')
|
|
|
|
print(' '.join([a,b,c]),'...>')
|
|
|
|
|
2021-01-17 16:01:58 +03:00
|
|
|
def testTop():
|
|
|
|
import foo
|
2021-01-31 05:13:21 +03:00
|
|
|
printPackage(foo)
|
2021-01-17 16:01:58 +03:00
|
|
|
try:
|
|
|
|
print(foo.bar, "Fail")
|
|
|
|
except:
|
|
|
|
print(repr(exception)) # AttributeError
|
|
|
|
|
|
|
|
def testCaching():
|
|
|
|
from foo.bar import baz
|
2021-01-31 05:13:21 +03:00
|
|
|
printPackage(baz)
|
2021-01-17 16:01:58 +03:00
|
|
|
import foo
|
2021-01-31 05:13:21 +03:00
|
|
|
printPackage(foo)
|
|
|
|
printPackage(foo.bar)
|
|
|
|
printPackage(foo.bar.baz)
|
2021-01-17 16:01:58 +03:00
|
|
|
print(foo.bar.baz.qux)
|
|
|
|
|
|
|
|
def testDirect():
|
|
|
|
import foo.bar.baz
|
2021-01-31 05:13:21 +03:00
|
|
|
printPackage(foo)
|
|
|
|
printPackage(foo.bar)
|
|
|
|
printPackage(foo.bar.baz)
|
2021-01-17 16:01:58 +03:00
|
|
|
print(foo.bar.baz.qux)
|
|
|
|
|
|
|
|
def testFromImport():
|
|
|
|
from foo.bar import baz
|
2021-01-31 05:13:21 +03:00
|
|
|
printPackage(baz)
|
2021-01-17 16:01:58 +03:00
|
|
|
print(baz.qux)
|
|
|
|
try:
|
|
|
|
print(foo, "Fail")
|
|
|
|
except:
|
|
|
|
print(repr(exception))
|
|
|
|
|
|
|
|
def testRenames():
|
|
|
|
import foo.bar.baz as blah
|
2021-01-31 05:13:21 +03:00
|
|
|
printPackage(blah)
|
2021-01-17 16:01:58 +03:00
|
|
|
print(blah.qux)
|
|
|
|
try:
|
|
|
|
print(foo, "Fail")
|
|
|
|
except:
|
|
|
|
print(repr(exception))
|
|
|
|
from foo.bar.baz import qux as thing
|
|
|
|
print(thing)
|
|
|
|
try:
|
|
|
|
print(qux, "Fail")
|
|
|
|
except:
|
|
|
|
print(repr(exception))
|
|
|
|
try:
|
|
|
|
print(foo.bar, "Fail")
|
|
|
|
except:
|
|
|
|
print(repr(exception))
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
testTop()
|
|
|
|
testCaching()
|
|
|
|
testDirect()
|
|
|
|
testFromImport()
|
|
|
|
testRenames()
|