dir(),divmod(),eval(),exec() 2018-10-6

#内置函数源码

def dir(p_object=None): # real signature unknown; restored from __doc__
    """
    dir([object]) -> list of strings

    If called without an argument, return the names in the current scope.
    Else, return an alphabetized list of names comprising (some of) the attributes
    of the given object, and of attributes reachable from it.
    If the object supplies a method named __dir__, it will be used; otherwise
    the default dir() logic is used and returns:
      for a module object: the module's attributes.
      for a class object:  its attributes, and recursively the attributes
        of its bases.
      for any other object: its attributes, its class's attributes, and
        recursively the attributes of its class's base classes.
    """
    return []

def divmod(x, y): # known case of builtins.divmod
    """ Return the tuple (x//y, x%y).  Invariant: div*y + mod == x. """
    return (0, 0)

def eval(*args, **kwargs): # real signature unknown
    """
    Evaluate the given source in the context of globals and locals.

    The source may be a string representing a Python expression
    or a code object as returned by compile().
    The globals must be a dictionary and locals can be any mapping,
    defaulting to the current globals and locals.
    If only globals is given, locals defaults to it.
    """
    pass

def exec(*args, **kwargs): # real signature unknown
    """
    Execute the given source in the context of globals and locals.

    The source may be a string representing one or more Python statements
    or a code object as returned by compile().
    The globals must be a dictionary and locals can be any mapping,
    defaulting to the current globals and locals.
    If only globals is given, locals defaults to it.
    """
    pass

'''
百度翻译:
        DEF DIR(PyObjult=无):未知的实签名;从

        “”

        DIR([Obj])->字符串列表

        如果没有参数调用,则返回当前范围中的名称。

        否则,返回字母名称的列表,包括(部分)属性。

        给定的对象和可从其获得的属性。

        如果对象提供了一个名为y.dIrthix的方法,则将使用该方法,否则

        默认的DR()逻辑被使用并返回:

        对于模块对象:模块的属性。

        用于类对象:属性及其递归属性

        它的基础。

        对于任何其他对象:它的属性,它的类的属性,以及

        递归地递归类的基类的属性。

        “”

        返回[]

        DEVMODD(x,y):已知的构建实例

        “返回元组(x//y,x%y)。不变量:div *y+mod==x。

        返回(0, 0)

        DEFEVE(*ARGs,**KWARGS):未知实签名

        “”

        在全球化和本地人的背景下评估给定的来源。

        源可以是表示Python表达式的字符串。

        或CaseRever()返回的代码对象。

        全局变量必须是字典,而局部变量可以是任何映射,

        默认为当前全局变量和本地变量。

        如果只给出全局变量,则局部变量默认为它。

        “”

        通过

        DEFEXEC(*ARGs,**KWARGS):未知实签名

        “”

        在全局和局部上下文中执行给定的源。

        源可以是表示一个或多个Python语句的字符串。

        或CaseRever()返回的代码对象。

        全局变量必须是字典,而局部变量可以是任何映射,

        默认为当前全局变量和本地变量。

        如果只给出全局变量,则局部变量默认为它。

        “”

        通过

'''

direct = '''
目录无链接:

1 scope
2 alpahabetized
3 comprising
4 reachable
5 otherwise
6 logic
7 recursively
8 invariant
9 mapping
10 evaluate

'''

