copy from <Learn pyton, 3rd edition>, P506
Namespaces: The Whole Story
Now that we’ve examined class and instance objects, the Python namespace story is
complete. For reference, I’ll quickly summarize all the rules used to resolve names
here. The first things you need to remember are that qualified and unqualified names
are treated differently, and that some scopes serve to initialize object namespaces:
• Unqualified names (e.g., X) deal with scopes.
• Qualified attribute names (e.g., object.X) use object namespaces.
• Some scopes initialize object namespaces (for modules and classes).
Simple Names: Global Unless Assigned
Unqualified simple names follow the LEGB lexical scoping rule outlined for functions
in Chapter 16:
Assignment (X= value)
Makes names local: creates or changes the name X in the current local scope,
unless declared global.
Reference (X)
Looks for the name X in the current local scope, then any and all enclosing functions,
then the current global scope, then the built-in scope.
Attribute Names: Object Namespaces
Qualified attribute names refer to attributes of specific objects, and obey the rules for
modules and classes. For class and instance objects, the reference rules are augmented
to include the inheritance search procedure:
Assignment (object.X= value)
Creates or alters the attribute name X in the namespace of the object being qualified,
and none other. Inheritance-tree climbing happens only on attribute
reference, not on attribute assignment.
Reference (object.X)
For class-based objects, searches for the attribute name X in object, then in all
accessible classes above it, using the inheritance search procedure. For nonclass
objects such as modules, fetches X from object directly.
分享到:
相关推荐
python库。 资源全名:import_resolve-0.1.2.tar.gz
cannot resolve unit name 问题(delphi2007-delphi2010) 出现这类问题的情况,一般是可以编译,运行程序的. ,但是在输入.号的时候不能出现自动提示.
几天了一直没找到这个问题的解决方法,网上说有什么补丁也没下到,今天自己摸索解决了,给遇到同样问题的网友一个参考吧
作为MySQL调优的一部分,很多人都推荐开启skip_name_resolve。这个参数是禁止域名解析的(当然,也包括主机名)。很多童鞋会好奇,这背后的原理是什么,什么情况下开启这个参数比较合适。 基于以下原因,MySQL服务端...
资源分类:Python库 所属语言:Python 资源全名:pkgutil_resolve_name-0.0.0a0.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
opencv4.1.0使用cmake编译时,提示FFMPEG: Download failed: 6;"Couldn't resolve host name
在优化MYSQL配置时,加入 skip-name-resolve ,在重新启动MYSQL时检查启动日志,发现有警告信息
解决方法:在配置文件my.cnf的[mysqld]下加入skip-name-resolve。 原因是默认安装的MySql开启了DNS的反向解析。如果禁用的话就不能在MySQL的授权表中使用主机名了而只能用ip格式。 附:How MySQL uses DNS When a ...
发现大量的进程的状态为 login 原来默认的时候mysql启动时是不使用 skip-name-resolve选项的,这样的话,从其它主机的连接会比较慢,因为mysql会对这个ip做dns反向查询,导致大量的连接处于 login状态….....
XE10 编译提示 cannot resolve unit name Graphics 处理完成
The recipes take a problem-solution approach to resolve issues commonly faced by Python programmers across the globe. You will be armed with the knowledge of creating applications with flexible ...
PEP 3155: Qualified name for classes and functions PEP 412: Key-Sharing Dictionary PEP 362: Function Signature Object PEP 421: Adding sys.implementation SimpleNamespace Using importlib as the ...
pyyaml模块在python中用于处理yaml格式数据,主要使用yaml.safe_dump()、yaml.safe_load()函数将python值和yaml格式数据相互转换。当然也存在yaml.dump()、yaml.load()函数,同样能实现数据转换功能,只是官方不太...
原来是Mysql会对请求的地址进行域名解析,开发的电脑并没有域名,所以会导致特别的慢,下面通过本文给大家分享MySql使用skip-name-resolve解决外网链接客户端过慢问题
主要介绍了mysql 加了 skip-name-resolve不能链接数据库问题的解决方法,需要的朋友可以参考下
前端开源库-resolve-bower以异步和同步方式代表bower文件解析bower,如require.resolve()。