• python帮助信息查看以及笔记


    如何获取使用帮助:

      获取对象支持使用的属性和方法:dir()    

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

    代码实例:

     1 >>> dir()
     2 ['__builtins__', '__doc__', '__name__', '__package__']
     3 >>> import struct
     4 >>> dir()
     5 ['__builtins__', '__doc__', '__name__', '__package__', 'struct']
     6 >>> dir(struct)
     7 ['Struct', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_clearcache', 'calcsize', 'error', 'pack', 'pack_into', 'unpack', 'unpack_from']
     8 >>> class Person(object):
     9 ...     def __dir__(self):
    10 ...             return ["name", "age", "country"]
    11 ...
    12 >>> dir(Person)
    13 ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__','__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']
    14 >>> tom = Person()
    15 >>> dir(tom)
    16 ['age', 'country', 'name']

      某方法的具体使用帮助:help(list.pop)

      获取可调用对象的文档字串:print obj.__doc__

    #pydoc raw_input

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

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

    argv 是所谓的“参数变量(argument variable)”,是一个非常标准的编程术语。在其他的编程语言里你也可以看到它。这个变量包含了你传递给 Python 的参数。

    from sys import argv 
    script, first, second, third = argv 
    print "The script is called:", script 
    print "Your first variable is:", first 
    print "Your second variable is:", second 
    print "Your third variable is:", third

    #python argv.py argvtest wjoyxt1 wjoyxt2 wjoyxt3
    -----------------------------------

  • 相关阅读:
    asp.net mvc 两级分类联动方法示例
    动手实践虚拟网络
    KVM 网络虚拟化基础
    LVM 类型的 Storage Pool
    KVM 存储虚拟化
    CPU 和内存虚拟化原理
    远程管理 KVM 虚机
    启动第一个 KVM 虚机
    准备 KVM 实验环境
    虚拟化
  • 原文地址:https://www.cnblogs.com/wjoyxt/p/4988303.html
Copyright © 2020-2023  润新知