context = '''

1 scope
        [ 英  [sk??p]   美  [skop]
        n. 范围;余地;视野;眼界;导弹射程
        vt. 审视]
        {the range of things that a subject, activity, book etc deals with
        〔学科、活动、书籍等的〕范围}
        <return the names in the current scope:
        返回当前范围的所有名字(变量名)>

2 alphabetize <=> alphabetize
        [ 英  ['?lf?b?ta?z]   美  ['?lf?b?'ta?z]
            vt. 依字母顺序排列;用字母表示;拼音化]
        {to arrange(安排,排列) things in order according(
         使一致) to the letters of the alphabet(字母表)
            按字母顺序排列}
        <return an alphabetized list of names comprising (
            some of) the attributes:
            返回按字母排序的变量名的列表,包括(部分)属性>

3 comprising <=> comprise
        [
             英  [k?m'pra?z]   美  [k?m'pra?z]
            vt. 包含;由…组成
            ]
        {If you say that something comprises or is comprised of a number of things or people, you mean it has them as its parts or members. 包含; 由…组成}
        <comprising (some of) the attributes
            包含(部分)属性>

4 reachable
        [ 英  ['ri?t??bl]   美  ['rit??bl]
            adj. 可获得的;可达成的]
        {   softly reachable 软可及的
            Reachable Zone 可接触区域
            reachable object 可达对象
            Reachable Accounts 成功联系量
            reachable vertex 可达顶点
            reachable neighbor 可达邻域
            reachable domain 可达范围
            Stay Reachable 保持平易近人
            reachable subnet 可达子网}
        <and of attributes reachable from it:
            以及从中可获得的属性>

5 otherwise
        [英 [??e?wa?z]   美 [??e?rwa?z]
            adv.
            否则;另外;别的方式
            adj.
            别的,另外的;不同的
            conj.
            否则,不然]
        {used when saying what bad thing will happen if something is not done
            否则,要不然 〔指如果不做某事,就会发生不好的事〕}
        <otherwise the default dir() logic is
            used and returns:
            否则,默认的dir()逻辑就会被使用并返回(如下值:)>

6 logic
        [ 英  ['l?d??k]   美  ['lɑd??k]
            n. 逻辑;逻辑学;逻辑性
            adj. 逻辑的]
        {a way of thinking about something that seems correct and reasonable, or a set of sensible
        (明智的; 通情达理的; 合乎情理的; 意识到的,能感觉到的;) reasons for doing something
            逻辑;〔做某事的〕道理,合理的想法a set of 一套}
        <逻辑>

7 recursively
        [[ri'k?sivli]
            adv. 递归地;递回地]
        {   recursively computable 递归可计算的
            recursively constructing 递归构造
            recursively projective 递归射影的
            recursively invariance 递归不变性
            Include Recursively 包括当前文件夹
                    以及它的子文件夹内所有的文件夹
            recursively axiomatizable 递归可公理化
            recursively isomorphism 递归同构
            Recursively Representative 递归可表示性
            recursively presentable 递归可表现}
        <for a class object:  its attributes, and recursively the attributes
            用于类对象,(返回)它的属性和递归属性>

8 invariant
        [ 英  [?n've?r??nt]   美  [?n'v?r??nt]
            adj. 不变的
            n. [数] 不变量;[计] 不变式]
        { an entity(实体,存在,本质), quantity(量,数量,大量,总量ˋkwɑnt?t? /), etc,

        that is unaltered(不变的/?n???lt?d/) by a 

        particular(特别的) transformation(转化) of
        coordinates(坐标,相配之衣物,使协调 /k?????d?n?ts, -?ne?ts/) 不变式; 不变量
        百度:不受特定坐标变换影响的实体、数量等

                invariant mass 不变质量
                invariant mass 固有质量
                Casimir invariant 卡西米尔不变量
                Hopf invariant 霍普夫不变量
                time invariant 时间不变量
                invariant point 不变点
                invariant function 不变函数
                invariant subgroup 不变子群
                integral invariant 积分不变式
                integral invariant 积分不变量
                optical invariant 光学不变量
                optical invariant 光学间隔}
        <Return the tuple (x//y, x%y). Invariant: div*y + mod == x.
        百度:返回元组(x//y,x%y)。不变量:div *y+mod==x?>

9 mapping <=> map
        [ 英  ['m?p??]   美  ['m?p??]
            v. 绘图;筹划(map的ing形式)
            n. 地图;绘图;[数] 映像]
        {   texture mapping 材质贴图
            texture mapping 纹理映射
            texture mapping 纹理贴图
            texture mapping 贴图坐标
            space mapping 空间映射
            space mapping 空间制图
            space mapping 空间映射法
            Squeeze mapping 挤压映射
            Cylindrical Mapping 圆柱体贴图
            Cylindrical Mapping 圆柱体映射
            Cylindrical Mapping 圆柱贴图
            Cylindrical Mapping 圆柱映射
            concept mapping 概念构图
            concept mapping 概念图
            concept mapping 概念映射
            concept mapping 概念绘图
            inverse mapping 逆映射
            inverse mapping 反向映射
            inverse mapping 逆映像
            inverse mapping 材质处理逆向算法
            Delete Mapping 删除贴图
            Automatic Mapping 自动映射
            Automatic Mapping 自动绘图
            Automatic Mapping 自动贴图
            Automatic Mapping 卷展栏
            aerial mapping 航空测绘
            aerial mapping 航空测图
            aerial mapping 航空写像
            aerial mapping 航摄制图}
        <The globals must be a dictionary and locals can be any mapping:
            全局变量必须是字典,局部变量可以是任何映射。

            eval(expression[, globals[, locals]])
            expression -- 表达式。
            globals -- 变量作用域,全局命名空间,如果被提供,
            则必须是一个字典对象。
            locals -- 变量作用域,局部命名空间,如果被提供,
            可以是任何映射对象。>

10 evaluate
            [ 英  [?'v?lj?e?t]   美  [?'v?lj?'et]
                vt. 评价;估价;求…的值
                vi. 评价;估价]
            {to judge how good, useful, or successful
                 something is 评估,评价}
            <Evaluate the given source in the context of globals and locals
              在全局和局部的上下文中评估给定的源(码)>

函数dir()
            dir()?函数不带参数时,返回当前范围内的变量、方法和定义的类型列表;带参数时,返回参数的属性、方法列表。如果参数包含方法__dir__(),该方法将被调用。如果参数不包含__dir__(),该方法将最大限度地收集参数信息。

            语法

            dir 语法:
            dir([object])

            参数说明:

            object -- 对象、变量、类型。

            ---------------------

            本段内容摘自 苏源流 的CSDN 博客

函数divmod()
            把除数和余数运算结果结合起来,返回一个包含商和余数的元组(a // b, a % b)。例如10/3 = 3……1 (3余1)
            divmod(10,3) ---> (3,1)

                >>> divmod(10,3)
                (3, 1)
                >>> 

函数eval()和exec(),可以将引号里的命令执行,input()的数据类型为str
                  eval(input()) , exec(input())就可以直接解读
                  input的内容
        运用场景:
                比如你做了一个记账程序,要修改信用卡的可用额度
                amount_usable = input('请输入现在的可用额度')
                eval(amout_usable),可用额度就由字符串类型变成了数字类型

exec()与eval()的区别:
    exec()可以解悉带=号的表达式,eval()不行。看单词意思就可以知道谁的功能
    eval<=>evaluate 求……值。
    exec<=>excute 执行

具体参考博客:https://www.cnblogs.com/yangmingxianshen/p/7810496.html

'''

