Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Ë­Óùýpython µÄmock ×öunit test

Èç¹ûÒ»¶Î´úÂë

Python code:

#!/usr/bin/python2.5

from urllib2 import Request,urlopen,URLError

def check():
req = Request('http://www.google.com')
try:
res = urlopen(req).read()
return res
except URLError, e:
if hasattr(e, 'reason'):
return('We failed to reach the server. Reason: %s' % e.reason)
elif hasattr(e, 'code'):
return('The server couldn\'t fulfill the request. Error code: %s' %
e.code)

if __name__ == '__main__':
print check()



ÏÖÔÚÎÒÒª×öunit test ÎÒÔõôÑùÄÜÓÃmock À´×öһЩģÄâµÄ·ÃÎÊÍøÂç¼°Òì³£´¦Àí£¿

ÓÑÇé°ï¶¥

moke ÄÜ×öʲô?ÄÜÔÚ¿Í»§¶ËÖ´ÐÐjsÂð?



End_rbody_60020883//-->
¸Ã»Ø¸´ÓÚ2009-09-25 10:49:51±»¹ÜÀíԱɾ³ý



¶ÔÎÒÓÐÓÃ[0]
¶ª¸ö°åש[0]
ÒýÓÃ
¾Ù±¨
¹ÜÀí
TOP








Ïà¹ØÎÊ´ð£º

python Òì³£Í˳ö

×î½üÓÃpythonдһ¸ö³ÌÐò,×ÜÊÇÒì³£Í˳ö£¬µ«ÊÇȴû·¨ÓÃtry..exceptÀ´²¶×½

ÓÉÓÚû·¨·¢Í¼Æ¬£¬ËùÒÔ°ÑÏà¹ØµÄÐÅÏ¢´òÓ¡³öÀ´
Òì³£µÄÐÅÏ¢´óÖÂÈçÏ£º

python.exeÓöµ½ÎÊÌâÐèÒª¹Ø±Õ¡£ÎÒÃǶԴËÒýÆðµÄ²»±ã±íʾ±§Ç¸ ......

pythonÖÐÏß³ÌÎÊÌ⣿£¿

ÎÒÏÖÔÚÊÇÕâÑùµÄ
¿ªÁËÒ»¸ö×ÓỊ̈߳¬¶ÁÈ¡ÏÂÃæµÄÏûÏ¢
±¾ÒâÊÇ
Python code:

while not self._stopevent.isSet( ):
re=¶ÁȡϲãÏûÏ¢
if re>0:
´¦Àí
else:
pass

¼ÙÈ ......

ÇóÖú£ºpython¶ÁÈ¡mp3µÄid3±êÇ©ÐÅÏ¢ÎÊÌâ

ÎÒµÄmp3±êÇ©ÐÅÏ¢ÊÇͨ¹ýTag&Rename Èí¼þÀ´Ð޸ĵÄ
Ð޸ĵÄÐÅÏ¢ÈçÏÂ
Album Title ISRC
77 66 99

---python¶ÁÈ¡mp3µÄid3µÄ´úÂë----

from mutagen.mp3 import MP3
import mutagen.id3
......

ÇëÎÊpythonºÍpyodcÓÐÊ²Ã´Çø±ð

Âé·³¸ßÊÖ½â´ðһϠллÁË ÎÒÊÇÐÂÊÖ Ò»Ð©¸ÅÄî¶¼²»Ì«Çå³þ¡£¡£¡£
pyodbc is a Python module that allows you to use ODBC to connect to almost any database from Windows, Linux, OS/X, and more.

pyodbcÊÇ ......

µÚÒ»´ÎÓÃPythonд³ÌÐò£¬Ê¹ÓÃfindº¯ÊýÓöµ½Ò»¸öÎÊÌâ

//ÏÂÃæµÄ´úÂëÔËÐÐÕý³£

tomstrs=re.findall(......)
mtxx=''
for tomstr in tomstrs:
  tomstr=tomstr.strip()
  if  tomstr:
      mtxx += tomstr ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