python串連mysql資料庫樣本(做增刪改操作)

一、相關代碼資料庫配置類 MysqlDBConn.py 代碼如下:#encoding=utf-8'''Created on 2012-11-12Mysql Conn串連類'''import MySQLdbclass DBConn: conn = None #建立和資料庫系統的串連 def connect(self): self.conn = MySQLdb.connect(host="localhost",port=3306,user="house",

python抓取豆瓣圖片並自動儲存樣本學習

環境Python 2.7.6,BS4,在powershell或命令列均可運行。請確保安裝了BS模組 代碼如下:# -*- coding:utf8 -*-# 2013.12.36 19:41 wnlo-c209# 抓取dbmei.com的圖片。from bs4 import BeautifulSoupimport os, sys, urllib2# 建立檔案夾,昨天剛學會path = os.getcwd() # 擷取此指令碼所在目錄new_path = os.path.join(

python串連mongodb操作資料樣本(mongodb資料庫配置類)

一、相關代碼資料庫配置類 MongoDBConn.py 代碼如下:#encoding=utf-8'''Mongo Conn串連類'''import pymongoclass DBConn: conn = None servers = "mongodb://localhost:27017" def connect(self): self.conn = pymongo.Connection(self.servers) def close(self):

Python群發郵件執行個體代碼

直接上代碼了 代碼如下:import smtplibmsg = MIMEMultipart()#構造附件1att1 = MIMEText(open('/home/a2bgeek/develop/python/hello.py', 'rb').read(), 'base64', 'gb2312')att1["Content-Type"] = 'application/octet-stream'att1["Content-Disposition"] = 'attachment; filename="

python中mechanize庫的簡單使用樣本

代碼如下:#!/usr/bin/env/ python#coding=utf-8import mechanizeimport cookielib# Cookie Jarcj = cookielib.LWPCookieJar()# Browserbr = mechanize.Browser()br.set_cookiejar(cj)# Browser

使用python擷取CPU和記憶體資訊的思路與實現(linux系統)

大家都知道,linux裡一切皆為檔案,在linux/unix的根目錄下,有個/proc目錄,這個/proc 是一種核心和核心模組用來向進程(process)發送資訊的機制(所以叫做“/proc”),這個偽檔案系統允許與核心內部資料結構互動,擷取有關進程的有用資訊,在運行中(on the fly)改變設定(通過改變核心參數)。與其他檔案系統不同,/proc 存在於記憶體而不是硬碟中。proc 檔案系統提供的資訊如下:•進程資訊:系統中的任何一個進程,在 proc

python3使用tkinter實現ui介面簡單一實例

代碼如下: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

linux系統使用python監測系統負載指令碼分享

代碼如下:#!/usr/bin/env Python import os def load_stat(): loadavg = {} f = open("/proc/loadavg") con = f.read().split() f.close() loadavg['lavg_1']=con[0] loadavg['lavg_5']=con[1] loadavg['lavg_15']=con[2] loadavg['nr']=

linux系統使用python擷取cpu資訊指令碼分享

linux系統使用python擷取cpu資訊指令碼分享 代碼如下:#!/usr/bin/env Pythonfrom __future__ import print_functionfrom collections import OrderedDictimport pprintdef CPUinfo(): ''' Return the information in /proc/CPUinfo as a dictionary in the following format:

python實現非同步回調機制代碼分享

1 將下面代碼拷貝到一個檔案,命名為asyncore.py 代碼如下:import socketimport selectimport sysdef ds_asyncore(addr,callback,timeout=5): s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.connect(addr) r,w,e = select.select([s],[],[],timeout) if r:

python發送arp欺騙攻擊程式碼分析

代碼如下:# -*- coding: cp936 -*-from scapy.all import *from threading import Thread,Lock,activeCountBROADCASTMAC = getmacbyip('192.168.0.120')class Loop(Thread): def __init__(self,ip): Thread.__init__(self) self.ip = ip def run(self):

分析python伺服器拒絕服務的攻擊代碼

代碼如下:# -*- coding: cp936 -*-from scapy.all import *from threading import Thread,activeCountfrom random import randintclass Loop(Thread): def __init__(self,remoteAddr): Thread.__init__(self) self.remoteAddr = remoteAddr def

python解析發往原生資料包樣本 (解析資料包)

tcp.py 代碼如下:# -*- coding: cp936 -*-import socketfrom struct import *from time import ctime,sleepfrom os import systemsystem('title tcp sniffer')system('color 05')# the public network interfaceHOST = socket.gethostbyname(socket.gethostname())#

vc6編寫python擴充的方法分享

系統內容:VC6 +

壓縮包密碼破解樣本分享(類似典破解)

昨天翻硬碟,找到一個好東西,可惜自己加了密碼自己不記得了。試了幾個常用的沒試出來,於是寫了這麼個小指令碼來替我嘗試。。呵呵,還真給解出來了。python指令碼內容如下,跑跑自己加密的壓縮包還不錯 代碼如下:# -*- coding: utf-8 -*-import sys,osdef IsElementUniq(list): """ 判斷list中的元素是否為唯一的 """ for word in list: if

python3.3教程之類比百度登陸代碼分享

代碼如下:#-*-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 =

使用BeautifulSoup爬蟲程式擷取百度搜尋結果的標題和url樣本

熟悉Java的jsoup包的話,對於Python的BeautifulSoup庫應該很容易上手。 代碼如下:#coding: utf-8import sysimport urllibimport urllib2from BeautifulSoup import BeautifulSoupquestion_word = "吃貨 程式員"url = "http://www.baidu.com/s?wd=" +

python使用urllib模組開發的多線程豆瓣小站mp3下載器

代碼如下:#! /usr/bin/python2.7# -- coding:utf-8 --import os, urllib,urllib2, thread,threadingimport re#匹配音樂urlreg=re.compile('{"name":"(.+?)".+?"rawUrl":"(.+?)",.+?}', re.I)class downloader(threading.Thread): def __init__(self, url, name):

python練習程式批量修改檔案名稱

代碼如下:# encoding:utf-8### 檔案名稱如:# 下吧.mp3##import os,refs=os.listdir('xb')for f in fs: ######方法一:partition擷取無用字元 #1.將檔案名稱以'['符分為3部分 #ls=f.partition('[') #2.ls[0]為需要檔案名稱,因此擷取ls[1:] #dirtystring = ''.join(ls[1:]) #3.開始替換 #newname=f.replace(dirtystring, '

python逐行讀取檔案內容的三種方法

方法一: 代碼如下:f = open("foo.txt") # 返回一個檔案對象 line = f.readline() # 調用檔案的 readline()方法 while line: print line, # 後面跟 ',' 將忽略分行符號 # print(line, end = '')   # 在 Python 3中使用 line = f.readline()

總頁數: 2974 1 .... 2737 2738 2739 2740 2741 .... 2974 Go to: 前往

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.