>>> data = {'1':1 , '2':2}
>>> text = 'data['1'] = 111'
  File "<stdin>", line 1
    text = 'data['1'] = 111'
                  ^
SyntaxError: invalid syntax #外面和里面的引号要区分开。
>>> text = "data['1'] = 111"
>>> text
"data['1'] = 111"
>>> eval(text)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1
    data['1'] = 111
              ^
SyntaxError: invalid syntax #说=是不支持的语法
>>> exec(text)
>>> data
{'1': 111, '2': 2}#被exec改成功了
>>> 

exec()与eval()与compile()具体区别参考博客:https://www.cnblogs.com/yangmingxianshen/p/7810496.html

dir()具体:https://blog.csdn.net/kyjl888/article/details/78940805?utm_source=copy

原文地址:https://www.cnblogs.com/wujianghu/p/9747163.html

时间: 2024-08-02 01:21:05

dir(),divmod(),eval(),exec() 2018-10-6的相关文章

python中eval, exec, execfile,和compile(转载)

此日志为转载,原文链接:http://skandgjxa.blog.163.com/blog/static/1415298201010262403483/ eval(str [,globals [,locals ]])函数将字符串str当成有效Python表 达式来求值,并返回计算结果. 同样地, exec语句将字符串str当成有效Python代码来执行.提供给exec的代码的名称空间和exec语句的名称空间相同. 最后,execfile(filename [,globals [,locals

python中eval, exec, execfile,和compile

eval(str [,globals [,locals ]])函数将字符串str当成有效Python表达式来求值,并返回计算结果. 同样地, exec语句将字符串str当成有效Python代码来执行.提供给exec的代码的名称空间和exec语句的名称空间相同. 最后,execfile(filename [,globals [,locals ]])函数可以用来执行一个文件,看下面的例子: >>> eval('3+4') 7 >>> exec 'a=100' >>

如何查看 exec sp_execute 10 XXX, XXXX的RPC事件 内容

