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

Python´úÂëÓÅ»¯

Python´úÂëÓÅ»¯--ÉÙ´ò×ÖС¼¼ÇÉ
˵Ã÷£ºÔö¼Ó´úÂëµÄÃèÊöÁ¦£¬¿ÉÒԳɱ¶¼õÉÙÄãµÄLOC£¬×öµ½¼òµ¥£¬²¢ÇÒÕæÇÐÓÐÁ¦
¹Ûµã£ºÉÙ´ò×Ö£½¶à˼¿¼£«ÉÙ³ö´í£¬10´úÂëÐбÈ50ÐиüÄÜÈÃÈËÃ÷°×£¬ÒÔϼ¼ÇÉÓÐÖúÓÚÌá¸ß5±¶¹¤×÷ЧÂÊ
1. ½»»»±äÁ¿ÖµÊ±±ÜÃâʹÓÃÁÙʱ±äÁ¿£º(cookbook1.1)
ÀÏ´úÂ룺ÎÒÃǾ­³£ºÜÊìÁ·ÓÚÏÂÃæµÄ´úÂë
temp = x
x = y
y = temp
´úÂëÒ»£º
u, v, w = w, v, u
ÓÐÈËÌá³ö¿ÉÒÔÀûÓø³ÖµË³ÐòÀ´¼ò»¯ÉÏÃæµÄÈýÐдúÂë³ÉÒ»ÐÐ
´úÂë¶þ£º
u, v = v, u
ÆäʵÀûÓÃPythonÔª×鸳ֵµÄ¸ÅÄ¿É¸ü¼òÃ÷ -- Ôª×é³õʼ»¯ + Ôª×鸳ֵ
2. ¶Á×Öµäʱ±ÜÃâÅжϼüÖµÊÇ·ñ´æÔÚ£º(cookbook1.2)
d = { 'key': 'value' }
ÀÏ´úÂ룺
if 'key' in d: print d['key']
else: print 'not find'
дúÂ룺
print d.get('key', 'not find')
3. Ñ°ÕÒ×îСֵºÍλÖõĴúÂëÓÅ»¯£º
s = [ 4,1,8,3 ]
ÀÏ´úÂ룺
mval, mpos = MAX, 0
for i in xrange(len(s)):
if s[i] < mval: mval, mpos = s[i], i
дúÂ룺
mval, mpos = min([ (s[i], i) for i in xrange(len(s)) ])
Ôª×é±È½ÏµÄÌØÐÔ£¬¿ÉÒÔ·½±ãµÄд×öÒ»ÐÐ
¹ÛµãÒ»£ºÓÃPython±à³Ì£¬ÐèÒªÓГһ×Öǧ½ð”µÄ¸Ð¾õ£»¼ÈȻѡÔñÁËPython£¬¾Í²»ÒªÔÚÒâµ¥ÌõÓï¾äµÄЧÂÊ¡£
ÉÏÃ漸µãÀý×Ӻܻù´¡£¬Êµ¼ÊÖн«Ô­Ê¼´úÂëѹËõ1/5²¢²»ÊDz»¿ÉÄÜ£¬ÎÒÃÇ֮ǰһ¸ö×ÓÏîÄ¿£¬C++´úÂë270K
Öع¹ºóPython´úÂëÖ»ÓÐ67K£¬µ±È»Ê¹ÓÃpythonµÄÈÕ־ģ¿é£¨logging£©£¬¶Áд±í¸ñÎı¾£¨csv£©µÈ£¬Ò²¹¦
²»¿ÉÄ©£¬×îÖÕ´úÂë±ä³ÉÔ­À´µÄ1/4£¬ÎÒ¾õµÃ×Ô¼ºµÄÊÙÃüÑÓ³¤ÁËÈý±¶¡£¡£¡£ÏÂÃæÓÅ»¯¼¸¸ö³£ÓôúÂ룺
4. Îļþ¶ÁÈ¡¹¤×÷µÄ×î¼òµ¥±í´ï£º
ÀÏ´úÂ룺ÎÒÃÇÐèÒª½«Îı¾Îļþ¶ÁÈëµ½ÄÚ´æÖÐ
line = ''
fp = open('text.txt', 'r')
for line in fp: text += line
´úÂëÒ»£º
text = string.join([ line for line in open('text.txt')], '']
´úÂë¶þ£º
text = ''.join([ line for line in open('text.txt')])
´úÂëÈý£º
text = file('text.txt').read()
а汾µÄPython¿ÉÒÔÈÃÄãд³ö±È1£¬2ƯÁÁµÄ´úÂ루openÊÇfileµÄ±ðÃû£¬ÕâÀïfile¸üÖ±¹Û£©
5. ÈçºÎÔÚPythonʵÏÖÈýԪʽ£º
ÀÏ´úÂ룺ÓùßC++,Java,C
²»Ï²»¶Ð´ÏÂÃæ´úÂë
if n >= 0: print 'positive'
else: print 'negitive'
´úÂëÒ»£º¸Ã¼¼ÇÉÔÚ LuaÀïÒ²ºÜ³£¼û
print (n >= 0) and 'positive' or 'negitive'
˵Ã÷£ºÕâÀïµÄ'and'ºÍ'or'Ï൱ÓÚCÖеÄ':'ºÍ'?'µÄ×÷Ó㬵ÀÀíºÜ¼òµ¥£¬ÒòΪÈç¹û±í´


