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

python中如何判断一个变量的数据类型?(原创)

import types
type(x) is types.IntType # 判断是否int 类型
type(x) is types.StringType #是否string类型
.........
--------------------------------------------------------
超级恶心的模式,不用记住types.StringType
import types
type(x) == types(1) # 判断是否int 类型
type(x) == type('a') #是否string类型
------------------------------------------------------
使用内嵌函数:
isinstance
(
object, classinfo
)
Return true if the object
argument is an instance
of the classinfo
argument, or of a (direct or indirect)
subclass thereof. Also return true if classinfo
is a type
object and object
is an object of that type. If object
is not a class instance or an object of the given type, the function
always returns false. If classinfo
is neither a class
object nor a type object, it may be a tuple of class or type objects,
or may recursively contain other such tuples (other sequence types are
not accepted). If classinfo
is not a class, type, or
tuple of classes, types, and such tuples, a TypeError
exception is raised. Changed in version
2.2: Support for a tuple of type information was added.
Python可以得到一个对象的类型 ,利用type函数:
>>>lst = [1, 2, 3]
>>>type(lst)
<type 'list'>
不仅如此,还可以利用isinstance函数,来判断一个对象是否是一个已知的类型。
isinstance说明如下:
    isinstance(object, class-or-type-or-tuple) -> bool
   
    Return whether an object is an instance of a class or of a subclass
thereof.
    With a type as second argument, return whether that is the object's
type.
   
The form using a tuple, isinstance(x, (A, B, ...)), is a shortcut
for
    isinstance(x, A) or isinstance(x, B) or ... (etc.).
其第一个参数为对象,第二个为类型名或类型名的一个列表。其返回值为布尔型。若对象的类型与参数二的类


相关文档:

用Python提取文件夹下的特定扩展名的文件

                用Python提取文件夹下的特定扩展名的文件
      不知道什么时候,网闲着没用,挂了个linux的视屏教程,里面有很多个文件夹,有很多无关的文件。这对于像我没收藏垃圾文件癖好的人来说,简直是 ......

LINUX平台部署apache+mod_python+django


前一篇文章写的在APACHE安装MOD_PYTHON的经过,其实挺简单,就是版本不兼容的问题.这次我大概说下部署DJANGO的过程.
先修改APACHE配置文件,使其加载mod_python模块
LoadModule python_module libexec/mod_python.so
运行命令查看
bin/httpd -M可以看到
 python_module (shared)
Syntax OK
说明apache已经成功加 ......

Python正则表达式

正则表达式是个魔鬼,也是个天使。在你没有掌握它之前,它是魔鬼,在你掌握它后,它是天使,但是,时
不时还是要跳出来,给你调皮捣蛋一番。


一个正则表达式就是由普通字符以及特殊字符组成的文字模式,该模式描述在查找文字主体时待
匹配的一个或多个字符串。正则表达式作为一个模板,将某个字符模式与所搜索的 ......

python模块之codecs

python对多国语言的处理是支持的很好的,它可以处理现在任意编码的字符,这里深入的研究一下python对多种不同语言的处理。
    有一点需要清楚的是,当python要做编码转换的时候,会借助于内部的编码,转换过程是这样的:
        原有编码 -> 内部编码 ->
目 ......

Python MySQLdb 查询返回字典结构


Python MySQLdb 查询返回字典结构 smallfish
MySQLdb默认查询结果都是返回tuple,输出时候不是很方便,必须按照0,1这样读取,无意中在网上找到简单的修改方法,就是传递一个cursors.DictCursor就行。
默认程序:
import MySQLdb
db = MySQLdb.connect(host = 'localhost', user = 'root', passwd = '123456', d ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号