Python入门的36个例子 之 18
例1:
# _018
# This is a module (if write Chinese in a module, there will be a error)
def func1():
print 'This is function 1.'
def func2():
print 'This is function 2.'
def func3():
print 'This is function 3.'
# 019
# 使用“import”语句调用模块:
import _018_Module
_018_Module.func1()
_018_Module.func2()
_018_Module.func3()
output:
This is function 1.
This is function 2.
This is function 3.
例2:
# _018
# This is a module (if write Chinese in a module, there will be a error)
def func1():
print 'This is function 1.'
def func2():
print 'This is function 2.'
def func3():
print 'This is function 3.'
# 020
# 使用“from ... import ...”语句调用模块
from _018_Module import func2
import _018_Module
_018_Module.func1()
func2()
_018_Module.func3()
output:
This is function 1.
This is function 2.
This is function 3.
例3:
# _018
# This is a module (if write Chinese in a module, there will be a error)
def func1():
print 'This is function 1.'
def func2():
print 'This is function 2.'
def func3():
print 'This is function 3.'
# 021
# 使用“from ... import *”语句调用模块
from _018_Module import *
func1()
func2()
func3()
output:
This is function 1.
This is function 2.
This is function 3.
相关文档:
import time,thread
def test(a,b):
for i in range(a,b):
time.sleep(1)
print i
def start():
thread.start_new_thread(test,(1,1001))
thread.start_new_thread(test,(1000,2001))
if __name__=='__main__':
start()
......
E-mail主要由邮件头和邮件体两部分组成。
邮件头中的内容和我们寄信时写在信封上的内容大同小意,当然这里也包含了很多路过的“邮局”的信息了。
邮件体中的内容就是我们写的信或者包裹。
python自身包含了email模块处理可以快速的处理E-mail中的信息
import email
#打开一个文件
fp = open('email.eml', ' ......
python使用SocketServers
SocketServers模块为一组socket服务类定义了一个基类,这组类压缩和隐藏了监听、接受和处理进入的socket连接的细节。
1、SocketServers家族
TCPServer和UDPServer都是SocketServer的子类,它们分别处理TCP和UDP信息。
注意:SocketServer也提供UnixStreamServer(TCPServer的子类)和UNIXdatag ......
# 004
# 利用三引号(''' or """)可以指示多行字符串
print '''line1
line2
line3'''
# 另外,你还可以在三引号中任意使用单引号和双引号
print ''' "What's up? ," he replied.'''
# 否则,你好使用转义符来实现同样的效果
# 还是使用三引号好,不然就破坏了视觉美了
print ' \"Wha ......
# 015
# 默认参数的本质是:
# 不论你是否提供给我这个参数,我都是要用它,
# 那么我就要想好在你不向我提供参数的时候我该使用什么。
# 或者,这样来理解:
# 有一些参数在一般情况下是约定俗成的,
# 但,在极少情况下会有一些很有个性的人会打破传统而按照自己的习惯来做事
def theFirstDayInAWeek(theDay = 'Sunda ......