• python解決八皇后算法 代碼段

    python解決經典算法八皇后問題,在棋盤上放置8個皇后,而不讓她們之間互相攻擊。 import sys, itertools from sets import Set NUM_QUEENS = 8 MAX

    fwwc 2015-01-08   1670   0
    Python  

    python操作mysql數據庫代碼 代碼段

    python操作mysql數據庫的相關操作實例 # -*- coding: utf-8 -*- #python operate mysql database import MySQLdb #數據庫名稱

    gcmc 2015-01-11   4725   0
    Python  

    python 去除html標簽的代碼 代碼段

    #! /usr/bin/python # -*- coding:utf-8 -*- ''' Created on 2013-12-18 @author: Java ''' import re from

    em7 2015-01-22   1807   0
    Python  

    python轉換字符集 代碼段

    def URLtoUTF8(string): """""" g_code_type = ['utf-8', 'utf8', 'gb18030', 'gb2312', 'gbk', 'ISO-8859-2'] try: tmp = urllib.unquote(str(string)) code = chardet.detect(tmp)['encoding'] try: g_code_type.i

    pythopen 2015-01-22   1154   0
    Python  

    Python3 圖片打水印 代碼段

    from PIL import Image, ImageDraw, ImageFont import os def water_work(img): x, y = img.size textx = int(x*1.5) texty = int(y*1.5) blank = Image.new('RGB', (textx, texty), 'white') draw = ImageDraw.Draw

    pe6y 2015-03-17   1256   0
    Python  

    python socket 輕量級服務器 代碼段

    使用非阻塞加多線程的方式,輕松實現python網絡服務器框架。 工作總結 由于Python天生的優點,特別適用于快速實現功能。 #!/usr/bin/python2.7 import sys import

    fpcm 2015-04-30   2132   0
    Python  

    python 多線程優先隊列Queue 代碼段

    隊列為空返回True否則返回False full(): 隊列已滿返回True,負責返回False #!/usr/bin/python import Queue import threading import time exitFlag

    pythopen 2015-05-14   4285   0
    Python  

    python獲取當天日期 代碼段

    import datetime # Get a date object today = datetime.date.today() # General functions print "Year: %d" % today.year print "Month: %d" % today.month print "Day: %d" % today.day print "Weekday: %d" % to

    mn6e 2015-05-24   1101   0
    Python  

    Python實現文件的壓縮及解壓 代碼段

    當我們遇到大量小文件的傳輸時,一般會涉及到文件的壓縮和解壓,下面對zip的壓縮解壓直接上代碼 壓縮: def zip_dir(dirname,zipfilename): """ | ##@函數目的: 壓縮指定目錄為zip文件 | ##@參數說明:dirname為指定的目錄,zipfilename為壓縮后的zip文件路徑 | ##@返回值:無 | ##@函數邏輯: """ filelist = []

    ybw8 2015-06-04   1236   0
    Python  

    python編寫簡單抽獎系統 代碼段

    #!/usr/bin/env python #coding=utf-8 from Tkinter import * import time import random class App: def __init__(self

    pykde 2015-06-15   3215   0
    Python  

    python統計cpu的利用率 代碼段

    python統計cpu的利用率 #-*-coding=utf-8-*- import win32pdh import time # Counter paths PROCESSOR_PERCENT =

    mxw8 2015-06-18   1062   0
    Python  

    python xmlrpc實現文件傳輸的代碼 代碼段

    SimpleXMLRPCServer import xmlrpclib def python_logo(): handle = open("python_logo.jpg",'rb') return xmlrpclib

    mxw8 2015-06-18   1893   0
    Python  

    python讀取ini配置文件 代碼段

    #!/usr/bin/python # -*- coding: iso-8859-1 -*- import ConfigParser # Open a configuration file config

    jopen 2015-06-24   1290   0
    Python  

    python生成字母驗證圖片 代碼段

    from PILimport Image, ImageDraw, ImageFont import random def generate_authenticode(): letters = random.sample('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',4) width = 100 height = 4

    jopen 2015-06-28   1187   0
    Python  

    python改變圖片尺寸 代碼段

    from PIL import Image def change_image_size(image_path,size=(600,600)): img = Image.open(image_path) img = img.resize(size) #img.thumbnail(size,Image.ANTIALIAS) //縮放 img.save('./result.jpg') change_im

    jopen 2015-06-28   2255   0
    Python  

    python事件驅動模型的代碼 代碼段

    __author__ = 'Administrator' #/usr/env/bin python ''' this is document ''' class Event(object): ''' 事件初始化的一個方式

    jopen 2015-07-14   1062   0
    Python  

    python封裝的GET&POST請求 代碼段

    #coding=utf-8 import os import urllib import httplib import requests import json def get_page_content(baseUrl, path, params, headers, type = 'get'): try: httpClient = httplib.HTTPConnection(baseUrl, 8

    jopen 2015-07-10   1828   0
    Python  

    python urllib2 超時處理實例 代碼段

    python的urllib2包的timeout異常需要通過socket.timeout異常來捕獲,如下實例: import urllib2 import socket class MyException(Exception):

    gd7g 2015-08-12   1112   0
    C/C++  

    Python SMTP 發送純文本 代碼段

    import smtplib import getpass msg = MIMEText('這是一封來自python的純文本郵件','plain','utf-8') from_addr = '發件人郵箱地址' password

    jopen 2015-08-18   911   0
    Python  

    python構造函數示例 代碼段

    # class Critter(object): '''A virtual pet''' def __init__(self): print 'A new critter has been born!' def talk(self): print '\nHi. I'm an instance of class Critter.' # main crit1 = Critter() crit2 = C

    nf83 2015-08-26   752   0
    Python  
    1 2 3 4 5 6 7 8 9 10

    關鍵詞

    Python C/C++

  • sesese色