## Python-习题11~15 原

_Somuns

``````print "How old are you?",
age = raw_input()
print "How tall are you?",
height = raw_input()
print "How much do you weight?",
weight = raw_input()

print "So,you're %r old,%rtall and %r heavy." %(
age,height,weight)
``````

``````How old are you? 35
How tall are you? 6'2''
how much do you weight? 180lb
So,you're '35' old,"6'2''"tall and '180lb' heavy.``````

1.  raw_input 不管用户输入什么类型的都会转变成字符型

2.  另：input会根据用户输入变换相应的类型，而且如果要输入字符和字符串的时候必须要用引号包起来。

3.  自己再写一段类似格式的：

``````print "How many times did you go to the park?",
times = raw_input()
print "How often do you go home a week?",
fluence = raw_input()
print "What food is you favorite?",
food = raw_input()

print """So, you went the park %r times,go home %r times a week,
like %r very much."""%(times,fluence,food)
``````

``````How many times did you go to the park? 4
How often do you go home a week? 3
What food is you favorite? fish
So, you went the park '4' times,go home '3' times a week,
like 'fish' very much.``````

``y = raw_input("Name?")   # Name？ 起到了提示别人的作用``

``````age = raw_input("How old are you? ")
height = raw_input("How tall are you?")
weight = raw_input("How much do you weight?")

print "So you're %r old, %r tall and %r heavy."%(
age,height,weight)
``````

``````How old are you? 35
How tall are you?6'2''
How much do you weight?180lb
So you're '35' old, "6'2''" tall and '180lb' heavy.``````

1.  在Linux中的命令行输入pydoc raw_input   的结果是

2.  pydoc 命令是文档生成工具：

``````python -m pydoc raw_input

S C:\Documents and Settings\jdu> python -m pydoc
pydoc - the Python documentation tool

pydoc.py <name> ...
Show text documentation on something. <name> may be the name of a
Python keyword, topic, function, module, or package, or a dotted
reference to a class or function within a module or module in a
package. If <name> contains a '\', it is used as the path to a
Python source file to document. If name is 'keywords', 'topics',
or 'modules', a listing of these things is displayed.

pydoc.py -k <keyword>
Search for a keyword in the synopsis lines of all available modules.

pydoc.py -p <port>
Start an HTTP server on the given port on the local machine.

pydoc.py -g
Pop up a graphical interface for finding and serving documentation.

pydoc.py -w <name> ...
Write out the HTML documentation for a module to a file in the current
directory. If <name> contains a '\', it is treated as a filename; if
it names a directory, documentation is written for all the contents.

PS C:\Documents and Settings\jdu>
``````

``````#!/usr/bin/python
"""Show off features of [pydoc] module
This is a silly module to
demonstrate docstrings
"""
__author__ = 'David Mertz'
__version__= '1.0'
__nonsense__ = 'jabberwocky'
class MyClass:
"""Demonstrate class docstrings"""
def __init__ (self, spam=1, eggs=2):
"""Set default attribute values only
Keyword arguments:
spam ― a processed meat product
eggs ― a fine breakfast for lumberjacks
"""
self.spam = spam
self.eggs = eggs``````

pydoc 模块利用了 Python 文档的约定，又使用了一些有关 Python 导入、继承和其它类似的实用知识。此外， pydoc 有绝对的天赋可以使自己在不同的操作模式下被使用（马上就能看到更多有关这个论点的资料）。让我们用一些时间，看看通过 OS 命令行调用的 manpage 风格的用法。

``````% pydoc.py mymod
Python Library Documentation: module mymod
NAME
mymod - Show off features of [pydoc] module
FILE
/articles/scratch/cp18/mymod.py
DESCRIPTION
This is a silly module to
demonstrate docstrings
CLASSES
MyClass
class MyClass
| Demonstrate class docstrings
|
| __init__(self, spam=1, eggs=2)
| Set default attribute values only
|
| Keyword arguments:
| spam ― a processed meat product
| eggs ― a fine breakfast for lumberjacks
DATA
__author__ = 'David Mertz'
__file__ = './mymod.pyc'
__name__ = 'mymod'
__nonsense__ = 'jabberwocky'
__version__ = '1.0'
VERSION
1.0
AUTHOR
David Mertz``````

