pythonµÄwiki ÁÐ×Ó.
#coding=utf-8
from newtest.wiki.models import WiKi
from django.template import loader, Context
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
def index(request, pagename=""):
"""ÏÔʾÕý³£Ò³Ã棬¶ÔÒ³ÃæµÄÎÄ×Ö×öÌØÊâµÄÁ´½Ó´¦Àí"""
if pagename:
#²éÕÒÊÇ·ñÒѾ´æÔÚÒ³Ãæ
pages = WiKi.objects.filter(pagename=pagename)
if pages:
#´æÔÚÔòµ÷ÓÃÒ³ÃæÄ£°å½øÐÐÏÔʾ
return process('wiki/page.html', pages[0])
else:
#²»´æÔÚÔò½øÈë±à¼»Ãæ
return render_to_response('wiki/edit.html', {'pagename':pagename})
else:
page = WiKi.objects.get(pagename='FrontPage')
return process('wiki/page.html', page)
def edit(request, pagename):
"""ÏÔʾ±à¼´æÔÚÒ³Ãæ"""
page = WiKi.objects.get(pagename=pagename)
return render_to_response('wiki/edit.html', {'pagename':pagename, 'content':page.content})
def save(request, pagename):
"""±£´æÒ³ÃæÄÚÈÝ£¬ÀÏÒ³Ãæ½øÐÐÄÚÈÝÌæ»»£¬ÐÂÒ³ÃæÉú³ÉмǼ"""
content = request.POST['content']
pages = WiKi.objects.filter(pagename=pagename)
if pages:
pages[0].content = content
pages[0].save()
else:
page = WiKi(pagename=pagename, content=content)
page.save()
return HttpResponseRedirect("/wiki/%s" % pagename)
import re
r = re.compile(r'\b(([A-Z]+[a-z]+){2,})\b')
def process(template, page):
"""´¦ÀíÒ³ÃæÁ´½Ó£¬²¢ÇÒ½«»Ø³µ·ûתΪ"""
t = loader.get_template(template)
content = r.sub(r'<a href="/wiki/\1" mce_href="wiki/\1">\1</a>', page.content)
#content=re.sub(r'\b(([A-Z]+[a-z]+){2,})\b',r'<a href="/wiki/\1" mce_href="wiki/\1">\1</a>',page.content)
content = re.sub(r'[\r\n]+', '<br>', content)
c = Context({'pagename':page.pagename, 'content':content},autoescape=False)
return HttpResponse(t.render(c))
views.py
from django.conf.urls.defa
Ïà¹ØÎĵµ£º
$ ×Ö·û´®µÄĩβ
^ ×Ö·û´®µÄ¿ªÊ¼
\b ×Ö·ûµÄ±ß½ç
ǰ׺t ×Ö·û´®Öеķ´Ð±Ïߣ¨ËùÓÐ×Ö·û£©²»×ªÒå
? ¿ÉÑ¡µØÆ¥Åä(λÓÚ֮ǰµÄ)µ¥¸ö×Ö·û
() ¸Ä±äÓÅÏȼ¶£¬×÷Ϊһ¸öÕûÌ壬һ¸ö×é
| »òÕß
(A|B) ¾«È·Æ¥ÅäA»òBÖеÄÒ»¸ö
{n,m} Æ¥Å䣨λÓÚ֮ǰµÄ×Ö·û£©nµ½m´Î
VERBOSE ......
ѧϰpython±¾¾ÍÊÇÒµÓàÖ®ºÃ£¡Ê鱾ɶµÄ£¬¶¼ÎÞ´Ó˵Æð¡£ËùÒÔż¶ûÅöµ½Ò»¸öºÃµÄÄ£¿é£¬¾ÍÒªÔÚ²©¿ÍÖмǼһÏ£¬ÒÔ±ãÈÕºóÖ®Óá£ÊÇÒÔ¸ßÊÖÖ±½ÓµÄÆ®¹ý¡£ÏÂÃæÇÐÈëÕýÌâ¡£
globÊÇpython×Ô¼º´øµÄÒ»¸öÎļþ²Ù×÷Ïà¹ØÄ£¿é£¬ÄÚÈÝÒ²²»¶à£¬ÓÃËü¿ÉÒÔ²éÕÒ·ûºÏ×Ô¼ºÄ¿µÄµÄÎļþ£¬¾ÍÀàËÆÓÚWindowsϵÄÎļþËÑË÷£¬¶øÇÒÒ²Ö§³ÖͨÅä·û£¬*,?,[]Õ ......
Python lists have a built-in sort() method that modifies the list in-place and a sorted() built-in function that builds a new sorted list from an iterable.
There are many ways to use them to sort data and there doesn't appear to be a single, central place in the various man ......
client:
import socket, sys
if __name__ == '__main__':
#´¦Àí²ÎÊý
argv = sys.argv
if (len(argv)!=3) or (len(argv)==2 and argv[1]=='/?'):
print '>>>Useage:', argv[0], '<address> < ......
¿Í»§¸øÒ»¶ÑͼƬҪ´«µ½ºǫ́£¬Í¼Æ¬Ì«´óÁË£¬ÉÏ°ÙÕÅͼÓÃphotoshop¸ÄÌ«Âý£¬¾ÍÏëµ½ÓÃpythonд¸ö¼òµ¥µÄÅú´¦Àí¡£¹¦Äܼòµ¥¾ÍÊÇ°ÑÔͼ°´±ÈÀýËõС£¬´úÂë¸ü¼òµ¥ 20¶àÐС£
# -*- coding: cp936 -*-
import Image
import glob, os
#ͼƬÅú´¦Àí
def timage():
for files in glob.glob('D:\\1\\*.JPG'):
filepath,filena ......