Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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ǶÈëC++Ïê½â(3)

¼Ìǰƪ¡¶Import Module¡·£¨http://blog.csdn.net/xiadasong007/archive/2009/09/02/4512797.aspx£©£¬¼ÌÐø·ÖÎöǶÈ벿·Ö»ù´¡ÖªÊ¶¡£Õâ´Î²»¶à˵£¬ÓÐʲôÎÊÌâ¼ÇµÃ¶à²éÓ¢ÎÄ×ÊÁÏ£¬¹úÄÚµÄÕâ·½ÃæÖªÊ¶ÉÙ
»¹ÊÇÀ´¿´´úÂ룬дÍêÎÒ¾Í˯¾õÁË~
 
#include "python/python.h"
#include <iostream>
using namespace std;
int ......

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

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

Python±Ê¼Ç£¨5£©

Ä£¿é
 
Ò».¼ò½é
Ä£¿é»ù±¾ÉϾÍÊÇÒ»¸ö°üº¬ÁËËùÓÐÄ㶨ÒåµÄº¯ÊýºÍ±äÁ¿µÄÎļþ¡£ÎªÁËÔÚÆäËû³ÌÐòÖÐÖØÓÃÄ£¿é£¬Ä£¿éµÄÎļþÃû±ØÐëÒÔ.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 ......

python »ù±¾ÀàÐÍlist¡¢tuple¡¢dictѧϰ


1.list£¨Êý×飩
x´ú±íÊý×éÖеÄÔªËØ£¬i´ú±íλÖÃ
a) append(x) °ÑÔªËØxÌí¼Óµ½Êý×éµÄβ²¿
b) insert(i,x) °ÑÔªËØx ²åÈ뵽λÖÃi
c) remove(x) ɾ³ýµÚÒ»¸öÔªËØx
d) pop(i) ɾ³ýµÚi¸öÔªËØ£¬²¢·µ»ØÕâ¸öÔªËØ¡£Èôµ÷ÓÃpop()Ôòɾ³ý×îºóÒ»¸öÔªËØ
e) index(x) ·µ»ØÊý×éÖеÚÒ»¸öֵΪxµÄλÖá£Èç¹ûûÓÐÆ¥ÅäµÄÔªËØ»áÅ׳öÒ»¸ö´íÎó
f ......

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ºÅ