Ïà¹ØÎĵµ£º

PythonÉÏ´«Îļþµ½·þÎñÆ÷

#! /usr/bin/env python
# -*- coding: utf-8 -*-
from ftplib import FTP
from os import path
from optparse import OptionParser
from FtpDownload import spilt_cmd
import socket
import sys
'''
ÉÏ´«ÖÕ¶ËMRÎļþµ½·þÎñÆ÷
V1.0    zhai   2009-07-27
'''
def main():
&nbs ......

PythonÏ̱߳à³Ì£¨Ò»£©Ï̶߳ÔÏó

ÎÒÃÇÔÚ×öÈí¼þ¿ª·¢µÄʱºòºÜ¶àÒªÓõ½¶àÏ̼߳¼Êõ¡£ÀýÈçÈç¹û×öÒ»¸öÏÂÔØÈí¼þÏóflashget¾ÍÒªÓõ½¡¢ÏóÔÚÏßÊÓƵ¹¤¾ßrealplayerÒ²ÒªÓõ½ÒòΪҪͬʱÏÂÔØmedia stream»¹Òª²¥·Å¡£ÆäʵÀý×ÓÊǺܶàµÄ¡£
Ïß³ÌÏà¶Ô½ø³ÌÀ´ËµÊÇ“ÇáÁ¿¼¶”µÄ£¬²Ù×÷ϵͳÓýÏÉÙµÄ×ÊÔ´´´½¨ºÍ¹ÜÀíÏ̡߳£³ÌÐòÖеÄÏß³ÌÔÚÏàͬµÄÄÚ´æ¿Õ¼äÖÐÖ´ÐУ¬²¢¹²ÏíÐí¶àÏà ......

python_ÀàÐͺͶÔÏó


Python ³ÌÐòÖеÄÒ»ÇÐÊý¾Ý¶¼ÊǶÔÏ󡣶ÔÏó°üÀ¨×Ô¶¨Òå¶ÔÏó¼°»ù±¾µÄÊý¾ÝÀàÐÍÈçÊýÖµ¡¢×Ö·û´®¡¢ÁÐ±í¡¢×ÖµäµÈ¡£ÄãÄܹ»ÒÔÀà»òÀ©Õ¹ÀàÐ͵ķ½Ê½´´½¨×Ô¶¨Òå¶ÔÏó¡£±¾ÕÂÖ÷ÒªÃèÊö Python¶ÔÏóÄ£Ðͼ°µÚËÄÕÂ--ÔËËã·ûÓë±í´ïʽÖÐÒªÓõ½µÄһЩԤ±¸ÖªÊ¶¡£
 
1.1. ÊõÓï
³ÌÐòÖеÄÒ»ÇÐÊý¾Ý¶¼ÊǶÔÏó£¬Ã¿¸ö¶ÔÏó¶¼ÓÐÈý¸ö»ù±¾ÊôÐÔ£¬¼´±êʶ(ÀàË ......

python pyserial ´®¿Ú

ÓÃpythonдÁ˸ö×î¼òµ¥µÄ¶Á´®¿ÚµÄ³ÌÐò£¬ÒòΪ¹¤×÷Öо­³£ÐèÒª¶Á´®¿Ú
·Åԭʼ´úÂë
import serial
ser = serial.Serial('com3',baudrate=115200, bytesize=8,parity='N', stopbits=1,xonxoff=0, timeout=1)
while( True ):
    a = ser.read(100)
    print a
ÓÃÍêÐèÒªser.close()£¬·ñÔòÆäË ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