Python ÖÐÎÄ×Ö·û´®µÄ½ØÈ¡
def
subString
(s,
length):
us = unicode(s, 'utf-8
')
gs =
us.encode('gb2312
')
n = int(length)
t = gs[:n]
while True
:
try
:
unicode(t, 'gbk
')
break
except
:
n -= 1
t = gs[:n]
return
t.decode('gb2312
')
Ïà¹ØÎĵµ£º
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
......
ǰһƪÎÄÕÂдµÄÔÚAPACHE°²×°MOD_PYTHONµÄ¾¹ý,Æäʵͦ¼òµ¥,¾ÍÊÇ°æ±¾²»¼æÈݵÄÎÊÌâ.Õâ´ÎÎÒ´ó¸Å˵ϲ¿ÊðDJANGOµÄ¹ý³Ì.
ÏÈÐÞ¸ÄAPACHEÅäÖÃÎļþ,ʹÆä¼ÓÔØmod_pythonÄ£¿é
LoadModule python_module libexec/mod_python.so
ÔËÐÐÃüÁî²é¿´
bin/httpd -M¿ÉÒÔ¿´µ½
python_module (shared)
Syntax OK
˵Ã÷apacheÒѾ³É¹¦¼Ó ......
½ñÌìÊǵڶþÌì×Ô¼º¿´¹ØÓÚPythonÁË£¬¿´¼ûÒ»¸öPython2дµÄ°Ù¶È´Êµä£¬ÎÒÒ²ÓÃPython 3 дÁËÒ»¸ö¡£ÕæµÄºÜСÇÉ£¬ºÇºÇ£¬ºÜºÃµÄÓïÑÔ¡£
²»ÖªµÀÔõôÉÏ´«´úÂë¸ñʽµÄ£¬¾ÍÉÏ´«Îı¾ÁË£º
# -*- coding: utf8 -*-
import urllib.parse
import urllib.request
def search(word):
#word = input("ÊäÈëÄãÒª²éѯµÄ ......
¹ØÓÚPython£¬±¾È˲»Ïë¶à˵ÁË£¬Èç¹û²»ÖªµÀʲôÊÇPython£¬¿ÉÒÔ¿´¡¶Ê²Ã´ÊÇPython
£¿¡·Ò»ÎÄ¡£Python¿ÉÒÔ¿ª·¢CGI³ÌÐò£¬ÄÇôÔÚApacheÏÂÓ¦ÈçºÎÅäÖÃÄØ£¿±¾ÎÄÖ»½²ÊöÁËÈçºÎ
ÒÔCGI·½Ê½ÅäÖÃApache£¬Ê¹ÆäÖ§³ÖPython³ÌÐò¡£ÆäËü·½Ê½£¬Èçmod_pythonÔò²»ÔÚÌÖÂÛ·¶Î§
(ÆäʵÊÇûÅä³É¹¦:-)¡£ÎÒËùʹÓõÄϵͳ»·¾³ÎªWindows 2000, Apache 1.3.19£ ......