class TestForFromClassImportItsSundryAttributes: ClassAttribute = lambda: tprint("class attribute") def ordinaryMethod(self): tprint("ordinary method") @staticmethod def staticMethod(): tprint("static method") @classmethod def classMethod(that): tprint("class method") def __repr__(self): tprint("magic method") return "test for from class import its sundry attributes"
def __init__(this, *args, **kwargs): tprint("top __init__ function within a script is", type(__init__), "in", __file__, this, args, kwargs)
from cfg import tprint tprint("file is", __file__) tprint("package is", __package__) # TODO: 在脚本顶层定义以下魔法属性是然并卵的事情 # __new__ # __init__ # __call__ # __add__ # __del__ # __eq__ # __metaclass__ # __slot__ # TODO: 为何可以给模块对象动态添加却用不到下列方法 # def __getattr__(this, name): # tprint("get a none-existent attribute", name, "in", __file__) # def __setattr__(this, name, entity): # tprint("set attribute", this, name, entity, "in", __file__) # def __getattribute__(this, name): # tprint("get a defined attribute", name, "in", __file__) __dict__ = {"name": "bob", "sex": "secret"} def __init__(this, *args, **kwargs): tprint("top __init__ function within a script is", type(__init__), "in", __file__, this, args, kwargs)
def me(): tprint("this is", me.__name__, "in", __file__)
from cfg import tprint tprint("file is", __file__) tprint("package is", __package__) from operator import getitem from collections import Counter def me(): tprint("this is", me.__name__, "in", __file__) from explicit.intricacy import * # 测试相对引入 # from ..implicit import libi # attempted relative import beyond top-level package from .intricacy import *
def c(): tprint("this is", c.__name__, "in", __file__)
def __repr__(self): tprint("magic method") return "test for from class import its sundry attributes"
def __init__(this, *args, **kwargs): tprint("top __init__ function within folder module's __init__.py", this, args, kwargs, "in", __file__)
def staticMethod(): tprint("static method")
def ordinaryMethod(self): tprint("ordinary method")
def b(): tprint("this is", b.__name__, "in", __file__)
def init(): tprint("this is", __file__, init.__name__, "in", __file__)
def __init__(self): tprint("i am", self.__class__.__name__, "in", __file__)
from cfg import tprint, tpprint tprint("file is", __file__) tprint("package is", __package__) def init(): tprint("this is", __file__, init.__name__, "in", __file__) class Init(object): def __init__(self): tprint("i am", self.__class__.__name__, "in", __file__) def me(): tprint("this is", me.__name__, "in", __file__) from momus import c c.c() c.cc() import momus tprint("folder without __init__.py is", type(momus), "in", __file__, dir(momus)) tprint("script under folder without __init__ attribute is", type(c), "in", __file__, dir(c)) from momus import d
def dd(): tprint("this is", dd.__name__, "in", __file__)
def classMethod(that): tprint("class method")
def __init__(self): tprint("classic class in newer python is normal class automatically")
def a(): tprint("this is", a.__name__, "in", __file__)