当前位置:网站首页>Eval function, global, local variables
Eval function, global, local variables
2022-06-27 20:29:00 【LRJ-jonas】
eval() function :
a=10; print(eval("a+1"))
eval Function will “ String text ” Change to code variable
stay Python in evel() The syntax format of the function is eval(expression, globals=None, locals=None)
global:g local:t
a=10
b=20
c=30
g={'a':6,'b':8}
t={'b':100,'c':10}
print(eval('a+b+c',g,t))
a and c Go to the dictionary respectively g And the dictionary t The value in , When globals and locals There are parameters in b You take locals The value in . therefore a=6,b=100,c=10. The running result is 116
application : You can use one line of code to implement the functions of the calculator print(eval(input(' Please enter ')))
.
shortcoming : But because it has the ability to convert strings into expressions for execution , So it can execute system commands . This can easily be used by people with ulterior motives to execute system commands , Delete key system files .
边栏推荐
- As a software engineer, give advice to young people (Part 2)
- Common shell script commands (4)
- 【debug】平台工程接口调试
- 低代码开发平台是什么?为什么现在那么火?
- UE4随笔:FString、FName 与 FText
- 安全才是硬道理,沃尔沃XC40 RECHARGE
- ABAP随笔-通过api获取新冠数据
- [bug] there is an error uploading the picture (413 request entity too large)
- Rust advanced ownership - memory management
- 优维HyperInsight:掘金164.94亿美元可观测市场的“金锄头”?
猜你喜欢
CSDN 技能树使用体验与产品分析(1)
Redis cluster
Graylog 新一代日志收集预警系统安装配置
Data intelligence enters the "deep water area", and data governance is the key
UE4: explanation of build configuration and config
Database lock problem
一段时间没用思源,升级到最新的 24 版后反复显示数据加密问题
muduo
openssl客户端编程:一个不起眼的函数导致的SSL会话失败问题
Bit. Store: long bear market, stable stacking products may become the main theme
随机推荐
Redis cluster
Redis cluster Series II
低代码开发平台是什么?为什么现在那么火?
1028 List Sorting
1025 PAT Ranking
[数组]BM99 顺时针旋转矩阵-简单
Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
Summary of submarine cable detection technology
1023 Have Fun with Numbers
海量数据出席兰州openGauss Meetup(生态全国行)活动,以企业级数据库赋能用户应用升级
键入网址到网页显示,期间发生了什么?
Logcli Loki command line tool
At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions
【STL编程】【竞赛常用】【part 3】
CSDN 技能树使用体验与产品分析(1)
SQL报了一个不常见的错误,让新来的实习生懵了
从指令交读掌握函数调用堆栈详细过程
Grasp the detailed procedure of function call stack from instruction reading
When developing digital collections, how should cultural and Museum institutions grasp the scale of public welfare and Commerce? How to ensure the security of cultural relics data?
Linux系统ORACLE 19C OEM监控管理