python֮ǿ´óµÄÈÕ־ģ¿é¡¾×ª¡¿
1.¼òµ¥µÄ½«ÈÕÖ¾´òÓ¡µ½ÆÁÄ»
import
logging
logging.
debug(
'This is debug message'
)
logging.
info(
'This is info message'
)
logging.
warning(
'This is warning message'
)
ÆÁÄ»ÉÏ´òÓ¡:
WARNING:root:This is warning message
ĬÈÏÇé¿öÏ£¬logging½«ÈÕÖ¾´òÓ¡µ½ÆÁÄ»£¬ÈÕÖ¾¼¶±ðΪWARNING£»
ÈÕÖ¾¼¶±ð´óС¹ØÏµÎª£ºCRITICAL > ERROR > WARNING > INFO > DEBUG > NOTSET£¬µ±È»Ò²¿ÉÒÔ×Ô¼º¶¨ÒåÈÕÖ¾¼¶±ð¡£
2.ͨ¹ýlogging.basicConfigº¯Êý¶ÔÈÕÖ¾µÄÊä³ö¸ñʽ¼°·½Ê½×öÏà¹ØÅäÖÃ
import
logging
logging.
basicConfig(
level=
logging.
DEBUG,
format=
'%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s'
,
datefmt=
'%a, %d %b %Y %H:%M:%S'
,
filename=
'myapp.log'
,
filemode=
'w'
)
logging.
debug(
'This is debug message'
)
logging.
info(
'This is info message'
)
logging.
warning(
'This is warning message'
)
./myapp.logÎļþÖÐÄÚÈÝΪ:
Sun, 24 May 2009 21:48:54 demo2.py[line:11] DEBUG This is debug message
Sun, 24 May 2009 21:48:54 demo2.py[line:12] INFO This is info message
Sun, 24 May 2009 21:48:54 demo2.py[line:13] WARNING This is warning message
logging.basicConfigº¯Êý¸÷²ÎÊý:
filename: Ö¸¶¨ÈÕÖ¾ÎļþÃû
filemode: ºÍfileº¯ÊýÒâÒåÏàͬ£¬Ö¸¶¨ÈÕÖ¾ÎļþµÄ´ò¿ªÄ£Ê½£¬'w'»ò'a'
format: Ö¸¶¨Êä³öµÄ¸ñʽºÍÄÚÈÝ£¬format¿ÉÒÔÊä³öºÜ¶àÓÐÓÃÐÅÏ¢£¬ÈçÉÏÀýËùʾ:
%(levelno)s: ´òÓ¡ÈÕÖ¾¼¶±ðµÄÊýÖµ
%(levelname)s: ´òÓ¡ÈÕÖ
Ïà¹ØÎĵµ£º
#---------------------תתתתתתתתתתתתתתתתתתתתתתת-------------------------------------------#
Python×÷ΪһÖÖ¹¦ÄÜÇ¿´óÇÒͨÓõıà³ÌÓïÑÔ¶ø¹ãÊÜºÃÆÀ£¬Ëü¾ßÓзdz£ÇåÎúµÄÓï·¨ÌØµã£¬ÊÊÓÃÓÚ¶àÖÖ²Ù×÷ϵͳ£¬Ä¿Ç°ÔÚ¹ú¼ÊÉϷdz£Á÷ÐУ¬ÕýÔڵõ½Ô½À´Ô½¶àµÄÓ¦Óá£
¡¡¡¡ÏÂÃæ¾ÍÈÃÎÒÃÇÒ»ÆðÀ´¿´¿´ËüµÄÇ¿´ó ......
1. ´òÓ¡±äÁ¿ºÍ±äÁ¿×ÔÏÔ
>>> myString = 'Hello World!'
>>> print myString
Hello World!
>>> myString
'Hello World!'
ÒòΪ£º print Óï¾äµ÷ÓÃstr()º¯ÊýÏÔʾ¶ÔÏ󣬶ø½»»¥Ê½½âÊÍÆ÷Ôòµ÷ÓÃrepr()º¯ÊýÀ´ÏÔʾ¶ÔÏó
sys.stdout.write('hello')²»»áÔÚĩβ¼ÓÉÏ'\n'£¬¶øprint»á
2. ´òÓ¡Îļþ
hand ......
ÔÚ½²Êöfilter£¬mapºÍreduce֮ǰ£¬Ê×ÏȽéÉÜÒ»ÏÂÄäÃûº¯Êýlambda¡£
lambdaµÄʹÓ÷½·¨ÈçÏ£ºlambda [arg1[,arg2,arg3,...,argn]] : expression
ÀýÈ磺
>>> add = lambda x,y : x + y
>>> add ......
PythonµÄÃæÏò¶ÔÏóÐÔÖÊ
ÀàºÍ¶ÔÏóÊÇÃæÏò¶ÔÏó±à³ÌµÄÁ½¸öÖ÷Òª·½Ãæ¡£Àà´´½¨Ò»¸öÐÂÀàÐÍ£¬¶ø¶ÔÏóÕâ¸öÀàµÄ ʵÀý ¡£ÕâÀàËÆÓÚÄãÓÐÒ»¸öintÀàÐ͵ıäÁ¿£¬Õâ´æ´¢ÕûÊýµÄ±äÁ¿ÊÇintÀàµÄʵÀý£¨¶ÔÏ󣩡£
ÐèҪעÒâµÄÊÇ£¬ÔÚPythonÖУ¬¼´±ãÊÇÕûÊýÒ²±»×÷Ϊ¶ÔÏó£¨ÊôÓÚintÀࣩ¡£ÕâºÍC++¡¢Java£¨1.5°æÖ®Ç°£©°ÑÕûÊý´¿´â×÷ΪÀàÐÍÊDz»Í¬µÄ¡£Í¨¹ ......