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

PythonÕýÔò±í´ïʽ

ÕýÔò±í´ïʽÊǸöħ¹í£¬Ò²ÊǸöÌìʹ¡£ÔÚÄãûÓÐÕÆÎÕËü֮ǰ£¬ËüÊÇħ¹í£¬ÔÚÄãÕÆÎÕËüºó£¬ËüÊÇÌìʹ£¬µ«ÊÇ£¬Ê±
²»Ê±»¹ÊÇÒªÌø³öÀ´£¬¸øÄãµ÷Ƥµ·µ°Ò»·¬¡£


Ò»¸öÕýÔò±í´ïʽ¾ÍÊÇÓÉÆÕͨ×Ö·ûÒÔ¼°ÌØÊâ×Ö·û×é³ÉµÄÎÄ×Öģʽ£¬¸ÃģʽÃèÊöÔÚ²éÕÒÎÄ×ÖÖ÷Ìåʱ´ý
Æ¥ÅäµÄÒ»¸ö»ò¶à¸ö×Ö·û´®¡£ÕýÔò±í´ïʽ×÷Ϊһ¸öÄ£°å£¬½«Ä³¸ö×Ö·ûģʽÓëËùËÑË÷µÄ×Ö·û´®½øÐÐÆ¥Å䣬²¢ÄÜÌáÈ¡³öÆ¥ÅäµÄ½á¹û¡£ËüÊÇËÑË÷¡¢Ìæ»»ºÍ½âÎö¸´ÔÓ×Ö·ûģʽµÄ
Ò»ÖÖÇ¿´ó¶ø±ê×¼µÄ·½·¨¡£

ÕýÔò±í´ïʽÓÐ×Å×ÜÌå¹æ·¶µÄÒ»Ì×Óï·¨£¬µ«Êǵ½Á˸÷ÖÖÓïÑÔÖУ¬ÓÖ»áÓÐʹÓÃÉϵÄÉÔ΢²»Í¬£¬Ö÷ÒªÊDZí´ïʽµÄϸ
΢Óï·¨±í´ï£¬»¹ÓÐÓïÑÔµÄÆ¥ÅäÀàºÍ·½·¨µÄ²»Í¬¡£

PythonµÄËùÓÐÀà¿â¶¼ÔÚre°üÖУ¬ºÍjava
1.4ÒÔºóµÄ²»Í¬£¬StringµÄ¸÷¸ö·½·¨£¬findºÍreplace¶¼²»×Ô×öÖ÷ÕŵÄȥʹÓÃÕýÔò±í´ïʽ£¬¶øÊÇʹÓüòµ¥µÄ×Ö·û´®·½Ê½¡£ÕâµãÎұȽÏÐÀÉÍ£¬ÓÐʱ
ºòÖ»ÊÇ×öһЩ¼òµ¥µÄÌæ»»£¬²»ÒªÅªÕýÔò±í´ïʽÕâôÂé·³£¬Ò²ÈÃÐÂÊÖÃÇÃþ²»×ű±£¬Ìæ»»Á½¸ö×Ö·û¾ÍҪȥÁ˽âÕýÔò±í´ïʽÕâô¿äÕÅ¡£

¹¤¾ß
   
PythonÓÐÒ»¸ö·Ç³£ºÃµÄÕýÔò±í´ïʽ¸¨Öúµ÷ÊÔ¹¤¾ß£ºKodos¡£ÓÐWindows°æ±¾£¬ÌṩÁ˶ÔÕýÔò±í´ïʽµÄ·½±ãµÄʵʱµ÷ÊÔ¹¦ÄÜ£¬½¨ÒéѧϰÕýÔò±í´ïʽǰ
Ò»¶¨ÒªÏÂÔØ£º
     http://kodos.sourceforge.net/
   
 
Ó¦Óó¡¾°£º
 ×ª»»urlΪ·¾¶Ãû
import
 re
articleUrl =
"http://pp.sohu.com/yule/photoview-44789795.html#44789795"
path =
re.sub("http://|https://", "", articleUrl)
path =
re.sub("[?&.=#-]", "_", path)
path
   
