[python]locals内置函数
locals
()Update and return a dictionary representing the current local symbol table. Free variables are returned by
locals()
when it is called in function blocks, but not in class blocks.Note: The contents of this dictionary should not be modified; changes may not affect the values of local and free variables used by the interpreter.
内置函数locals返回的是当前状态的本地命名空间, 应该当作只读字典处理, 写入会有意外发生.
在函数中, 或者其他局部变量产生的情况下, 对其的更改可能无法保存.
def f():
x = 10
lc = locals()
lc['x'] = 20
# 'x'->20 remains on dictionary before locals() is called
print lc
# {'x': 20}
locals()
# locals dictionary is refreshed in the above call to locals()
print lc
# {'x': 10, 'lc': {...}} f()
[python]locals内置函数的更多相关文章
- python基础-内置函数详解
一.内置函数(python3.x) 内置参数详解官方文档: https://docs.python.org/3/library/functions.html?highlight=built#ascii ...
- 如何查看Python的内置函数
经常调用的时候不知道python当前版本的内置函数是哪些,可以用下面的指令查看: C:\Users\Administrator>python Python 2.7.11 (v2.7.11:6d1 ...
- python基础——内置函数
python基础--内置函数 一.内置函数(python3.x) 内置参数详解官方文档: https://docs.python.org/3/library/functions.html?highl ...
- Python的内置函数
python的内置函数一共有68个,下面将简单介绍各个函数的功能. abs() dict() help() min() setattr() all() dir() hex() next() slice ...
- Python入门-内置函数一
什么是内置函数?就是python给你提供的拿来直接用的函数,比如print,input等等,截止到python版本3.6.2 python一共提供了68个内置函数,他们就是python直接提供给我们的 ...
- python_way,day3 集合、函数、三元运算、lambda、python的内置函数、字符转换、文件处理
python_way,day3 一.集合 二.函数 三.三元运算 四.lambda 五.python的内置函数 六.字符转换 七.文件处理 一.集合: 1.集合的特性: 特性:无序,不重复的序列 如果 ...
- python print()内置函数
啦啦啦啦啦啦,我又来了,学习任何东西都得坚持,我一定的好好加油!!! 今天来说说print()函数,前边我们已经用过好好多次啦,现在来学习哈吧!!! Python的内置函数,print() print ...
- Python 集合内置函数大全(非常全!)
Python集合内置函数操作大全 集合(s).方法名 等价符号 方法说明 s.issubset(t) s <= t 子集测试(允许不严格意义上的子集):s 中所有的元素都是 t 的成员 s ...
- Python字典内置函数和方法
Python字典内置函数和方法: 注:使用了 items.values.keys 返回的是可迭代对象,可以使用 list 转化为列表. len(字典名): 返回键的个数,即字典的长度 # len(字典 ...
随机推荐
- (一)Django项目架构介绍
项目的架构为: 1.虚拟环境virtualenv 安装Django==2.1.3 安装pymysql 安装mysqlclient 安装其他等 2.项目结构为: 应用APP: blog -- 管理博客 ...
- SpringBoot基于数据库的定时任务统一管理
定时任务1 import lombok.extern.slf4j.Slf4j; /** * @author Created by niugang on 2019/12/24/15:29 */ @Slf ...
- 【转】iOS 7免费设计资源汇总
原文链接:http://mobile.51cto.com/hot-406317.htm#585532-tsina-1-28470-7e393678b940a4d55500bf3feae3d2e9 以下 ...
- 配置IDEA默认作者@author
IDEA安装目录下,使用文本编辑器打开~/bin/idea64.exe.vmoptions文件 在最后添加:-Duser.name=Your name 保存重启IDEA,Done
- Java 方法重写方法重载
1,方法的重载和方法的重写 方法名相同形参列表不通 方法名字的重新定义2,面向过程是分步骤解决问题 用方法组织代码 面向对象是以分类的方式解决问题 用类住址代码3 类是对对象的抽象 对象万事万物都是对 ...
- 02.flask-script
网址:https://pypi.org/project/Flask-Script/ 文档:https://flask-script.readthedocs.io/en/latest/ 1.安装 2.新 ...
- matplotlib 直方图
一.特点 数据必须是原始数据不能经过处理,数据连续型,显示一组或多组分布数据 histogram 直方图 normed 定额 二.核心 hist(x, bins=None, normed=None) ...
- tomcat启动时检测到循环继承而栈溢出的问题:Caused by: java.lang.IllegalStateException: Unable to complete the scan for annotations for web application [/test] due to a StackOverflowError. Possible root causes include
最近在公司更新一个老项目的时候,发现部署项目后tomcat报错,错误如下: Caused by: java.lang.IllegalStateException: Unable to complete ...
- [bzoj1070] [洛谷P2053] [SCOI2007] 修车
Description 同一时刻有N位车主带着他们的爱车来到了汽车维修中心.维修中心共有M位技术人员,不同的技术人员对不同 的车进行维修所用的时间是不同的.现在需要安排这M位技术人员所维修的车及顺序, ...
- Error:Cannot build artifact 'XXX:war exploded' because it is included into a circular dependency (artifact 'XXXX:war exploded', artifact 'XXX:war exploded') Idea启动项目报错解决方案
在Idea中使用Maven创建父子工程,第一个Model的那个项目可以很好的运行,在创建一个Model运行时报这个错.原因是tomcat部署了多个Web项目,可能最开始是两个项目的配置文件混用用,最后 ...