笨辦法學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)

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM