ÓÃPythonдµÄͼƬ֩ÖëÈË
дÁ˸öͼƬ֩ÖëÈËÍæÍ棬ץÁ˼¸¸öÍøÒ³ÊÔÊÔ£¬¸Ð¾õ²»²»´í¡£ºËÐĵĴúÂë¿ÉÄÜ20ÐÐÒ²²»µ½£¬¼ò½àÃ÷ÁË£¬ÎûÎû¡£·Ï»°ÉÙ˵£¬´ä»¨£¬ÉÏ´úÂë~~
#coding=utf-8
import os
import sys
import re
import urllib
URL_REG = re.compile(r'(http://[^/\\]+)', re.I)
IMG_REG = re.compile(r'<img[^>]*?src=([\'"])([^\1]*?)\1', re.I)
def download(dir, url):
'''ÏÂÔØÍøÒ³ÖеÄͼƬ
@dir ±£´æµ½±¾µØµÄ·¾¶
@url ÍøÒ³url
'''
global URL_REG, IMG_REG
m = URL_REG.match(url)
if not m:
print '[Error]Invalid URL: ', url
return
host = m.group(1)
if not os.path.isdir(dir):
os.mkdir(dir)
# »ñÈ¡html,ÌáȡͼƬurl
html = urllib.urlopen(url).read()
imgs = [item[1].lower() for item in IMG_REG.findall(html)]
f = lambda path: path if path.startswith('http://') else \
host + path if path.startswith('/') else url + '/' + path
imgs = list(set(map(f, imgs)))
print '[Info]Find %d images.' % len(imgs)
# ÏÂÔØͼƬ
for idx, img in enumerate(imgs):
name = img.split('/')[-1]
path = os.path.join(dir, name)
try:
print '[Info]Download(%d): %s'% (idx + 1, img)
urllib.urlretrieve(img, path)
except:
print "[Error]Cant't download(%d): %s" % (idx + 1, img)
def main():
if len(sys.argv) != 3:
print 'Invalid argument count.'
return
dir, url = sys.argv[1:]
download(dir, url)
if __name__ == '__main__':
# download('D:\\Imgs', 'http://www.163.com')
main()
Ïà¹ØÎĵµ£º
Ê×ÏÈתÔØÒ»¶Î¹ØÓÚÍƼöµÄѧϰpythonµÄÊé¼®£¨ÔÎÄÁ´½Ó£©£º
1.ѧϰ¡¶A Byte of Python¡·£¬ÖÐÎÄÒëÃûΪ¡¶Python¼òÃ÷½Ì³Ì£¨pdfÏÂÔصØÖ·£©¡·£¬È«ÊéÏÂÀ´Ö»ÓÐ100¶àÒ³£¬¼òµ¥¸ÉÁ·£¬Í¨Ë×Ò׶®£¬Êǹ«ÈϵÄPythonÈëÃŽ̡̳£ÎÒËäȻϵ½ÁË¡¶Python¼òÃ÷½Ì³Ì¡·pdf°æ£¬µ«ÊǾõµÃÆäÖеĴúÂë¿ÉÄÜÊÇÒòΪÒëÕßת»»ÎĵµÀàÐ͵ÄÔÒò£¬¸ñʽ±äµÃºÜÂÒ£¬ËùÒÔ× ......
#¶ÑÅÅÐò
def Heapify(mylist, start, end):
left = 0
right = 0
maxv = 0
left = start * 2
right = start * 2 + 1
while left <= end:
maxv = left
if right <= end:
if mylist[left] < mylist[right]:
maxv = right
......
Çé¾°Ò»£º
ÔÚÎļþ¼ÐÀïÓÐÁùÊ®¶à¸öRM¸ñʽµÄÊÓƵÎļþ£¬ÎÒÏÖÔÚÐèÒª°ÑËüÃǵÄÎļþÃû¶¼ÌáÈ¡³öÀ´£¬²¢È¥µôÎļþµÄÀ©Õ¹Ãû£¬ÒÔ±ã·Åµ½ÐèÒªµÄÍøÒ³Àï¡£
Ó¦¸ÃÓÐʲôÈí¼þ¿ÉÒÔÍê³ÉÕâ¸ö¼òµ¥µÄÒªÇ󣬿ÉÊÇһʱ¼äµ½ÄÄÀïÈ¥ÕÒÕâ ÑùÒ»¸ö·ûºÏÒªÇóµÄÈí¼þÄØ£¿×ܲ»ÄÜÊÖ¹¤Íê³É°Ñ¡£ÔÚLinuxÉÏÓÃÇ¿´óµÄshell½Å±¾Ó¦¸ÃÒ²¿ÉÒÔÍê³É£¬¿ÉÊÇʹÓÃWindowsµÄÅóÓÑÄØ£¿Æä ......
ÔÚWindowsÀï´î½¨PythonµÄGTK+»·¾³»¹ÊDZȽÏÂé·³µÄÓÐÒÔϼ¸¸ö×¢ÒâÊÂÏî
1¡¢PyGTKÍøÕ¾ÉÏϵİü£¬¿ÉÄÜûÓÐGladeÀࣨLib\site-packages\gtk-2.0\gtkĿ¼ÏÂûÓÐglade.pyd£©£¬Èç¹ûûÓÐÕâ¸öÀàÄã¾ÍÎÞ·¨ÔÚ³ÌÐòÀïµ¼ÈëGlade¹¤¾ß´´½¨µÄxml£¬ÊÖд½çÃ滹ÊÇͦÂé·³µÄ¡£
2¡¢GTKÍøÕ¾ÉϵÄGTK°ü£¬Ã»ÓаüÀ¨GladeµÄDLLÎļþ£¬»¹ÊÇÎÞ·¨¶ÁÈëGladeµÄxm ......
ʱ³£¼ûµ½Ò»Ð©ºÃµÄPythonÄ£¿é£¬Èç¹û²»Ëæʱ¼ÇÏ£¬µÈÓõÄʱºòÓÖÊÇÒ»ÕóÂÒ·£¬ºÃÔÚPythonÒýÓÃÒ»¸öÄ£¿é¼«Æä·½±ã£¬OK£¬·Ï»°ÉÙ˵£º
1. decimal
±ê׼ģ¿é£¬2.4ÒýÈ룬ÓÃÓÚ¸¡µãÊýµÄ¾«È·±íʾ£º
>>> 0.1 + 0.1 + 0.1 - 0.3
5.5511151231257827e-17
>>> from decimal import Decimal
>>> def _(x): retu ......