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

python try catch

try:
  seq = int(seq)
  if seq < 0:
    print "Error"
except (TypeError, ValueError):
  print "Error"

ÔÚÕâÀïÎÒÏë°Ñ seq Ö»ÒªÊDz»´óÓÚµÈÓÚ0µÄ¶¼Å×Òì³£ ¿ÉÒÔÂð£¿
ÁíÍâassert Å׳öµÄÒì³£ except ºÃÏñ½Ø»ñ²»µ½°¡
except ºóÃæ²»Òª¼ÓÀ¨ºÅ.

Ö±½ÓÕâÑùÊÔ

try:
    raise TypeError, "Catch it"
except TypeError, e
    print "catch!"




except (TypeError, ValueError)µ±È»ÊDz»ÄܽػñassertÓï¾äÅ׳öµÄAssertionError£¬µÃ°ÑËü¼ÓÈëÀ¨ºÅÀï...

raise ¾Í¿ÉÒÔÁË

Python code:

try:
seq = int(seq)
except TypeError:
print "Error"
if seq < 0:
raise ValNotRight



Python code:

class ValNotRight(Exception):
pass





Ïà¹ØÎÊ´ð£º

python Òì³£Í˳ö

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

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

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

PythonÖеÄUnicodeÔÚDelphiÈçºÎ»¹Ô­³ÉGb2312£¿

ÒÑÖªPython ÖУº
s = unicode("²âÊÔ", "gb2312")
s = u'\u6d4b\u8bd5'
print s
²âÊÔ

ÔÚDelphiÀïÃæÈçºÎ½«\u6d4b\u8bd5ÕâÑùµÄ»¹Ô­³ÉGb2312µÄºº×ÖÄØ£¿
ÕÒµ½¸ö·½·¨
......

pythonÕýÔò±í´ïʽ ÈçºÎÈ¡³öÒÔÏÂ×Ö·û´® ¶àл

s='aaa111aaa,bbb222,333ccc,444ddd444,555eee666,fff777ggg'
ÓÃÕýÔò±í´ïʽȡ³ö Ç°ºó×ÖĸÏàͬµÄÊý¾Ý ½á¹ûÈçÏÂ:
111 ddd
лл~
Python code:

import re
s='aaa111aaa,bbb222,333ccc,444ddd444,555eee666,ff ......

³ÏÕÐPython³ÌÐòÔ±²ÎÓë¼ÆËã»úÊé¼®³ö°æ

ÓźñµÄ¸å³ê£¬³ÏÕÐPython¼¼ÊõÈËÔ±²ÎÓë¸÷ÖÖ¼¼ÊõÊé¼®³ö°æ¡£ 
ͨ¹ý¸ÃÊé¼®£¬×÷Õß¿ÉÒԵõ½Èçϱ¨³ê£º 
1¡¢·áºñµÄ¸å³ê¡£ 
2¡¢Êé¼®Öø×÷µÄÊðÃûȨ¡£ 
3¡¢¶Ô×÷ÕߺÍÊé½øÐÐÐû´«£¬Ìá¸ß×÷ÕßÔÚ¼¼ÊõȦ×ÓÀ ......

Çë½Ì¸ßÊÖ¹ØÓÚpython¿ª·¢webµÄÎÊÌâ¡£

ÇëÎʸßÊÖ£¬ÈçºÎÓÃpython¿ª·¢webʱ£¬²»ÓÃcssÑùʽ±íÖ±½ÓÓÃpythonÓïÑÔʵÏÖÍøÕ¾Ò³ÃæЧ¹ûÔÚ800*600¡¢1200*1600¡¢1024*768µÈÏÔʾ·Ö±æÂʵÄÏÔʾÆ÷ÉÏÕý³£ÏÔʾÄØ£¿£¿
²»Ã÷°×ÄãÒª×öʲô...

1. web¿ª·¢, ʼÖÕ´«Ë͹ýÀ´, ä ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