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: ´òÓ¡ÈÕÖ
Ïà¹ØÎĵµ£º
$ ×Ö·û´®µÄĩβ
^ ×Ö·û´®µÄ¿ªÊ¼
\b ×Ö·ûµÄ±ß½ç
ǰ׺t ×Ö·û´®Öеķ´Ð±Ïߣ¨ËùÓÐ×Ö·û£©²»×ªÒå
? ¿ÉÑ¡µØÆ¥Åä(λÓÚ֮ǰµÄ)µ¥¸ö×Ö·û
() ¸Ä±äÓÅÏȼ¶£¬×÷Ϊһ¸öÕûÌ壬һ¸ö×é
| »òÕß
(A|B) ¾«È·Æ¥ÅäA»òBÖеÄÒ»¸ö
{n,m} Æ¥Å䣨λÓÚ֮ǰµÄ×Ö·û£©nµ½m´Î
VERBOSE ......
×î½üÔÚ¹«Ë¾¸ºÔðÒ»¸öÏîÄ¿£¬ÊÇ×öÒ»¸ö±àÒëÆ÷£¬´ó¼Ò¿ÉÄÜÖªµÀ£¬×ö±àÒëÆ÷Ò»°ãÓÃC++»òjava£¬µ«ÊÇÎÒµÄÕâ¸öÏîĿȴʹÓÃÁËpythonÀ´×öÕâ¸ö±àÒëÆ÷£¬ºÜÓÐÌôÕ½ÐÔ¡£
ÎÒ½ñÌìËù½²µÄÊÇÔÚ¿ª·¢¹ý³ÌÖУ¬¶ÔʹÓÃpython2.6ÓïÑԵĸÐÊÜ£¬Ä¿Ç°Õâ¸öÏîÄ¿ÒѾÍê³ÉÈý·ÖÖ®Ò»ÁË¡£
˵ʵ»°£¬python²¢²»ÊʺÏ×öÕâÑùµÄÏîÄ¿¡££¨ËäȻҲÄÜ×ö£©ÒÔÏÂÊÇ×ܽáÁËpythonÏà¹Ø ......
ѧϰpython±¾¾ÍÊÇÒµÓàÖ®ºÃ£¡Ê鱾ɶµÄ£¬¶¼ÎÞ´Ó˵Æð¡£ËùÒÔż¶ûÅöµ½Ò»¸öºÃµÄÄ£¿é£¬¾ÍÒªÔÚ²©¿ÍÖмǼһÏ£¬ÒÔ±ãÈÕºóÖ®Óá£ÊÇÒÔ¸ßÊÖÖ±½ÓµÄÆ®¹ý¡£ÏÂÃæÇÐÈëÕýÌâ¡£
globÊÇpython×Ô¼º´øµÄÒ»¸öÎļþ²Ù×÷Ïà¹ØÄ£¿é£¬ÄÚÈÝÒ²²»¶à£¬ÓÃËü¿ÉÒÔ²éÕÒ·ûºÏ×Ô¼ºÄ¿µÄµÄÎļþ£¬¾ÍÀàËÆÓÚWindowsϵÄÎļþËÑË÷£¬¶øÇÒÒ²Ö§³ÖͨÅä·û£¬*,?,[]Õ ......
Ä£¿é
Ò».¼ò½é
Ä£¿é»ù±¾ÉϾÍÊÇÒ»¸ö°üº¬ÁËËùÓÐÄ㶨ÒåµÄº¯ÊýºÍ±äÁ¿µÄÎļþ¡£ÎªÁËÔÚÆäËû³ÌÐòÖÐÖØÓÃÄ£¿é£¬Ä£¿éµÄÎļþÃû±ØÐëÒÔ.pyΪÀ©Õ¹Ãû¡£
ÀýÈ磺
#!/usr/bin/python
# Filename: using_sys.py
import sys
print 'The command line arguments are:'
for i in sys.argv:
print i
print '\n ......
#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=""):
"""ÏÔʾÕý³£Ò³Ã棬¶ÔÒ³ÃæµÄÎÄ×Ö×öÌØÊâµÄÁ´½Ó´¦Àí"""
......