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

pythonÄ£¿éÖ®ConfigParser ini

תÔØ×Ô£ºhttp://hi.baidu.com/myitlyj/blog/item/25586bd7088ba3dba044df6b.html
ÔÚ³ÌÐòÖÐʹÓÃÅäÖÃÎļþÀ´Áé»îµÄÅäÖÃһЩ²ÎÊýÊÇÒ»¼þºÜ³£¼ûµÄÊÂÇ飬ÅäÖÃÎļþµÄ½âÎö²¢²»¸´ÔÓ£¬ÔÚpythonÀï¸üÊÇÈç´Ë£¬ÔÚ¹Ù·½·¢²¼µÄ¿âÖоͰüº¬ÓÐ×öÕâ¼þÊÂÇéµÄ¿â£¬ÄǾÍÊÇConfigParser£¬ÕâÀï¼òµ¥µÄ×öһЩ½éÉÜ¡£
ConfigParser½âÎöµÄÅäÖÃÎļþµÄ¸ñʽ±È½ÏÏóiniµÄÅäÖÃÎļþ¸ñʽ£¬¾ÍÊÇÎļþÖÐÓɶà¸ösection¹¹³É£¬Ã¿¸ösectionÏÂÓÖÓжà¸öÅäÖÃÏ±ÈÈ磺
[db]
db_host=127.0.0.1
db_port=3306
db_user=root
db_pass=password
[concurrent]
thread=10
processor=20
¼ÙÉèÉÏÃæµÄÅäÖÃÎļþµÄÃû×ÖΪtest.conf¡£ÀïÃæ°üº¬Á½¸ösection,Ò»¸öÊÇdb, ÁíÒ»¸öÊÇconcurrent, dbÀïÃ滹°üº¬ÓÐ4ÏconcurrentÀïÃæÓÐÁ½Ïî¡£ÕâÀïÀ´×ö×ö½âÎö£º
#-*- encoding: gb2312 -*-
import ConfigParser
import string, os, sys
cf = ConfigParser.ConfigParser()
cf.read("test.conf")
# ·µ»ØËùÓеÄsection
s = cf.sections()
print 'section:', s
o = cf.options("db")
print 'options:', o
v = cf.items("db")
print 'db:', v
print '-'*60
#¿ÉÒÔ°´ÕÕÀàÐͶÁÈ¡³öÀ´
db_host = cf.get("db", "db_host")
db_port = cf.getint("db", "db_port")
db_user = cf.get("db", "db_user")
db_pass = cf.get("db", "db_pass")
# ·µ»ØµÄÊÇÕûÐ͵Ä
threads = cf.getint("concurrent", "thread")
processors = cf.getint("concurrent", "processor")
print "db_host:", db_host
print "db_port:", db_port
print "db_user:", db_user
print "db_pass:", db_pass
print "thread:", threads
print "processor:", processors
#ÐÞ¸ÄÒ»¸öÖµ£¬ÔÙд»ØÈ¥
cf.set("db", "db_pass", "zhaowei")
cf.write(open("test.conf", "w"))


Ïà¹ØÎĵµ£º

python decorator

1.³£Ó÷½·¨£¬²»´ø²ÎÊý
def decator(func):
    def inner_func(*args):
        args = (i * 2 for i in args)
        return func(*args)
    return inner_func
   
@decator
def add(a, ......

pythonÓ¦ÓÃÁìÓò½éÉÜ

pythonÓ¦ÓÃÁìÓò½éÉÜ 
Python×÷ΪһÖÖ¹¦ÄÜÇ¿´óÇÒͨÓõıà³ÌÓïÑÔ¶ø¹ãÊܺÃÆÀ£¬Ëü¾ßÓзdz£ÇåÎúµÄÓï·¨Ìص㣬ÊÊÓÃÓÚ¶àÖÖ²Ù×÷ϵͳ£¬Ä¿Ç°ÔÚ¹ú¼ÊÉϷdz£Á÷ÐУ¬ÕýÔڵõ½Ô½À´Ô½¶àµÄÓ¦Óᣠ
ÏÂÃæ¾ÍÈÃÎÒÃÇÒ»ÆðÀ´¿´¿´ËüµÄÇ¿´ó¹¦ÄÜ£º 
Python£¨ÅÉÉ­£©£¬ËüÊÇÒ»¸ö¼òµ¥µÄ¡¢½âÊÍÐ͵ġ¢½»»¥Ê½µÄ¡¢¿ÉÒÆÖ²µÄ¡¢ÃæÏò¶ÔÏóµÄ³¬¸ß¼¶Óï ......

Python 3 ³õ̽£¬µÚ 2 ²¿·Ö: ¸ß¼¶Ö÷Ìâ

Python 3 ÊÇ Guido van Rossum ¹¦ÄÜÇ¿´óµÄͨÓñà³ÌÓïÑÔµÄ×îа汾¡£ËüËäÈ»´òÆÆÁËÓë 2.x °æ±¾µÄÏòºó¼æÈÝÐÔ£¬µ«È´ÇåÀíÁËijЩÓï·¨·½ÃæµÄÎÊÌâ¡£±¾ÎÄÊÇÕâ¸öÓÉÁ½²¿·Ö×é³ÉµÄϵÁÐÎÄÕÂÖеĵڶþƪ£¬±¾ÎĹ¹½¨ÔÚ´ËϵÁÐ Ç°Ò»ÆÚÎÄÕ µÄ»ù´¡Ö®ÉÏ£¬ÄÚÈݺ­¸ÇÁË Python ¸ü¶àµÄÐÂÌØÐԺ͸ü¸ßÉîµÄһЩÖ÷Ì⣬±ÈÈçÔÚ³éÏó»ùÀà¡¢ÔªÀàºÍÐÞÊηûµÈ·½ÃæµÄ ......

PYTHONÉèÖÃĬÈÏÓïÑÔ±àÂë

ת×Ô http://www.javaeye.com/topic/561786
Ô­Ìû£ºhttp://www.cnblogs.com/jingleguo/archive/2008/06/02/1211820.html
µ±pythonÖм䴦Àí·ÇASCII±àÂëʱ£¬¾­³£»á³öÏÖÈçÏ´íÎó£º
UnicodeDecodeError: 'ascii' codec can't decode byte 0x?? in position 1: ordinal not in range(128)
0x??Êdz¬³ö128µÄÊý×Ö£¬pythonÔÚĬÈϵ ......

python mysqlµ¼ÈëÊý¾Ý

[root@pku-fan MySQL]# cat limbs.sql
CREATE DATABASE cookbook;
USE cookbook;
DROP TABLE IF EXISTS limbs;
CREATE TABLE limbs
(
    thing   VARCHAR(20),    # what the thing is
    legs    INT,     ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