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

Python 中文字符串的截取

def
subString
(s,
length):
   
us = unicode(s, 'utf-8
')
    gs =
us.encode('gb2312
')
    n = int(length)
   
t = gs[:n]
    while True
:
        try
:
            unicode(t, 'gbk
')
            break
       
except
:
            n -= 1
           
t = gs[:n]
    return
t.decode('gb2312
')


相关文档:

Python Get Key press

refer from:  http://www.daniweb.com/forums/thread115282.html#
python
Syntax
(Toggle Plain Text
)

# respond to a key
without the need to press
enter
 
import
Tkinter
as tk
 
def
keypress(
event)
:
if
event.keysym
== 'Escape'
:
root.destroy
......

Python、Unicode和中文[转]


关键字: python
Python、Unicode和中文[转] 
python的中文问题一直是困扰新手的头疼问题,这篇文章将给你详细地讲解一下这方面的知识。当然,几乎可以确定的是,在将来的版本中,python会彻底解决此问题,不用我们这么麻烦了。 
先来看看python的版本: 
>>> import sys 
>> ......

python读取目录下文件并生成日志

很长的一段代码,但很清楚。哈哈。
import os
from time import strftime
stamp=strftime("%Y-%m-%d %H:%M:%S")
logfile = 'F:\\test\\m-php-framework\\tmp\logs\\error_report.log'
path = 'F:\\test\\'
files = os.listdir(path)
bytes = 0
numfiles = 0
for f in files:
if f.startswith('t'): ......

Python MySQLdb 查询返回字典结构


Python MySQLdb 查询返回字典结构 smallfish
MySQLdb默认查询结果都是返回tuple,输出时候不是很方便,必须按照0,1这样读取,无意中在网上找到简单的修改方法,就是传递一个cursors.DictCursor就行。
默认程序:
import MySQLdb
db = MySQLdb.connect(host = 'localhost', user = 'root', passwd = '123456', d ......

Python 八荣八耻

http://www.okpython.com/bbs/thread-3367-1-2.html
以动手实践为荣 , 以只看不练为耻;
以打印日志为荣 , 以单步跟踪为耻;
以空格缩进为荣 , 以制表缩进为耻;
以单元测试为荣 , 以人工测试为耻;
以模块复用为荣 , 以复制粘贴为耻;
以多态应用为荣 , 以分支判断为耻;
以Pythonic为荣 , 以冗余拖沓为耻;
以总结分享为 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号