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 a ......
“¹þ¹þ£¡ÖªµÀÎÒ²Ù×÷Ö®ÍõС°×µÄÀ÷º¦ÁË°É£¡”
ÿµ±ÖÜÁùÍíÉÏ£¬Ð¡°××ÜÊÇÒª¸úËÞÉáµÄµÜÐÖÌô¼¸¾ÖħÊÞ¡£Æ¾½è×Å·çɧµÄ×ßλºÍâ«ËöµÄÒâʶ£¬Ð¡°××ÜÊÇЦµÀ×îºó¡£Õâ²»£¬Ð¡°×ÓÖÒ»´ÎÈ¡µÃÁËÒÔÒ»µÐ¶þµÄʤÀû¡£
“Ö÷ÒªÊǶàÏß²Ù×÷£¡”ÕâÊÇС°×¶Ô×Ô¼ºÊ¤ÀûµÄ×ܽᡣ
½ñÌìÎÒÃǾÍҪѧϰ¶àỊ̈߳¬¿´¿´Ð¡°×ÊÇÔõÑùʤÀûµÄ¡£
Ê×ÏÈÎÒÃÇÒª³ÎÇåµÄÊÇPythonµÄ¶àÏ̲߳¢²»ÊÇÀûÓÃϵͳ±¾ÉíµÄ¶àÏ̻߳úÖÆ£¬¶øÊÇ»ùÓÚPython½âÊÍÆ÷£¬Êµ¼ÊÔÚϵͳ¿´À´»¹ÊÇÒ»¸öÏ̡߳£ÔÚPythonÖУ¬´æÔÚÒ»¸öGlobal Interpreter Lock(GIL)£¬¼´È«¾Ö½âÊÍÆ÷Ëø£¬ËüµÄ×÷ÓÃÔÚÓÚÈÃͬһʱ¿ÌÖ»ÄÜÓÐÒ»¸öÏ̶߳ÔÓÚpython¶ÔÏó½øÐвÙ×÷¡£ËùÒÔPythonµÄ¶àÏß³ÌÎÞ·¨³ä·ÖÀûÓöàºËCPU£¬ÉõÖÁµ¥ºËCPU£¬Õâ¿ÉÒÔ˵ÊǽâÊÍÓïÑÔµÄͨ²¡¡£ÓÐʱ¿ÉÒÔͨ¹ý´´½¨¶à¸ö½ø³Ì£¨¶ø²»ÊÇỊ̈߳©£¬»òÕßʹÓÃJython°æ±¾À´½â¾ö¡£
¶àÏ̴߳øÀ´µÄȱµã£º1¡¢´úÂë±àдÄѶȼӴ󣬶àÏß³ÌÖ®¼äµÄÇÀÕ¼ÈÝÒײúÉú´íÎ󣬳öÏÖÒì³££»2¡¢Ïß³ÌÖ®¼äµÄÇл»Í¬Ñù»á¼Ó´óCPUºÍÄÚ´æµÄ¸ºµ£¡£
ÎÞÂÛÈçºÎ£¬¶àÏ̻߳¹ÊÇÖµµÃһѧµÄ£¬ÒòΪËüÓÐÒ»¸ö²»¿ÉºöÊÓµÄÓŵ㣺ִÐÐËٶȿ죬ÇмDz»Ä ......
³¬Èº.comµÄ²©¿Í
Pythonת»»office wordÎļþΪHTML
ÕâÀï²âÊԵĻ·¾³ÊÇ£ºwindows xp,office 2007,python 2.5.2,pywin32 build
213£¬ÔÀíÊÇÀûÓÃwin32com½Ó¿ÚÖ±½Óµ÷ÓÃoffice
API£¬ºÃ´¦ÊǼòµ¥¡¢¼æÈÝÐԺã¬Ö»ÒªofficeÄÜ´¦ÀíµÄ£¬python¶¼¿ÉÒÔ´¦Àí£¬´¦Àí³öÀ´µÄ½á¹ûºÍoffice wordÀïÃæ“Áí´æΪ”Ò»Ö¡£
#!/usr/bin/env python
#coding=utf-8
from
win32com import
client as
wc
word = wc.Dispatch
(
'Word.Application'
)
doc = word.Documents
.Open
(
'd:/labs/math.doc'
)
doc.SaveAs
(
'd:/labs/math.html'
, 8
)
doc.Close
(
)
word.Quit
(
)
¹Ø¼üµÄ¾ÍÊÇdoc.SaveAs(‘d:/labs/math.html’,
8)ÕâÒ»ÐУ¬ÍøÉϺܶàÎÄÕÂд³É£ºdoc.SaveAs(‘d:/labs/math.html’,
win32com.client.constants.wdFormatHTML)£¬Ö±½Ó±¨´í£º
AttributeError: class Constants has no attribute ‘wdFormatHTML’
µ±È»ÄãÒ²¿ÉÒÔÓÃÉÏÃæµÄ´úÂ뽫wordÎļþת»»³ÉÈÎÒâ¸ñʽÎļþ£¨Ö»Òªoffice 2007Ö§³Ö£¬±ÈÈ罫wordÎļþת»»³ÉPDFÎļþ£¬°Ñ8¸Ä³É17¼´¿É£©£¬ÏÂÃæÊÇoffice 2007Ö§³ ......
ÎÊÌâÃèÊö£º¼ÙÉèÎÒÓÐÕâÑùÁ½¸ölist£¬
Ò»¸öÊÇlist1£¬list1 = [1, 2, 3, 4, 5]
Ò»¸öÊÇlist2£¬list2 = [1, 4, 5]
ÎÒÃÇÈçºÎµÃµ½Ò»¸öеÄlist£¬list3£¬
list3ÖаüÀ¨ËùÓв»ÔÚlist2ÖгöÏÖµÄlist1ÖеÄÔªËØ¡£
¼´£ºlist3 = list1 - list2
½â¾ö·½°¸£ºÎÒÃÇ¿ÉÒÔÓÃset£¨¼¯ºÏ£©²Ù×÷
list3 = list(set(list1) - set(list2))
set²Ù×÷»á½«Ò»¸ölistת»»³ÉÒ»¸ö¼¯ºÏ¡£
¼ÙÉ裺list_t = [1, 2, 3, 1]
ÄÇô£ºlist(set(list_ ......
http://www.okpython.com/bbs/thread-3367-1-2.html
ÒÔ¶¯ÊÖʵ¼ùΪÈÙ , ÒÔÖ»¿´²»Á·Îª³Ü;
ÒÔ´òÓ¡ÈÕ־ΪÈÙ , ÒÔµ¥²½¸ú×ÙΪ³Ü;
ÒÔ¿Õ¸ñËõ½øΪÈÙ , ÒÔÖƱíËõ½øΪ³Ü;
ÒÔµ¥Ôª²âÊÔΪÈÙ , ÒÔÈ˹¤²âÊÔΪ³Ü;
ÒÔÄ£¿é¸´ÓÃΪÈÙ , ÒÔ¸´ÖÆÕ³ÌùΪ³Ü;
ÒÔ¶à̬ӦÓÃΪÈÙ , ÒÔ·ÖÖ§ÅжÏΪ³Ü;
ÒÔPythonicΪÈÙ , ÒÔÈßÓàÍÏí³Îª³Ü;
ÒÔ×ܽá·ÖÏíΪÈÙ , ÒÔ¹òÇóÆä½âΪ³Ü;
......
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
') ......