python¶ÁдÎļþ
1.open
ʹÓÃopen´ò¿ªÎļþºóÒ»¶¨Òª¼ÇµÃµ÷ÓÃÎļþ¶ÔÏóµÄclose()·½·¨¡£±ÈÈç¿ÉÒÔÓÃtry/finallyÓï¾äÀ´È·±£×îºóÄܹرÕÎļþ¡£
file_object = open('thefile.txt')
try:
all_the_text = file_object.read( )
finally:
file_object.close( )
×¢£º²»ÄÜ°ÑopenÓï¾ä·ÅÔÚtry¿éÀÒòΪµ±´ò¿ªÎļþ³öÏÖÒ쳣ʱ£¬Îļþ¶ÔÏófile_objectÎÞ·¨Ö´ÐÐclose()·½·¨¡£
2.¶ÁÎļþ
¶ÁÎı¾Îļþ
input = open('data', 'r')
#µÚ¶þ¸ö²ÎÊýĬÈÏΪr
input = open('data')
¶Á¶þ½øÖÆÎļþ
input = open('data', 'rb')
¶ÁÈ¡ËùÓÐÄÚÈÝ
file_object = open('thefile.txt')
try:
all_the_text = file_object.read( )
finally:
file_object.close( )
¶Á¹Ì¶¨×Ö½Ú
file_object = open('abinfile', 'rb')
try:
while True:
chunk = file_object.read(100)
if not chunk:
break
do_something_with(chunk)
finally:
file_object.close( )
¶ÁÿÐÐ
list_of_all_the_lines = file_object.readlines( )
Èç¹ûÎļþÊÇÎı¾Îļþ£¬»¹¿ÉÒÔÖ±½Ó±éÀúÎļþ¶ÔÏó»ñȡÿÐУº
for line in file_object:
process line
3.дÎļþ
дÎı¾Îļþ
output = open('data', 'w')
д¶þ½øÖÆÎļþ
output = open('data', 'wb')
×·¼ÓдÎļþ
output = open('data', 'w+')
дÊý¾Ý
file_object = open('thefile.txt', 'w')
file_object.write(all_the_text)
file_object.close( )
дÈë¶àÐÐ
file_object.writelines(list_of_text_strings)
×¢Ò⣬µ÷ÓÃwritelinesдÈë¶àÐÐÔÚÐÔÄÜÉÏ»á±ÈʹÓÃwriteÒ»´ÎÐÔдÈëÒª¸ß¡£
ÔÚ´¦ÀíÈÕÖ¾ÎļþµÄʱºò£¬³£³£»áÓöµ½ÕâÑùµÄÇé¿ö£ºÈÕÖ¾Îļþ¾Þ´ó£¬²»¿
Ïà¹ØÎĵµ£º
import urllib2
import time
import socket
from datetime import datetime
from thread_pool import *
def main():
url_list = {"sina":"http://www.sina.com.cn",
"sohu":"http://www.sohu.com",
"yahoo":"http://www.yahoo.com",
"xiaonei":"http://www.x ......
1£® Ê×ÏȾÍÊÇÔÚ±àÒëÆ÷ÖаÑpython°²×°Ä¿Â¼include/Óëlibs/¼ÓÈ룬¶ÔÓÚÕâµãÎÒÔÚvc6ÖпÉÒÔ£¬µ«ÊÇÔÚdev c++Öм´Ê¹¼ÓÈëÁ˱àÒëÒ²»á³ö´í£¬ËµÕÒ²»µ½pythonÍ·Îļþ£¬Õâµã±È½ÏÓôÃÆ£¬²»¹ý¿¼Âǵ½Ò»°ãwindows±à³Ì¶¼ÓõÄÊÇvc£¬ËùÒÔ²¢Ã»ÓÐʲôӰÏì°É£¡£¡£¡
È»ºóÓÃ#include <Python.h>¾Í¿ÉÒÔ°ÑpythonµÄÖ÷Í·Îļþ°üº¬½øÀ´ÁË¡£
µ«Ê ......
1£¬ÏÂÔØorg.python.pydev.feature-1.5.0.1251989166.zip http://sourceforge.net/projects/pydev/files/
2£¬°²×°²å¼þµ½eclipse
3£¬ÖØÆôeclipse
×¢Ò⣺ʹÓÃ1.5.6°æ±¾pydev²å¼þ£¬´´½¨python¹¤³Ì»á±¨´í£¬Ê¹ÓÃ1.5.0°æ±¾ÎÞ´ËÎÊÌâ¡£ ......
ÐèÒªÏÈ°²×°libxml2-devel libxslt-develÕâÁ½¸örpm°ü£¬Èç¹ûʹÓ÷ÇrootÓû§°²×°£¬¿ÉÒÔÏÂÔØlibxml2ºÍlibxsltµÄÔ´´úÂë½øÐа²×°¡£ libxml2-devel¡¢libxslt-devel×°ºÃºó£¬½âѹlxmlµÄ°ü£¬Çл»µ½Õâ¸ö°üµÄ·¾¶¡£
¼ÓÈëCFLAGS½øÐбàÒëºÍ°²×°£¬ÔÚshellÏÂÒÀ´ÎÊäÈëÈçÏÂÃüÁ CFLAGS=-I/usr/include/libxml2:/usr/include/libxslt/ ......
ÕÛÌÚ¼ÆËã»ú£¬±»¼ÆËã»úÕÛÌÚ£¬Ç°Ç°ºóºóÒ²ÓÐÊ®¼¸Äê¡£
×î¿É±¯µÄÊǾÓȻһÎÞËù³É£¬ËäÈ»½ö½ö³öÓÚÐËȤ£¬²¢ÎÞ¹¤×÷֮ѹÁ¦£¬µ«ÊÇÕâÖÖ´ìÕÛ¸ÐȷʵÊÇʵ´òʵµÄ¡£
ÒѾ¼Ç²»ÆðÊÇÄÄÒ»ÌìÁË£¬ºÃÏñͻȻ¾ÍÖªµÀÁËpythonµÄ´æÔÚ£¬´Ó×î³õµÄ²»¾Ò⣬µ½Ô½À´Ô½Ï²°®£¬ÎÒÒ»²½²½µÄÏòpython¿¿½ü¡£
ÎÒϲ»¶Python£¬ÕâÊÇÒ»¸öÊÂʵ£¬ÎÒ׫´ ......