PythonÔªÀà
±³ºóÓÐÒ»´óÌ×µÄÀíÂÛ £¡£¡¹ÜËüÄØ£¡£¿ÀíÂÛÄܵ±·¹³ÔÂð£¿
ÏÈÖªµÀÔõôÓÃÔÙ˵£¡
¼Çס£ºÔªÀà¾ÍÊÇÀàµÄÄ£°å——Ì«ÐÎÏóÁËÁËѽ£¬»ô»ô¡£
ÎÒÒªÒ»´óȺµÄÀ඼¾ßÓÐÒ»ÖÐÌص㣬ÎÒÔõô¸øËûÃǼÓÉÏÄØ£¿Ä£°åÄ£°åÂð£¬ÎÒ´ÓÕâ¸öÄ£°å´´½¨Ò»ÈºÀ಻¾ÍOKÁË£¿ÄǾÍÐèÒªÔªÀàÁË¡£»ô»ô¡·
¶¨ÒåÒ»¸öÔªÀࣨ¾ÍËùÒ»¸öÀàµÄÄ£°å£¡Äª¶àÏ룬»¹Òª¼ÇסÕâÊÇÀ༶±ðµÄ£¬²»ÊǶÔÏ󼶱ðµÄ£¡£©£º
class MyMeta(type):
... def __init__(cls,name,bases,dic):
... print cls.__name__
... print name
... def __str__(cls):return 'Beautiful class %s'%cls.__name__
ÕâÊǸöʲô¶«Î÷£¿¹þ£¬ÕâÊǸöÔªÀà¡£ÊǸöÀàµÄÄ£°å¡£
ËüÒªÓÃÔÚÄÄÀËüÒªÓÃÔÚÒ»¸öÀàÀ×÷ΪÕâ¸öÀàµÄÄ£°å¡£
ÆðµÄʲô×÷Óã¿Ä£°å£¬¾ÍÊÇÌṩһЩ¹²Í¬µÄÌØÕ÷¡£
Õâ¸öÀàÌṩÁËʲôÑùµÄÌØÕ÷£¿Á½¸öÌØÕ÷£¬1¡£ÀඨÒåºó´òÓ¡ÀàµÄÃû×Ö£¨__init__£©¡£2¡£´òÓ¡ÀàµÄ¸ñʽ(__str__)¡£
µ½µ×»ØÔõô¹¤×÷£¬´ò¿ªµÄÄãµÄ½âÊÍÆ÷£¬ÊäÈëÒÔÉϵĴúÂ룬ÉÏ·£º
ÊäÈ룺
class MyClass(object):
... __metaclass__ = MyMeta
»Ø³µ½áÊøÀàµÄ¶¨Òåʱ£¬Êä³ö£º
MyClass
MyClass
Ã÷°×ÁË°É£¬»ô»ô£¡ÊÂʵ֤Ã÷ËüȷʵÊdzõʼ»¯Ò»¸öÀ࣬¶ø²»ÊÇÒ»¸ö¶ÔÏ󣡣¡£¡£¡£¡Õâ¸öÊǵÚÒ»¸öÌØÕ÷¡£
µÚ¶þ¸ö£º
ÊäÈ룺
print MyClass
Êä³ö£º
Beautiful class MyClass
°¡¹þ£¬Ç¡ÈçÆä·Ö£¬ÈçÎÒÃÇËùÔ¤ÁϵÄÄÇÑù£¡£¡£¡£¡£¡£¡£¡£¡µ±È»Äã¿ÉÒÔÈÎÒâ¸öÐÔ»¯ÄãµÄÀ࣡£¡
####################################################################################
ÏÂÃæÎÒÃÇÀ´ÊµÏÖÒ»¸öSingletonģʽ£¨À´×Ô×ÄľÄñÉçÇø£©£º
SingletonÔªÀࣺ
class Singleton(type):
... def __init__(cls,name,bases,dic):
... super(Singleton,cls).__init__(name,bases,dic)
... cls.instance = None
... def __call__(cls,*args,**kwargs):
... if cls.instance is None:
... cls.instance = super(Singleton,cls).__call__(*args,**kwargs)
... return cls.instance
·Ç³£¼òµ¥µÄÒ»¸öÉè¼Æģʽ
Ïà¹ØÎĵµ£º
´úÂëÈçÏ£º
#!/usr/bin/env python
# -*-coding:UTF-8-*-#
from common import *
import Image, ImageFilter, math, sys, os, random
def modifyImageObj(img, matrix) :
width, height = img.size
for h in range(0, height) :&n ......
Õâ¸öÊÇ1.10°æ±¾µÄ²ÂÊý×Ö£¬ËäÈ»´úÂë»ù±¾²»±ä£¬µ«ÊDZäµÄÊÇ˼ά·½Ê½£¬²»ÔÙÊÇÓÃÃæÏò¹ý³ÌµÄ·½·¨£¬¶ø¸ÃΪÓÃÀàÀ´ÊµÏÖ£¬±È½ÏÇ°ºóµÄ´úÂ룬ÕâÒ»¸ö¼ò½à¶àÁË£¬¶øÇÒ¸üÈÝÒ×Àí½â£¡
¸üУº
#1.0°æ±¾ÖеÄÌáʾÀàÐÍÊÇ£ºAABB£¬¼òµ¥µÄ˵¾ÍÊÇÏà¶ÔλÖõÄÊý×Ö¶ÔÁ˾ÍÏÔʾA£¬´íÁ˾ÍÏÔʾB£»
#ÏÖÔÚµÄÌáʾ¸ÄΪ£º0A4B¸ñʽ£¬Ò²¾ÍÊÇ˵²»ÌáʾÄǸöλÖõÄÊý× ......
¼òµ¥¼ÓÃÜ£¬ÓÃpythonÀ´Ð´Ð´¡£
#coding=utf-8
'''
Description: ¿ÉÄæµÄ¼ÓÃÜÓë½âÃÜ
Environment: python2.5.x
Author:idehong@gmail.com
'''
import os
import sys
class Code(object):
'''¿ÉÄæµÄ¼ÓÃÜÓë½âÃÜ'''
def __init__(self, key = "idehong@gmail.com"):
self.__src_key ......
ÀµÓºƣ¨http://laiyonghao.com£©
½ñÌ죨2009Äê5ÔÂ31ÈÕ£© OurPNP.org ¸ãÁ˸ö¾Û»á»î¶¯£¬ÅªÁËÊ®¼¸¶þÊ®¸öÈËÔÚ¹ãÖݺ£Öé¹ã³¡µÄÌûá´ôÁËÎå¸öСʱ£¬´´ÏÂÁËÎÒÔÚ K ·¿´ôµÄ×ʱ¼ä¼Í¼¡£Ó¦ËûÃǵÄÑûÇ룬ÎÒ×öÁ˸öÌâΪ¡¶Óà python ¿ìËٴÍøÓηþÎñÆ÷¡·µÄСÑݽ²£¬ÒòΪÄDZߵĵçÊÓ¾¹È»²»ÄܽӵçÄÔ£¬ËùÒÔ½²µÄʱºòûÓÐÄܹ»²ÎÕÕ PPT À´½²£¬¹Û ......
Ò»¿ÅÓï·¨ÌÇ——×°ÊÎÆ÷
ÀíÂÛ²»È¥¹Ü£¬Ö»¹ÜÄÜ°ìÊ£º
1. ÎÒÒªÈÃÒ»¸öº¯ÊýÔÚÖ´ÐеÄʱºò£¬È¥×öһЩÊÂÇ飬±ÈÈ磬ÎÒÒª¿´¿´ÕâЩº¯ÊýÊDz»ÊÇÓÐdocstring£¬½«Õâ¸ö¹¦ÄÜÄóöÀ´£¬¶¨ÒåÒ»¸ö×°ÊÎÆ÷£º
def showmedoc(func):
if func.__doc__:
& ......