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

PythonÄ£¿éѧϰ

¡¡¡¡ÓÐʱºò£¬Òª°ÑÄÚ´æÖеÄÒ»¸ö¶ÔÏó³Ö¾Ã»¯±£´æµ½´ÅÅÌÉÏ£¬»òÕßÐòÁл¯³É¶þ½øÖÆÁ÷ͨ¹ýÍøÂç·¢Ë͵½Ô¶³ÌÖ÷»úÉÏ¡£PythonÖÐÓкܶàÄ£¿éÌṩÁËÐòÁл¯Óë·´ÐòÁл¯µÄ¹¦ÄÜ£¬È磺marshal, pickle, cPickleµÈµÈ¡£½ñÌì¾Í½²½²marshalÄ£¿é¡£
¡¡¡¡×¢Ò⣺
marshal²¢²»ÊÇÒ»¸öͨÓõÄÄ£¿é£¬ÔÚijЩʱºòËüÊÇÒ»¸ö²»±»ÍƼöʹÓõÄÄ£¿é£¬ÒòΪʹÓÃmarshalÐòÁл¯µÄ¶þ½øÖÆÊý¾Ý¸ñʽ»¹Ã»ÓÐÎĵµ»¯£¬ÔÚ²»Í¬°æ±¾µÄPythonÖУ¬marshalµÄʵÏÖ¿ÉÄܲ»Ò»Ñù¡£Ò²¾ÍÊÇ˵£¬ÓÃpython2.5ÐòÁÐΪһ¸ö¶ÔÏó£¬ÓÃpython2.6µÄ³ÌÐò·´ÐòÁл¯ËùµÃµ½µÄ¶ÔÏ󣬿ÉÄÜÓëÔ­À´µÄ¶ÔÏóÊDz»Ò»ÑùµÄ¡£µ«Õâ¸öÄ£¿é´æÔÚµÄÒâÒ壬ÕýÈçPythonÊÖ²áÖÐËù˵£ºThe marshal
module exists mainly to support reading and writing the “pseudo-compiled” code for Python modules of .pyc
files.
ÏÂÃæÊÇmarshalÄ£¿éÖж¨ÒåµÄһЩÓëÐòÁл¯/·´ÐòÁл¯Óйصĺ¯Êý£º
marshal.dump(value, file[, version])
¡¡¡¡½«ÖµÐ´Èëµ½Ò»¸ö´ò¿ªµÄÊä³öÁ÷Àï¡£²ÎÊývalue±íʾ´ýÐòÁл¯µÄÖµ¡£file±íʾ´ò¿ªµÄÊä³öÁ÷¡£Èç:ÒÔ”wb”ģʽ´ò¿ªµÄÎļþ£¬sys.stdout»òÕßos.popen¡£¶ÔÓÚһЩ²»Ö§³ÖÐòÁÐÀàµÄÀàÐÍ£¬dump·½·¨½«Å׳öValueErrorÒì³£¡£ÒªÌرð˵Ã÷һϣ¬²¢²»ÊÇËùÓÐÀàÐ͵ĶÔÏ󶼿ÉÒÔʹÓÃmarshalÄ£¿éÀ´ÐòÁл¯/·´ÐòÁл¯µÄ¡£ÔÚpython2.6ÖУ¬Ö§³ÖµÄÀàÐÍ°üÀ¨£ºNone
, integers, long integers, floating point numbers, strings, Unicode objects, tuple, list, set, dict, ºÍ code objects¡£¶ÔÓÚtuple, list, set, dictµÈ¼¯ºÏ¶ÔÏó£¬ÆäÖеÄÔªËرØÐëÒ²ÊÇÉÏÊöÀàÐÍÖ®Ò»¡£
marshal.load(file)
¡¡¡¡Ö´ÐÐÓëmarshal.dumpÏà·´µÄ²Ù×÷£¬½«¶þ½øÖÆÊý¾Ý·´ÐòÁÐΪPython¶ÔÏó¡£ÏÂÃæÊÇÒ»¸öÀý×Ó£¬ÑÝʾÕâÁ½¸ö·½·¨µÄʹÓãº


