PythonÖØÔØÑ§Ï°ÊÖ¼Ç
½ñÌìѧϰÁËÒ»ÏÂPythonµÄ²Ù×÷·ûÖØÔØ£¬×ܽáÁ˼¸µã±È½ÏÉñÆæµÄ¶«¶«£º
------------------------------------------------------------------------------------------------------------
¹ØÓÚiter£º
Technically, iteration contexts work by calling the iter built-in function to try to
find an _ _iter_ _ method, which is expected to return an iterator object. If it’s
provided,Python then repeatedly calls this iterator object’s next method to produce
items until a StopIteration exception is raised. If no such _ _iter_ _ method is found,
Python falls back on the _ _getitem_ _ scheme, and repeatedly indexes by offsets as
before, until an IndexError exception is raised.
ËùÒÔΪÁËʹÓÃiter£¬ÎÒÃDZØÐëÖØÔØ__iter__£¬È»ºóÔÙ¶¨ÒåÒ»¸önext·½·¨£¬Àý×ÓÈçÏ£º
class Squares:
def _ _init_ _(self, start, stop): # Save state when created
self.value = start - 1
self.stop = stop
def _ _iter_ _(self): # Get iterator object on iter( )
return self
def next(self): # Return a square on each iteration
if self.value == self.stop:
raise StopIteration
self.value += 1
return self.value ** 2
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
ÀûÓÃ__setattr__µÄʱºò£¬×Ô¼º¸³Öµ²»¿ÉÒÔʹÓÃself.name = value£¬ÒòΪÕâ¸öÓï¾äÒ²ÊÇÓÃÁË__setattr__
£¬ÕâÑùÖØ¸´Ê¹Ó㬳ö´í¡£ÒªÊ¹ÓÃself.__dict__['name'] = value
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
ÀûÓÃ__getattr__½¨Á¢“˽ÓД³ÉÔ±±äÁ¿£º
ÀûÓÃÖØÔØµÄ__setattr__ÔÚÿ´Îȡ֮ǰÅжÏÒ»ÏÂ˽ÓгÉÔ±Ãû×Öµ±ÖÐÓÐûÓУ¬À´ÊµÏÖ˽ÓУ¬´úÂëÈçÏ£¨È¡×Ô
Learning Python£©
class PrivateExc(Exception): pass
class Privacy:
&nb
Ïà¹ØÎĵµ£º
ʹÓÃpython.vimʹpython´úÂë¸ßÁÁ
http://www.vim.org/scripts/script.php?script_id=790
ʹÓÃ
Pydiction²å¼þʹvimÔö¼Ótab´úÂëÌáʾ¹¦ÄÜ
http://www.vim.org/scripts/script.php?script_id=850
¾ßÌå°²×°·½·¨¿ÉÒÔ²ÎÕÕ°ïÖú»òÕßREADME£¬ÒòΪ°æ±¾±ä»¯»áµ¼Ö°²×°·½·¨ÉϲúÉú²îÒì
±à¼~/.vimrcÎļþÔö¼ÓÏÂÃæÑ¡Ïî
set nu Ôö¼ÓÐÐ ......
import sys, pygame, time
size = width, height = 700,700
fontColor = (0,0,255)
class walk:
'''This is a game about war.
Just like war 3.'''
def __init__(self):
'''Init the screen.
Get param and init the screen'''
#print ('this is init funnction') ......
while µÄÓ÷¨£º
while ºóÃæ¸úÌõ¼þ±í´ïʽ£¬(:)ºóÃæ¸úÓï¾ä¿é£¬Äã¿ÉÒÔÔÚÕâ¶ÎÓï¾ä¿éÀïÐÞ¸ÄÌõ¼þ±í´ïʽµÄijЩ±äÁ¿£¬µ±Ìõ¼þ±í´ïʽ Ϊ¼ÙµÄʱºòÍ˳öÑ»·¡£ÀýÈ磺
flag = 5
while flag > 0:
#ÕâÀïÊÇÄãµÄ´úÂë
flag -= 1
#if flag == 3: break
#if flag == 3: continue
print flag
µ±È»ÄãÒ²¿ÉÒÔÔÚÊʵ ......
1. µÚ¶þÕ Óï·¨¼°´úÂëÔ¼¶¨
&nb ......