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

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¿âÏê½âÖ®ÍøÂç(2)

×òÌìÊÔÁËÏÂÓÃHTMLParserÀàÀ´½âÎöÍøÒ³£¬¿É·¢ÏÖ½á¹û²¢²»ÀíÏë¡£²»¹ÜÔõô˵£¬ÏÈдϹý³Ì£¬Ï£ÍûºóÀ´ÈËÄÜÔÚ´Ë»ù´¡ÉϽâ¾öÎÒËùÓöµ½µÄÎÊÌâ¡£
дÁË2Ì×½â¾ö·½°¸£¬µ±È»Õâ2Ì×Ö»ÄܶÔÌض¨ÍøÕ¾ÓÐЧ¡£ÎÒÕâÀïÖ÷Ҫ˵Ã÷϶ÔBBCÖ÷Ò³www.bbc.co.ukºÍ¶ÔÍøÒ×www.163.comµÄ½âÎö¡£
¶ÔÓÚBBC£º
ÕâÌ×Òª¼òµ¥µÃ¶à£¬¿ÉÄÜÊǸÃÍøÒ³µÄ±àÂë±È½Ï±ê×¼°É
import ......

(ת) pythonÓ¦ÓÃÁìÓò½éÉÜ

#---------------------תתתתתתתתתתתתתתתתתתתתתתת-------------------------------------------#
Python×÷ΪһÖÖ¹¦ÄÜÇ¿´óÇÒͨÓõıà³ÌÓïÑÔ¶ø¹ãÊܺÃÆÀ£¬Ëü¾ßÓзdz£ÇåÎúµÄÓï·¨Ìص㣬ÊÊÓÃÓÚ¶àÖÖ²Ù×÷ϵͳ£¬Ä¿Ç°ÔÚ¹ú¼ÊÉϷdz£Á÷ÐУ¬ÕýÔڵõ½Ô½À´Ô½¶àµÄÓ¦Óá£
 
¡¡¡¡ÏÂÃæ¾ÍÈÃÎÒÃÇÒ»ÆðÀ´¿´¿´ËüµÄÇ¿´ó ......

Python: ʹÓÃ×°ÊÎÆ÷¡°@¡±È¡µÃº¯ÊýÖ´ÐÐʱ¼ä

¡¡¡¡PythonÖпÉÒÔʹÓÃ×°ÊÎÆ÷¶Ôº¯Êý½øÐÐ×°ÊΣ¨»ò˵°ü×°£©£¬ÀûÓÃÕâ¸öÌØÐÔ£¬¿ÉÒԺܷ½±ã¡¢¼ò½àµØ½â¾öһЩÎÊÌ⣬±ÈÈç»ñµÃº¯ÊýÖ´ÐÐʱ¼äµÄÎÊÌâ¡£
¡¡¡¡Ê×ÏÈ£¬ÎÒÃǶ¨ÒåÒ»¸öº¯Êý£¬ÈçÏ£º
¡¡¡¡def exeTime(func):
def newFunc(*args, **args2):
t0 = time.time()
print "@%s, {%s} start" % (time.strftime("%X", time.local ......

pythonµÄwiki ÁÐ×Ó.

#coding=utf-8
from newtest.wiki.models import WiKi
from django.template import loader, Context
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response

def index(request, pagename=""):
"""ÏÔʾÕý³£Ò³Ã棬¶ÔÒ³ÃæµÄÎÄ×Ö×öÌØÊâµÄÁ´½Ó´¦Àí"""
......

Python ǶÌ׺¯Êý Óë ±äÁ¿×÷ÓÃÓò

a=1
print id(a)
a=2
print id(a)
a=a+1
print id(a) 
-------------------------------------------------------------------------------------------------------------------------
t=6
def tt():
    global t
    t=t+1
    print t
print t
tt()
½ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