Pythonでシンプルなプロキシサーバーを実現するプログラム
Pythonコード:
#/bin/env python
#coding:utf-8
import socket,select,sys,time
import thread
s_list ...
pythonでディレクトリをコピー操作
Pythonコード:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import time
sourceDir = ...
Pythonでテキストファイルを結合する方法
Pythonコード:
import sys,os,msvcrt
def join(in_filenames, out_filename):
out_file = open(out_filename, ...
Pythonでunicodeのファイルを読み込み
サンプルコード:
#coding=utf-8
import os
import codecs
def writefile(fn, v_ls):
f = codecs.open(fn, ...
Pythonのzipfileモジュールの利用方法メモ
Pythonコード
1.方法1:
import zipfile
z = zipfile.ZipFile(filename, ‘r’) #第二パラメータにrでzipファイルを読み取 ...
Pythonで大量ランダムmd5を生成する
サンプルコード:
import string, random
look_set = string.ascii_letters + string.digits
md5_len = 32
tmp_md5_l ...
Pythonでiniファイルの読み書き方法
サンプルコード:
#coding=utf-8
import ConfigParser
def writeConfig(filename):
config = ConfigParser.ConfigP ...
PythonでMySQLとMSSQLを接続する
サンプルコード:
host = ‘127.0.0.1’
user = ‘pythonadmin’
pwd = ‘startnews24’ ...
Python 文字をエンコードするプログラム
サンプルコード:
#coding=utf-8
import sys
print sys.getdefaultencoding()
u1 = ‘東京品川区’
print ...
PythonのHTMLParserでHTMLを解析する
Pythonコード:
#-*- encoding: utf-8 -*-
import HTMLParser
class MyParser(HTMLParser.HTMLParser):
def __ ...
PythonでConfigParserモジュールを操作する
Pythonコード:
#-*- encoding: utf-8 -*-
import ConfigParser
import string, os, sys
cf = ConfigParser.Co ...
Pythonのmysqldbの使い方メモ
サンプルコード:
#-*- encoding: utf-8 -*-
import os, sys, string
import MySQLdb
# データベースに接続
try:
Pythonのsqlite3ライブラリでデータベースを操作する
サンプルコード:
#-*- encoding:utf-8 -*-
import sqlite3
conn = sqlite3.connect(“D:\startnews24.db” ...
Pythonでbase64エンコードとデコードサンプルプログラム
サンプルコード1:
#-*- encoding:utf8-*-
import base64
import StringIO
a = “this is a test”
Pythonのquopriモジュールの使い方
サンプルコード:
#-*- encoding: utf-8 -*-
import quopri
a = “唯一のテスト”
b = quopri.encodestring( ...
Python threadingモジュールの利用方法2
サンプルコード:
#-*- encoding: utf-8 -*-
import threading
import time
class Test(threading.Thread):
Python threadingモジュールの利用方法1
サンプルコード:
#-*- encoding: utf-8-*-
import string, threading, time
def thread_main(a):
global count, m ...
Pythonでcssファイルをフォーマットする
サンプルコード:
import string, sys
import re, StringIO
TAB=4
def format(ss):
f = open (ss, “r ...