zoukankan      html  css  js  c++  java
  • 笨办法学Python记录--习题12-14 主要是pydoc用法,raw_input,argv

    20140413 -- 习题12 - 14 

    1. pydoc在windows的用法,必须进入到python安装目录,执行Python -m pydoc raw_input;

    网上给出了一个好玩的,不过只能查到文档级别:在命令行到pydoc所在的目录python的安装目录lib下,运行 python pydoc.py -p 8877 ,其中8877是随便能用的端口即可。之后在IE中打开“http://127.0.0.1:8877/ 你会有意外惊喜。

    查到的信息如下:

    raw_input(...)
    raw_input([prompt]) -> string

    Read a string from standard input. The trailing newline is stripped.
    If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.
    On Unix, GNU readline is used if enabled. The prompt string, if given,
    is printed without a trailing newline before reading.

    prompt译作提示,读取一个字符串,从标准输入中。紧接着是等待输入。如果用户使用了结束键,就抛出EOFError。在Unix,GNU被用到了,提示字符串事先被打印出来。

    PS C:Python27> python -m pydoc open
    Help on built-in function open in module __builtin__:

    open(...)
    open(name[, mode[, buffering]]) -> file object

    Open a file using the file() type, returns a file object. This is the
    preferred way to open a file. See file.__doc__ for further information.

    返回的是file对象。

    2. argv ---相当于shell中的$参数,用法如下:

    from sys import argv

    参数1,参数2 = argv #之后参数的饮用就和这个先后顺序有关了

    3. 配合raw_input使用argv效果不错,例如

    from sys import argv

    script,user_name = argv

    prompt = '>'

    print "My name is %s, and you know I am the %s script." %(user_name,script)

    print "do u like me?"

    like = raw_input(prompt)

    print "how old r u?"

    age = raw_input(prompt)

    print """

    OK, you said you %r me very much. you r %r years old.

    """ %(like,age)

  • 相关阅读:
    jsp中添加弹窗口并且实现向后台双向传递数据
    hql中or的用法(代替union)
    hql中in的用法
    spring中的定时任务调度用例
    JS如何将UTC格式时间转本地格式
    HttpSession与Hibernate中Session的区别
    adaptive hash index
    InnoDB Double write
    int(M)与int
    MySQL库目录下db.opt文件的作用
  • 原文地址:https://www.cnblogs.com/ianthe/p/3662391.html
Copyright © 2011-2022 走看看