易截截图软件、单文件、免安装、纯绿色、仅160KB

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.


相关文档:

python中使用方便的LIST对象

最近对python产生了兴趣,于是从网上下载了基本PYTHON的书和文档,开始了PYTHON的学习,发现PYTHON中的list对象的功能实在是非常强大,编程起来比其他的程序语言对列表的操作要方便的多。
在python中定义一个列表只需要如下语句
li = ["a","b","c","d"]
list有许多的函数可以用来进行对列表的操作,如extend,append,inse ......

MoteLab:返回串口数据处理(python)

从MoteLab返回的串口数据,包含messages.pickle文件这是MoteLab系统中串口收集数据的总和,但是这些数据需要解析后才能进行分析。下面的代码就是在python环境下提取message有效数据的代码。
使用命令 python TestOutput.py messages.pickle
生成的test.log就是获得的有效数据
返回数据的示例
1252985727.66  recei ......

Python代码优化

Python代码优化--少打字小技巧
说明:增加代码的描述力,可以成倍减少你的LOC,做到简单,并且真切有力
观点:少打字=多思考+少出错,10代码行比50行更能让人明白,以下技巧有助于提高5倍工作效率
1. 交换变量值时避免使用临时变量:(cookbook1.1)
老代码:我们经常很熟练于下面的代码
temp = x
x = y
y = ......

Python模块学习

  StringIO的行为与file对象非常像,但它不是磁盘上文件,而是一个内存里的“文件”,我们可以将操作磁盘文件那样来操作StringIO。一个简单的例子,让你对StringIO有一个感性的认识: 1  #coding=gbk 2    3  import StringIO, cStringIO, sys 4    5  s ......

Python:FriendFeed的Tornado Web Server

代码很简单,不到5k行。但是思路挺好的,改成non-blocking了之后效率就是能提高不少,特别是考虑到现代的web app都需要和其他的
HTTP服务器通信,blocking的代价太大了。 Tornado is an open source version of the scalable, non-blocking web server and tools that power FriendFeed. The FriendFeed application ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号