#
coding=gbk

 

import
 
marshal
,
 
sys
,
 
os

 

lst
 
=
 
[
1
,
 
(
2
,
 
"
string
"
)
,
 
{
"
key
"
:
 
"
Value
"
}
]

 

#
ÐòÁл¯µ½ÎļþÖÐ

fle
 
=
 
open
(
os
.
path
.
join
(
os
.
getcwd
(
)
,
 
'
fle
.
txt
'
)
,
 
'
wb
'
)

marshal
.
dump
(
lst
,
 
fle
)
10 
fle
.
close
(
)
11 
&nbs


Ïà¹ØÎĵµ£º

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()£¬·ñÔòÆäË ......

MoteLab£º·µ»Ø´®¿ÚÊý¾Ý´¦Àí£¨python£©

´ÓMoteLab·µ»ØµÄ´®¿ÚÊý¾Ý£¬°üº¬messages.pickleÎļþÕâÊÇMoteLabϵͳÖд®¿ÚÊÕ¼¯Êý¾ÝµÄ×ܺͣ¬µ«ÊÇÕâЩÊý¾ÝÐèÒª½âÎöºó²ÅÄܽøÐзÖÎö¡£ÏÂÃæµÄ´úÂë¾ÍÊÇÔÚpython»·¾³ÏÂÌáÈ¡messageÓÐЧÊý¾ÝµÄ´úÂë¡£
ʹÓÃÃüÁî python TestOutput.py messages.pickle
Éú³ÉµÄtest.log¾ÍÊÇ»ñµÃµÄÓÐЧÊý¾Ý
·µ»ØÊý¾ÝµÄʾÀý
1252985727.66  recei ......

£¨×ª£©Python×Ö·û´®µÄencodeÓëdecode isinstance

Ê×ÏÈÒª¸ãÇå³þ£¬×Ö·û´®ÔÚPythonÄÚ²¿µÄ±íʾÊÇunicode±àÂ룬Òò´Ë£¬ÔÚ×ö±àÂëת»»Ê±£¬Í¨³£ÐèÒªÒÔunicode×÷ΪÖмä±àÂ룬¼´ÏȽ«ÆäËû±àÂëµÄ×Ö·û´®½âÂ루decode£©³Éunicode£¬ÔÙ´Óunicode±àÂ루encode£©³ÉÁíÒ»ÖÖ±àÂë¡£
decodeµÄ×÷ÓÃÊǽ«ÆäËû±àÂëµÄ×Ö·û´®×ª»»³Éunicode±àÂ룬Èçstr1.decode('gb2312')£¬±íʾ½«gb2312±àÂëµÄ×Ö·û´®×ª»»³ ......

PythonÈëÃŵÄ36¸öÀý×Ó——15 ĬÈϲÎÊý

# 015
# ĬÈϲÎÊýµÄ±¾ÖÊÊÇ:
# ²»ÂÛÄãÊÇ·ñÌṩ¸øÎÒÕâ¸ö²ÎÊý,ÎÒ¶¼ÊÇÒªÓÃËü,
# ÄÇôÎÒ¾ÍÒªÏëºÃÔÚÄã²»ÏòÎÒÌṩ²ÎÊýµÄʱºòÎÒ¸ÃʹÓÃʲô¡£
# »òÕߣ¬ÕâÑùÀ´Àí½â£º
# ÓÐһЩ²ÎÊýÔÚÒ»°ãÇé¿öÏÂÊÇÔ¼¶¨Ë׳ɵģ¬
# µ«£¬ÔÚ¼«ÉÙÇé¿öÏ»áÓÐһЩºÜÓиöÐÔµÄÈË»á´òÆÆ´«Í³¶ø°´ÕÕ×Ô¼ºµÄÏ°¹ßÀ´×öÊÂ
def theFirstDayInAWeek(theDay = 'Sunda ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