Time of Update: 2016-06-06
mdb格式檔案可以通過mdbtools工具將內中包含的每張表匯出到csv格式檔案。由於access資料庫和postgresQL資料庫格式上會存在不通性,所以使用python的檔案處理,將所得csv檔案修改成正確、能識別的格式。匯入指令碼說明(此指令碼運行於linux):1.apt-get install mdbtools,安裝mdbtools工具2.將mdb 檔案拷貝到linux虛擬機器中,修改指令碼中mdb檔案目錄‘dir'3.修改伺服器及資料庫配置4.執行指令碼 代碼如下:# -*-
Time of Update: 2016-06-06
分析數字中經常是3個數字一組,之後跟一個逗號,因此規律為:***,***,***正則式 代碼如下:[a-z]+,[a-z]? 代碼如下:import resen = "abc,123,456,789,mnp"p = re.compile("\d+,\d+?")for com in p.finditer(sen): mm = com.group() print "hi:", mm print "sen_before:", sen sen = sen.replace(mm,
Time of Update: 2016-06-06
用git來管理工程的開發,git log是非常有用的‘曆史'資料,需求就是來自這裡,我們希望能對git log有一個定製性強的過濾。此段指令碼就是在完成這種類型的任務。對於一個repo所有branch中的commit,指令碼將會把message中存在BUG ID的一類commits給提取整理出來,並提供了額外的search_key, 用於定製過濾。 代碼如下:# -*- coding: utf-8 -*-# created by vince67 Feb.2014#
Time of Update: 2016-06-06
代碼如下:# -*- coding:utf-8 -*-# python3.3.3import
Time of Update: 2016-06-06
代碼如下:import os ## for os.path.isfile()def dealline(line) : print(line) ## 針對line我可以做很多事情def getfilename() : return input('Please input file name(input exit() for exit):').strip()class more : ## MORE功能 linenum = 0 size = 10 def
Time of Update: 2016-06-06
很多語言都提供了對參數或變數進行處理的機制,作為靈活的Python,提供了一些針對函數處理的特殊方法filter(function, sequence): 對sequence中的item依次執行function(item),將執行結果為True的item組成一個List/String/Tuplemap(function, sequence) : 對sequence中的item依次執行function(item),見執行結果組成一個Listreduce(function, sequence,
Time of Update: 2016-06-06
代碼如下:from creepy import Crawlerfrom BeautifulSoup import BeautifulSoupimport urllib2import jsonclass MyCrawler(Crawler): def process_document(self, doc): if doc.status == 200: print '[%d] %s' % (doc.status, doc.url)
Time of Update: 2016-06-06
測試url:http://tieba.baidu.com/p/27141123322?pn=begin 1end 4 代碼如下:import string ,urllib2def baidu_tieba(url,begin_page,end_page): for i in range(begin_page, end_page+1): sName = string.zfill(i,5)+ '.html' print '正在下載第' + str(i) +
Time of Update: 2016-06-06
一、python中對檔案、檔案夾操作時經常用到的os模組和shutil模組常用方法。1.得到當前工作目錄,即當前Python指令碼工作的目錄路徑:
Time of Update: 2016-06-06
考慮下述Python程式碼片段。對檔案中的資料進行某些操作,然後將結果儲存迴文件中: 代碼如下:with open(filename) as f: input = f.read()output = do_something(input)with open(filename, 'w') as f:
Time of Update: 2016-06-06
一、__init__ 方法是什嗎?使用Python寫過物件導向的代碼的同學,可能對 __init__ 方法已經非常熟悉了,__init__ 方法通常用在初始化一個類執行個體的時候。例如: 代碼如下:# -*- coding: utf-8 -*-class Person(object): """Silly Person""" def __init__(self, name, age): self.name = name self.age = age
Time of Update: 2016-06-06
Python使用 continue 語句跳出迴圈,而break跳出整個迴圈。continue 語句用來告訴Python跳過當前迴圈的剩餘語句,然後繼續進行下一輪迴圈。continue語句使用在用在while和for迴圈中。一、Python 語言 continue 語句文法格式如下: 代碼如下:continue二、邏輯流程圖:三、使用執行個體: 代碼如下:#!/usr/bin/pythonfor letter in 'Python': # First Example if
Time of Update: 2016-06-06
代碼如下:import timeimport tkinter as tkclass Window: def __init__(self, title='nms', width=300, height=120, staFunc=bool, stoFunc=bool): self.w = width self.h = height self.stat = True self.staFunc = staFunc
Time of Update: 2016-06-06
近期接手越來越多的東西,發布和營運的工作相當機械,加上頻率還蠻高,導致時間浪費還是優點多。修複bug什麼的,測試,提交版本庫(2分鐘),ssh到測試環境pull部署(2分鐘),rsync到線上機器A,B,C,D,E(1分鐘),分別ssh到ABCDE五台機器,逐一重啟(8-10分鐘) =
Time of Update: 2016-06-06
1.math簡介 代碼如下:>>> import math>>>dir(math) #這句可查看所有函數名列表>>>help(math) #查看具體定義及函數0原型2.常用函數 代碼如下:ceil(x) 取頂floor(x) 取底fabs(x) 取絕對值factorial (x) 階乘hypot(x,y) sqrt(x*x+y*y)pow(x,y) x的y次方sqrt(x) 開平方log(x)log10(x)trunc(x) 截斷取整數部分isnan (x)
Time of Update: 2016-06-06
代碼如下:#-*-coding:utf-8-*-'''Created on 2014年1月10日@author: hhdys'''import urllib.request,http.cookiejar,reclass Baidu: def login(self): cj = http.cookiejar.CookieJar() opener =
Time of Update: 2016-06-06
熟悉Java的jsoup包的話,對於Python的BeautifulSoup庫應該很容易上手。 代碼如下:#coding: utf-8import sysimport urllibimport urllib2from BeautifulSoup import BeautifulSoupquestion_word = "吃貨 程式員"url = "http://www.baidu.com/s?wd=" +
Time of Update: 2016-06-06
代碼如下:#!/usr/bin/env python# -*- coding: utf-8 -*- from scrapy.contrib.spiders import CrawlSpider, Rulefrom scrapy.contrib.linkextractors.sgml import SgmlLinkExtractorfrom scrapy.selector import Selectorfrom cnbeta.items import CnbetaItemclass
Time of Update: 2016-06-06
作業系統:linux軟體環境:Python 2.7.3 用法: 代碼如下:$ ./MonSocket.py # This is check the URI or Socket of the script #Usage: ./MonSocket.py -d URL; This is Http protocol ./MonSocket.py -s socket IP or domain; This is Socket protocol ./MonSocket.py -
Time of Update: 2016-06-06
例如 代碼如下:導演: 湯姆·提克威 / 拉娜·沃卓斯基 / 安迪·沃卓斯基編劇: 湯姆·提克威 / 安迪·沃卓斯基 / 拉娜·沃卓斯基主演: 湯姆·漢克斯 / 哈莉·貝瑞 / 吉姆·布勞德本特 / 雨果·維文 / 吉姆·斯特吉斯 / 裴鬥娜 / 本·衛肖 / 詹姆斯·達西 / 周迅 / 凱斯·大衛 / 大衛·吉雅西 / 蘇珊·薩蘭登 / 休·格蘭特類型: 劇情 / 科幻 / 懸疑官方網站: cloudatlas.warnerbros.com製片省/地區: 德國 / 美國 / 香港 /