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

python 模块的__name__ __main__

每个模块都有一个名称,在模块中可以通过语句来找出模块的名称。这在一个场合特别有用
——就如前面所提到的,当一个模块被第一次输入的时候,这个模块的主块将被运行。
每个Python模块都有它的__name__,如果它是'__main__',这说明这个模块被用户单独运行,
我们可以进行相应的恰当操作。
#!/usr/bin/python
# Filename: using_name.py
if __name__ == '__main__':
     print 'This program is being run by itself'
else:
     print 'I am being imported from another module'
输出
$ python using_name.py
This program is being run by itself
$ python
>>> import using_name
I am being imported from another module


相关文档:

Python字符串操作[转]


Python字符串操作
python如何判断一个字符串只包含数字字符 
python 字符串比较 
下面列出了常用的python实现的字符串操作
1.复制字符串
#strcpy(sStr1,sStr2)
sStr1 = 'strcpy'
sStr2 = sStr1
sStr1 = 'strcpy2'
print sStr2
2.连接字符串
#strcat(sStr1,sStr2)
sStr1 = 'strcat'
sStr2 = 'appen ......

python发邮件的代码

# -*- coding: cp936 -*-
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
import smtplib
 
#创建一个带附件的实例
msg = MIMEMultipart()
#构造附件
att = MIMEText(open('e:\\test.txt').read(), 'base64', 'gb2312')
att["Content-Type"] = 'application/ ......

Eclipse基于python、Django做Web开发

 先将上面创建好的testdemo工程目录\,将C:\Python25\Lib\site-packages\django\bin中的testdemo目录拷贝到自己的工作目录中,然后启动eclipse,点击“File”->“New”->“project…”,将会看到以下画面
 
选择“Pydev Project”,点击“Next&rdquo ......

Python之HTMLParser

"""A parser for HTML and XHTML."""
# This file is based on sgmllib.py, but the API is slightly different.
# XXX There should be a way to distinguish between PCDATA (parsed
# character data -- the normal case), RCDATA (replaceable character
# data -- only char and entity references and end tags a ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号