zoukankan      html  css  js  c++  java
  • mask-rcnn代码解读(七):display(self)函数的解析

    如和将class中定义的变量打印或读取出来,受maskrcnn的config.py的启示,我将对该函数进行解释。

    我将介绍该函数前,需要对一些名词进行解释,如下:

    ①Ipython:ipython是一个python的交互式shell,比默认的python shell好用得多,支持变量自动补全,自动缩进,支持bash shell命令,内置了许多很有用的功能和函数。学习ipython将会让我们以一种更高的效率来使用python。同时它也是利用Python进行科学计算和交互可视化的一个最佳的平台。

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

     

    ③.startswith():此函数判断一个文本是否以某个或几个字符开始,结果以True或者False返回。

    text='welcome to qttc blog'
    print text.startswith('w')      # True
    print text.startswith('wel')    # True
    print text.startswith('c')      # False
    print text.startswith('')       # True

    顺道介绍endswith():此函数判断一个文本是否以某个或几个字符结束,结果以True或者False返回。

    text='welcome to qttc blog'
    print text.endswith('g')        # True
    print text.endswith('go')       # False
    print text.endswith('og')       # True
    print text.endswith('')         # True
    print text.endswith('g ')       # False

    ④getattr(self, a):返回一个对象属性值,即变量的值

    def display(self):
    """Display Configuration values."""
    print(" Configurations:")
    for a in dir(self): # dir() 函数不带参数时,返回当前范围内的变量、方法和定义的类型列表;带参数时,返回参数的属性、方法列表
    if not a.startswith("__") and not callable(getattr(self, a)): # getattr() 函数用于返回一个对象属性值
    print("{:30} {}".format(a, getattr(self, a)))
    print(" ")

    在maskrcnn中,执行此代码运行结果为:





  • 相关阅读:
    bzoj_auto_submiter(辣鸡Py毁我青春系列)
    听说“辣鸡小隔膜”出V1.3了?
    shell脚本:统计分析 /home/ 目录用户磁盘使用情况
    shell脚本:DNS自检脚本
    Linux命令集锦:ssh命令
    Linux用户权限
    Linux文件属性
    Linux命令集锦:chown命令
    Linux命令集锦:chmod命令
    Linux命令集锦:tmux命令
  • 原文地址:https://www.cnblogs.com/tangjunjun/p/12057510.html
Copyright © 2011-2022 走看看