Time of Update: 2015-06-25
標籤:不積跬步,無以至千裡。不積小流,無以成江河。當我覺得沮喪、絕望的時候,就瘋狂的敲代碼,這樣會好受一點。 今天和昨天敲了兩天的小程式,算是對python的具體文法規則有個初步的手熟。http://www.w3cschool.cc/python3/python3-examples.html 今天看到群裡在討論什麼libsvm. 好像是跟python庫有關係。今天回去試一下安裝。Python 學習筆記12
Time of Update: 2015-06-25
標籤:python pip// wget pip[[email protected] tools]# wget https://bootstrap.pypa.io/get-pip.py--2015-06-25 14:40:46-- https://bootstrap.pypa.io/get-pip.py正在解析主機 bootstrap.pypa.io (bootstrap.pypa.io)... 103.245.222.175正在串連 bootstrap.pypa.io (
Time of Update: 2015-06-23
標籤: 在python開發中,我們常常需要執行命令,修改相關資訊。那對於初學者來說,python中如何執行命令呢?今天,小編就為大家分享3種python命令執行的方法。 1. 使用os.system("cmd") 在python中,使用os.system("cmd")的最大特點是,其執行時程式會打出cmd在linux上執行的資訊。import
Time of Update: 2015-06-23
標籤:# -*- coding: utf-8 -*-"""Created on Tue Jun 23 15:24:19 2015@author: hd"""from sklearn import cross_validationc = []j=0filename = r‘C:\Users\hd\Desktop\bookmarks\bookmarks.arff‘ out_train =
Time of Update: 2015-06-24
標籤:今天運行類型下列代碼與預想中有出入print os.path.abspath(__file__) #檔案不在根目錄os.chdir('/')print os.path.abspath(__file__)#與第一次不一樣但是運行import卻是對的test=import__('xx')os.chdir('/')test=import__('xx')reload(test)原來:1. abspath在linux下的做法只是:1.
Time of Update: 2015-06-23
標籤:python中實現並發的方式有很多種,通過多進程並發可以真正利用多核資源,而多線程並發則實現了進程內資源的共用,然而Python中由於GIL的存在,多線程是沒有辦法真正實現多核資源的。對於計算密集型程式,應該使用多進程並發充分利用多核資源,而在IO密集型程式中,多核優勢並不明顯,甚至由於大多數時間都是在IO堵塞狀態,多進程的切換消耗反而讓程式效率更加低下。而當需要並發處理IO密集型任務時,就需要用到協程(Coroutine)。協程並沒有系統級的調度,而是使用者級的調度方式,避免了系統調用的
Time of Update: 2015-06-25
標籤: 21.1. webbrowser — Convenient Web-browser controller Source code: Lib/webbrowser.py 翻譯:Z.F. The webbrowser module provides a high-level interface to allow displaying Web-based documents to users. Under most circumstances, simply
Time of Update: 2015-06-23
標籤:python uuid 1. 下載uuid模組https://pypi.python.org/pypi/uuid/uuid-1.30.tar.gz2. 解壓uuid模組tar zxvf uuid-1.3.0.tar.gz -C /usr/src3. build模組cd /usr/src/uuidpython setup.py build4. install模組python setup.py install函數用法uuid.
Time of Update: 2015-06-25
標籤:日記 python 檔案操作 與檔案操作有關函數: 1.開啟一個檔案open("檔案名稱","開啟檔案")開啟檔案歸類:模式開啟檔案檔案存在檔案不存在r唯讀開啟檔案報錯w唯寫清空檔案並開啟建立並開啟a唯寫開啟並追加建立並開啟r+讀寫從檔案開始讀,或重寫報錯w+讀寫清空並開啟建立並開啟a+讀寫開啟並追加建立並開啟範例:iword.txt檔案內容First wordSecond
Time of Update: 2015-06-24
標籤:在工作過程中發現監控即時重新整理檔案時,不是那麼的任性。故結合shell中的tail,做了一個類似tail的python指令碼。詳情如下: 1 #!/usr/bin/env python 2 #coding=utf-8 3 import os,sys,time,getopt 4 5 lastline=‘‘ 6 linelist=[] 7 def getNewLine(filename, count): 8 global lastline 9 global
Time of Update: 2015-06-24
標籤:ImagesImage interface.class novaclient.v2.images.Image(manager,info, loaded=False)Bases: novaclient.openstack.common.apiclient.base.ResourceAn image is a collection of files used to create or rebuild a server.Populate and bind to a
Time of Update: 2015-06-24
標籤:python 程式設計語言 sched模組提供了一個用於事件調度的類。scheduler類定義class sched.scheduler(timefunc=time.monotonic,
Time of Update: 2015-06-25
標籤:在自動化營運平台沒有做完之前,常需要登入伺服器做很多維護操作,每次找好長好長的密碼,那麼多伺服器,你會瘋掉的,所以瞎搞了以下指令碼.先解一下燃眉之急,哈哈cat login_root.exp#!/usr/bin/expect -cset IP [lindex $argv 0]set PWD [lindex $argv 1]set timeout 2spawn ssh [email protected]$IPexpect "*yes/no*" {send
Time of Update: 2015-06-23
標籤:有時候難免需要直接調用Shell命令來完成一些比較簡單的操作,比如mount一個檔案系統之類的。那麼我們使用Python如何調用Linux的Shell命令?下面來介紹幾種常用的方法:1. os 模組 1.1. os模組的exec方法族Python的exec系統方法同Unix的exec系統調用是一致的。這些方法適用於在子進程中調用外部程式的情況,因為外部程式會替換當前進程的代碼,不會返回。( 這個看了點 help(os) --> search
Time of Update: 2015-06-24
標籤:為了便於整理部分業務資料,以及儲存管理, 寫了此指令碼.後期如果有需求,再改一下. 1 #!/usr/bin/env python 2 #coding:utf8 3 4 import os,sys,time,commands,shutil,glob 5 import datetime 6 7 8 class FileSuo: 9 10 def __init__(self,dir):11 self.dir = dir12 13 def
Time of Update: 2015-06-23
標籤:python 多線程 編程 thread 1、使用thread模組(不推薦) 常用函數: ‘start_new_thread(function,args,kwargs=None)’:建立一個新的線程,並運行’function(args)’ ‘allocate_lock()’: 建立鎖對象 Lock object ‘exit()’: 提示線程退出
Time of Update: 2015-06-21
標籤:在採集網頁資訊的時候,經常需要偽造前序來實現採集指令碼的有效執行下面,我們將使用urllib2的header部分偽造前序來實現採集資訊方法1、?1234567891011121314151617181920212223242526272829#!/usr/bin/python# -*- coding: utf-8 -*-#encoding=utf-8#Filename:urllib2-header.py import urllib2import
Time of Update: 2015-06-22
標籤: 主題 用戶端/伺服器架構通訊端:通訊終點通訊端地址連線導向與無串連通訊端Python中的網路編程SOCKET模組通訊端對象方法TCP/IP用戶端和伺服器UDP/IP用戶端和伺服器SocketServer模組Twisted架構介紹相關模組 1.用戶端伺服器架構
Time of Update: 2015-06-22
標籤:A set is an unordered collection with no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support mathematical operations like union, intersection, difference, and symmetric
Time of Update: 2015-06-20
標籤:1.Python的下載和安裝我就不廢話了,百度上都有。我安裝的是Python 3.4.3