'pp_sohu_com/yule/photoview_44789795_html_44789795'
  
      
²ÉÓÃÕâÖÖÌæ»»·½Ê½£¬Ëæʱ·¢ÏÖurlÖÐÓÐзǷ¨×Ö·û£¬Ìí¼Óµ½[]ÖоͿÉÒÔÁË¡£[]±íʾ×Ö·û¼¯£¬ÔÚ[]ÆäÖеÄÈÎÒâ×Ö·û£¬¶¼»á±»Æ¥Åäµ½
      
 
2.  ÌáÈ¡htmlÒ³ÃæÖÐimg±êÇ©µÄsrcÊôÐÔ
    
import
 re
    
import
 urllib
    imgSrcPattern 
=
 r
'''
<img\s*src\s*="?(\S+)"?
'''
    
    pageUrl 
=
 
'
http://pp.sohu.com/yule/photoview-44789


Ïà¹ØÎĵµ£º

python ±Ê¼Ç for loop and extend, append

list.append(item)
list.extend(sequence)
http://docs.python.org/tutorial/datastructures.html
http://docs.python.org/library/functions.html Õ⼸Ìì¿´Ò»ÏÂ
python howto
¶÷¡£python documentation ȷʵºÜºÃºÜÇ¿´ó°¡£¡
list.append(x)Add an item to the end of the list; equivalent to a[len(a):]&n ......

ÓÃEclipse±àÒëÏòsqliteÊý¾Ý¿â²åÈëÊý¾ÝµÄpython³ÌÐò

½ñÌìÓöµ½ÁËÂé·³£º
      ÓÃEclipse±àÒëpythonÏòsqliteÊý¾Ý¿â²åÈëÊý¾Ý×ÜÊÇÌáʾ±àÂëµÄÎÊÌ⣬ÎÒÉèÖÃÁËEclipseµÄworkspaceÓÃutf-8±àÂ뻹ÊDz»ÐÐ
µ«ÊÇÓÃEclipseдµÄ³ÌÐò±£´æÔÙÓÃIDLE´ò¿ªÈ´ÄܱàÒ룬Ææ¹ÖÁË
ÎÒ¿¼Âǵ½¿ÉÄÜÊÇÅäÖõÄÔ­Òò£¬ÕÒÕÒ±éÁËËùÓеÄÅäÖ㬶¼Ã»ÓÐÎÊÌ⣬°üÀ¨¹¤³ÌÎļþ
×îºóÎÒÓÃxvi32´ò¿ ......

Python Get Key press

refer from:  http://www.daniweb.com/forums/thread115282.html#
python
Syntax
(Toggle Plain Text
)

# respond to a key
without the need to press
enter
 
import
Tkinter
as tk
 
def
keypress(
event)
:
if
event.keysym
== 'Escape'
:
root.destroy
......

pythonÖÐpackage»úÖƵÄÁ½ÖÖʵÏÖ·½Ê½


µ±Ö´ÐÐimport
moduleʱ£¬½âÊÍÆ÷»á¸ù¾ÝÏÂÃæµÄËÑË÷·¾¶£¬ËÑË÷module1.pyÎļþ¡£
1) µ±Ç°¹¤×÷Ŀ¼
2) PYTHONPATHÖеÄĿ¼
3) Python°²×°Ä¿Â¼
(/usr/local/lib/python)
ÊÂʵÉÏ£¬Ä£¿éËÑË÷ÊÇÔÚ±£´æÔÚsys.pathÕâ¸öÈ«¾Ö±äÁ¿ÖеÄĿ¼ÁбíÖнøÐÐËÑË÷¡£
sys.path»áÔÚ½âÊÍÆ÷¿ªÊ¼Ö´ÐÐʱ±»³õʼ»¯³É°üº¬£º
1)µ±Ç°¹¤×÷Ŀ¼
2) PYT ......

python »ñÈ¡±¾»úip

>>> from socket import socket, SOCK_DGRAM, AF_INET
>>> s = socket(AF_INET, SOCK_DGRAM)
>>> s.connect(('google.com', 0))
>>> s.getsockname()
('192.168.1.113', 43711) 
Linux:
import socket
import fcntl
import struct
def get_ip_address(ifname):
s = ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