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)

  • 相关阅读:
    electron之打包成安装程序
    electron之环境安装、启动程序
    微信支付.net官方坑太多,我们来精简
    微信支付官方.net版之坑你没商量
    程序员出路在何方
    简单介绍
    mac中显示隐藏文件
    sublime Text 3 安装emmet
    Andriod学习笔记5:通过NDK在C++中实现日志输出
    Andriod学习笔记4:mac下搭建 Eclipse+CDT 集成开发环境
  • 原文地址:https://www.cnblogs.com/ianthe/p/3662391.html
Copyright © 2011-2022 走看看