PythonµÄ×Öµä²Ù×÷
PythonµÄ×Öµä²Ù×÷
PythonÌṩÁ˶àÖÖÓ¦ÓÃÓÚ×ÖµäµÄ²Ù×÷¡£ÒòΪ×ÖµäΪÈÝÆ÷£¬ÄÚ½¨lenº¯Êý¿ÉÒÔ½«×ֵ䵱×÷µ¥Ò»²ÎÊýʹÓÃÌýÇзµ»Ø×Öµä¶ÔÏóÖÐÏîÄ¿£¨¼ü£¯Öµ¶Ô£©µÄÊýÄ¿¡£
×Öµä»áÔ±
ÔÚPython2.2ÒÔ¼°ºóÃæ°æ±¾£¬DÖеÄkÔËËã·û¼ì²âÊÇ·ñ¶ÔÏókÊÇ×ÖµäDÖеļü¡£Èç¹ûÊÇ·µ»ØTrueÈç¹û²»ÊÇ·µ»ØFalse¡£ÏàËƵģ¬
Ë÷ÒýÒ»¸ö×Öµä
×ÖµäDÖеÄÖµÓëÏà¹ØµÄ¼ük±»Ë÷Òý±íʾΪ£ºD[k]¡£Ë÷Òý×ÖµäûÓеļü»áÒýÆðÒâÍâ¡£ÀýÈ磺
d = { 'x':42, 'y':3.14, 'z':7 }
d['x']
# 42
d['z']
# 7
d['a']
# raises exception
ƽÕû¸³Öµµ½Ò»¸öʹÓû¹²»ÔÚ×ÖµäÖеļüµÄË÷Òý£¨ÀýÈ磬D[newkey]=value£©ÊÇÒ»¸ö¿ÉÐеIJÙ×÷£¬¸Ã²Ù×÷¼ÓÔؼüºÍÖµµ½×ÖµäÀïеÄÏîÄ¿ÖС£ÀýÈ磺
d = { 'x':42, 'y':3.14, 'z':7 }
d['a'] =
16
# d is now {'x':42,'y':3.14,'z':7,'a':16}
del
D[k]ÖеÄdelÓï¾ä£¬É¾³ý×ÖµäÖÐÓµÓмükµÄÏîÄ¿¡£Èç¹ûk²»ÊÇ×ÖµäDÖеļü£¬del
D[k]¾Í»áÒýÆðÒâÍâ¡£
×ֵ䷽·¨
×Öµä¶ÔÏóÌṩÁ˶àÖÖ·½·¨£¬Èçϱí¸ñËùʾ¡£·Ç±äÒì·½·¨·µ»Ø½á¹û£¬µ«²»¸Ä±äËüÃÇʹÓõĶÔÏó¡£ÔÚÏÂÃæÁбíÖУ¬DºÍD1´ú±íÈκÎ×Öµä¶ÔÏó£¬k´ú±íDÖÐÈκÎÓÐЧµÄ¼ü£¬xΪÈκζÔÏó¡£
·½·¨
ÃèÊö
Non-mutating methods
D.copy( )
Returns a (shallow) copy of the dictionary
D.has_key(k)
Returns True if k is a key in D, otherwise returns False
D.items( )
Returns a copy of the list of all items (key/value pairs) in
D
D.keys( )
Returns a copy of the list of all keys in D
D.values( )
Returns a copy of the list of all values in D
D.iteritems( )
Returns an iterator on all items(key/value pairs) in D
D.iterkeys( )
Returns an iterator o
Ïà¹ØÎĵµ£º
½ñÌìÓÖɨÁËÒ»±éÊý×ÖÕâÒ»ÕÂ.. ¿´µ½ÁËround()º¯Êý, ÊÇÔÚpythonºËÐıà³Ì˼ÏëµÄ5.6.2½ÚµÄĩβ, ÔÎÄÈçÏÂ:
round(flt, ndig=0) ½ÓÊÜÒ»¸ö¸¡µãÊý flt ²¢¶ÔÆäËÄÉáÎåÈ룬±£´æ ndigλСÊý¡£
Èô²»Ìṩndig ²ÎÊý£¬ÔòĬÈÏСÊýµãºó0λ¡£
round()½öÓÃÓÚ¸¡µãÊý¡££¨ÒëÕß×¢£ºÕûÊýÒ²¿ÉÒÔ£¬ ²»¹ý²¢Ã»ÓÐʲô
ʵ¼ÊÒâÒ壩
Æäʵ, ×ö¸ö浄 ......
import Queue, threading, sys
from threading import Thread
import time,urllib
# working thread
class Worker(Thread):
worker_count = 0
def __init__( self, workQueue, resultQueue, timeout = 0, **kwds):
Thread.__init__( self, **kwds ) ......
µ±Äê×ö±ÏÒµÂÛÎĵÄʱºòopenCV¾ÍÏñÊÇÎÒµÄÈðÊ¿¾üµ¶£¬Ì«ÓиÐÇéÁË¡£Èç½ñÓÃÁËÒ»Äê¶àµÄpython£¬·¢ÏÖopenCVÒ²ÓÐpython°æ±¾ÁË£¬ÕæÊÇÌ«¿áÁË£¡µ±È»pythonÔÚ´¦ÀíͼÏñʱ»¹¿ÉÒÔÓÃÆäËü¿âÀýÈçPIL(Python Imaging Library )£¬Ò»ÖÖÇáÁ¿¼¶µÄͼÏñ¿â¡£Ä¿Ç°openCV1.0°æ±¾¶ÔÓ¦µÄpython°æ±¾Îª2.5£¬openCV2.0¶ÔÓ¦python 2.6¡£
¸½Â¼£º
1. һƪ½éÉÜͼ ......
Õâ¸öËãÊÇC++ǶÈëpython°É£¬ÀûÓÃpythonʵÏÖÏÔʾºÍʼþ´¦Àí£¬C++ʵÏÖÂß¼
ÒÔºóÓÐʱ¼äÒ²»á·´¹ýÀ´ÊÔÊÔ£º£©
import pygame
import sys
import os
import ctypes
def cur_file_dir():
#»ñÈ¡½Å±¾Â·¾¶
path = sys.path[0]
#ÅжÏΪ½Å±¾Îļþ»¹ÊÇpy2exe±àÒëºóµÄÎļþ£¬Èç¹ûÊǽű¾Îļþ£¬Ôò·µ»ØµÄÊǽű¾µÄÄ¿Â ......
²Ù×÷ϵͳ£ºlinux debian 4.0£¬ python°æ±¾2.5
s1:°²×°python2.5-dev¡£ÒòΪPython.hÊÇÔÚdev°üÖвÅÓС£
test@debian:~/test_python_c$ aptitude search python2.5-dev
p python2.5-dev - Header files and a static library for Python.
test@debian:~/test_python_c$ sudo aptitude install python2 ......