使用事件探查器经常能捕捉到类似于exec sp_execute 10 XXX, XXXX的RPC事件. 我想问下从哪里可以看到存储过程sp_execute 10的内容呢?? 方法如下: 在新建的profiler的模板里面的EventData中勾选store procedure 的SP:StmtStartingORSP:stmtCompleted这两个选项就可以查看存储过程的执行语句了.

2018/10/10 awk 分析 nginx 日志

废话不多说,简单了解一下 awk - 强大的文本分析工具,也就是分析日志 最常用的就是分析日志了吧,做统计什么,这里也拿 nginx 日志来做分析 1:统计出现次数 - 比如状态码出现次数 - 先直接上命令 awk '{print $9}' access_log | sort | uniq -c | sort -rn - 可能会有一些疑惑,这个$9 是什么? - 我们拿出一条日志来看一下先 123.124.16.83 - - [10/Oct/2018:10:24:56 +0800] "GET /

2018.10.2浪在ACM 集训队第二次测试赛

2018.10.26 浪在ACM 集训队第二次测试赛 题目一览表(Green color indicate understand and Accept) 来源 考察知识点 完成时间 A 1273 海港(比赛过题) NOIP 普及组 2016 查分数组+二分 2018.10.26 D 1272 回问日期(比赛过题) NOIP 普及组 2016 思维? 2018.10.26 G 1268 扫雷游戏(比赛过题) NOIP 普及组 2015 暴力 or DFS 2018.10.26          

it&#39;s time to change myself now (2018.10.31)

自16年从新屋熊职校毕业,入职深圳某厂从事云存储两年半了.两年半的时间很快,快的感觉一生都会飞快,两年多一直很忙,忙的几乎忘了自己是否正向改变过. 正向改变,or 积极改变,今年十一回家,与几个好友小聚,开怀畅聊,聊了过去与未来:突然觉得,在公司在岗位上,自己停止不前浑然不知,抽身之后,方被自己的状态震惊到. 从这几个方面: 工作:cs出身,从事云存储,美且名曰分布式存储,而我接触到的业务,非分布式,非传统存储,仅仅是对kv存储以lun或者说卷的管理这个层面.那么问题来了,这个层面究竟有多高的价

【谜客帝国】第139届微雨潇潇联想专场(2018.10.15)

[谜客帝国]第139届微雨潇潇联想专场(2018.10.15) 主持:瓷   计分:小白 1.本季重逢在帝国  只身东海挟春雷 乐天曲江之感怀 一段新愁染眉弯 5 今秋复来此 2.寒蛩轻唱送微凉  萧萧梧叶诉离情 白帝有语怜高洁 夜夜龙泉壁上鸣 4 此秋声也 3.人至中年心淡然  我言此季胜春潮 春愁夏恨冬烦忧 吟风作赋只伤春 4 不是悲秋 4.菊残犹有傲霜枝  立冬尚见黄叶飞 子夜歌里玉关情 竞雄洒血化碧涛 5 秋风吹不尽 5.轻寒最是可人天  貂裘换酒也堪豪 姑苏城外寒山寺 斋中结社咏海棠 

【谜客帝国】第140届兰萱联想专场(2018.10.30)

 [谜客帝国]第140届兰萱联想专场(2018.10.30) 主持:瓷   计分:默沫 1.沧海桑田.抱布贸丝.金兵撼山.吹灰之力(一字)易 2.云长拒豪宅.逃出囹圄来.红杏春意闹.破门阖又开(三字)关不住 3.浅尝辄止.滑稽出演.少年之行.不大喝茶(二字)小品 4.余高阳之苗裔兮.滕王阁主今何在.董卓废之立新君.古诗有云君不见(二字)少帝 5.匈奴鲜卑并川渝.顽皮妖宝憨态掬.因何前倨后恭也.似闻主动点炮语(二字)胡巴 6.正是阿堵物.三强皆出色.一掷千金者.实乃囊羞涩(三字)不差钱 7.上书帝

内置函数-max、min、round、sorted、ord、chr、any、all、dir、eval、exec、map、filter

http://www.nnzhp.cn/archives/152 1.max,min,round 1 print(max([3,4.563,3,6,2.5])) #取最大值,可循环参数即可,int类型的,字符串类型不行 2 print(min(9,4,7,1,0)) #取最小值 3 print(round(3.43535345,2)) #取即为小数,四舍五入 4 print(round(1.12345,2)) 2.sorted 1 s = '235434125636234' 2 res = so