``````% cat mymod2.py
from mymod import MyClass
class MyClass2(MyClass):
"""Child class"""
def foo(self):
pass
% pydoc.py mymod2.MyClass2
Python Library Documentation: class MyClass2 in mymod2
class MyClass2(mymod.MyClass)
| Child class
|
| __init__(self, spam=1, eggs=2) from mymod.MyClass
|
| foo(self)``````

``````% pydoc.py -k uuencode
uu - Implementation of the UUencode and UUdecode functions.
% pydoc.py uu
Python Library Documentation: module uu
NAME
uu - Implementation of the UUencode and UUdecode functions.
[...]``````

pydoc 除了它的命令行用法之外，还有其它四种“模式”可以显示被生成的同样的文档。

Shell 模式：在 Python 交互式 shell 中，您可以导入 pydoc 的 help() 函数，这样就能够在不离开交互式会话的情况下获得任何对象的帮助。也可以只输入一个 help 进入交互式“help 解释器”。例如：

清单 5：shell 模式下的交互式 help 解释器

`````` #------- Interactive shell with help enhancements ------#
>>> from pydoc import help
>>> import uu
>>> help(uu.test)
Help on function test in module uu:
test()
uuencode/uudecode main program
>>> help
help>
``````

Web 服务器模式：仅使用 -p 选项， pydoc 就会在 LOCALHOST 上作为一个简单的 Web 服务器自启动。您可以使用任何 Web 浏览器浏览所有已安装在现有操作系统上的模块。这个服务器的主页是一张模块列表，根据目录（并用浏览器支持的醒目色块）将它们分组。此外，您查看其文档的每个模块也广泛分布着它导入的函数、方法以及指向任何模块的链接。
HTML 生成器模式： -w 选项对于 pydoc 可以归档的任何文档都能生成 HTML 文档页面。这些页面与您在 Web 服务器模式下可能会浏览到的页面本质上是一回事，但页面是静态的，可以进行存档、传输等等。
TK 浏览器模式： -g 选项将创建一个和 xman 或 tkman 风格很相似的“图形帮助浏览器。”

http://www.ibm.com/developerworks/cn/linux/sdk/python/charm-19/

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

4.  使用pydoc 再看一下open，file，os，和sys的含义，通读了解。

``````from sys import argv

script,first,second,third=argv

print "The script is called:",script
``````

``````\$ python ex13.py first 2nd 3rd
The script is called: ex13.py
``````

``````from sys import argv
script,user_name = argv
prompt = '>'

print "Hi %s,I'm the %s script." %(user_name,script)
print "I'd like to ask you a few questions."
print "Do you like me %s?" % user_name
like = raw_input(prompt)

print "Where do you live %s?" % user_name
lives = raw_input(prompt)

print """
Alright,so you said %r about liking me.
You live in %r. Not sure where that is.
And you have a %r computer. Nice.
"""%(likes,lives,computer)
``````

### _Somuns

【书坊11月赠书福利——第二期】《“笨办法”学Python》 （第3版）

2014/11/18
298
0
Python第四课----函数

2018/06/26
0
0

Hello World！不少人都与这句话邂逅在大家最初学习编程的时候。 2014年12月的编程语言排行榜中，Python位列在众多语言中的第8位，一直保持在前列。初学者看着简单清晰的语言极其容易上手。即...

2014/12/26
1K
4
python核心编程-第五章-习题

1.长整型表示数的范围比整型更大。在python中，整型、长整型趋于统一，普通用户不用特别关注两者区别，仅当需引用C语言时需要特别注意。 2.操作符 (a) def multiply(x,y): return x * y (b) ...

2015/11/18
76
0
《python 核心编程》第15章正则表达式 答案

2013/05/12
617
1

var params = {};testParan.split(',').forEach(item =>{ var tmpArr = item.split('='); Vue.set(params, tmpArr[0].trim(), tmpArr[1].trim());});Vue.set(params, 'sql', sql);......

25分钟前
4
0

分立器件被广泛应用到消费电子、计算机及外设、网络通信，汽车电子、led显示屏等领域。 　　半导体产业中有两大分支：集成电路和分立器件。 　　集成电路 　　集成电路（integrated circ...

35分钟前
5
0
kibana rpm安装

38分钟前
3
0

39分钟前
4
0

SuspendThread()：挂起线程 If the function succeeds, the return value is the thread's previous suspend count; otherwise, it is (DWORD) -1. ResumeThread()：启动线程 If the functio......

rainbowcode
39分钟前
5
0