Time of Update: 2018-12-06
#!/usr/bin/env python#coding=utf-8import os,shutil,stringdir = '/home/tt-ava/test' #這裡如果是windows系統,請按windows的目錄形式寫,如c:\\textfor i in os.listdir(dir): newfile = i.replace('.','_')
Time of Update: 2018-12-07
>>> logfile=open('/tmp/mylog.txt','a')>>> print >> logfile, 'fatail error: invalid arguments'>>> logfile.close()>>>user=raw_input("please input your name:")Numbers:intlongbool(True,False)floatcomplex(6.23+1.5
Time of Update: 2018-12-07
作者:Vamei 出處:http://www.cnblogs.com/vamei 歡迎轉載,也請保留這段聲明。謝謝!謝謝Tolbkni Kao幫我糾正錯誤 這裡的內容以Linux進程基礎和Linux文字資料流為基礎。subprocess包主要功能是執行外部的命令和程式。比如說,我需要使用wget下載檔案。我在Python中調用wget程式。從這個意義上來說,subprocess的功能與shell類似。 1.
Time of Update: 2018-12-06
#!/usr/bin/python
Time of Update: 2018-12-06
常量:常量名所有字母大寫,由底線串連各個單詞,如WHITE = 0XFFFFFFTHIS_IS_A_CONSTANT = 1變數:1.普通變數: 全部小寫,由底線串連各個單詞,如:1color = WHITE2this_is_a_variable = 12.保護成員變數: 單底線作首碼,意思是只有類對象和子類對象自己能訪問到這些變數,且不能用'from module import *'匯入。如:1_name=name3.私人成員變數: 雙底線作首碼,意思是只有類對象自己能訪問,
Time of Update: 2018-12-06
scim-python 是一個 SCIM 的 Python 封裝,使用python語言開發的智能拼音IME,由於採用了搜狗公司公開的語料庫裡的詞語和詞頻資訊,所以對字詞的識別率很高,而且詞語聯想也很精準。 scim-python是一款難得的IME,希望做得越來越好,試用兩天感覺猶如在linux平台下使用搜狗拼音,強烈推薦!ubuntu8.04下安裝:sudo apt-get install scim-devsudo apt-get install python-desudo apt-get
Time of Update: 2018-12-07
time常用函數 最近參與python的一個項目,發現經常遇到一些常用的模組,而每次使用時,我都要查一遍。終於,我決定要各個擊破,對常用的python小知識進行總結。下面總結了python中對時間處理的常見函數。在開始之前,首先要說明這幾點:在Python中,通常有這幾種方式來表示時間:1)、時間戳記 2)、格式化的時間字串 3)、
Time of Update: 2018-12-06
按照我們中國農曆的說法,今年是蛇年,也可以說是python的本命年。Python作為一個輕量級的Web程式設計語言,近年來越來越被編程人重視,另一說是,現在最賺錢的四種程式設計語言是:Objective-C、C++、Python、C,甚至有程式員在微博裡調侃:“因為今年是蛇年,所以使用python coding。”雖然叫Python程式設計語言,其實與蛇無半點鐘毛關係,只是Python的創始人是一個喜劇團體Monty Python的粉絲而已。在Python的官方網站中,是這樣描述Python的:
Time of Update: 2018-12-07
同步的方法基本與多線程相同。 1) Lock當多個進程需要訪問共用資源的時候,Lock可以用來避免訪問的衝突。import multiprocessingimport sysdef worker_with(lock, f): with lock: fs = open(f,"a+") fs.write('Lock acquired via with\n') fs.close() def worker_no_with(lock, f):
Time of Update: 2018-12-07
一 基本知識millisecond 毫秒microsecond 微秒 nanosecond 納秒1秒=1000毫秒 1毫秒=1000微秒 1微秒=1000納秒 二 perlperl中可以使用time或localtime來獲得時間,time返回從1970年1月1日0點的秒數,localtime返回目前時間的字串表示,或者年月日等得tuple表示。#!/usr/bin/perluse strict;use warnings;use POSIX qw(strftime);# seconds from
Time of Update: 2018-12-06
絕大多數linux distribution都內建安裝了python,我們只要在liunx命令列下打入python就能看到了,但是版本有點低不是我們想要的,如:1、下載python
Time of Update: 2018-12-07
#對象序列化import pickled={"a":"中國"}a=pickle.dumps(d,2)#序列化二進位print af=open("data","wb")f.write(a)f.close()#對象還原序列化import picklef = open("data","rb")a=f.read()d=pickle.loads(a)print d['a']中文也需要被視為位元據,pickle.dumps(d,2)第2個參數取值範圍是(0,1,2)
Time of Update: 2018-12-07
在平常的代碼中,我們常常需要與時間打交道。在Python中,與時間處理有關的模組就包括:time,datetime以及calendar。這篇文章,主要講解time模組。在開始之前,首先要說明這幾點:在Python中,通常有這幾種方式來表示時間:1)時間戳記 2)格式化的時間字串 3)元組(struct_time)共九個元素。由於Python的time模組實現主要調用C庫,所以各個平台可能有所不同。UTC(Coordinated Universal
Time of Update: 2018-12-06
將python的logging封裝更新了一下,目前支援同時向console,file,socket輸出,同時在config_logging或者config_logging_plus的時候先清除根logger的所有handler,避免在某些情況下的重複輸出。具體代碼如下:# -*- coding: utf-8 -*-'''Modified on 2012-11-27@summary: clear old root logger handlers when reconfig
Time of Update: 2018-12-07
整理的一些符號(前三個在java和c中是不這樣表達的,用&&、||、!表達)andornot!= (not equal)== (equal)>= (greater-than-equal)<= (less-than-equal)TrueFalseView Code # _*_ coding:utf-8 _*_print (True and False), Falseprint (False and True), Falseprint (1 == 1 and 2 == 1
Time of Update: 2018-12-07
在Ubuntu 9.04下配置Apache和Mod-Python直接使用軟體包管理器安裝apache,瀏覽器訪問localhost,Apache返回”It works!”。 直接使用軟體包管理器安裝mod-python,參照Ubuntu Forum的這個文章配置http://ubuntuforums.org/showthread.php?t=91101發現第一步疑似已經被軟體包管理器做了,直接修改設定檔:cd /etc/apache2/sites-available/sudo gedit
Time of Update: 2018-12-07
文章目錄 xlwt xlwthttp://pypi.python.org/pypi/xlrd簡單使用匯入xlwtimport xlwt建立一個excel檔案file = xlwt.Workbook() #注意這裡的Workbook首字母是大寫,無語吧建立一個sheettable = file.add_sheet('sheet
Time of Update: 2018-12-07
import structpack、unpack、pack_into、unpack_from # ref: http://blog.csdn.net/JGood/archive/2009/06/22/4290158.aspximport struct#pack - unpackprintprint '===== pack - unpack ====='str = struct.pack("ii", 20, 400)print 'str:', strprint 'len(str):',
Time of Update: 2018-12-07
1. YASnippet2. AutoComplete3. rope pip install rope4. pymacs(1) make install (2) 然後將編譯出來的pymacs.el拷貝到load path中 (3)或者位元組編譯它: 啟動 emacs, 執行 M-x byte-compile-file RET pymacs.el RET 此命令將產生 pymacs.elc 檔案。 可以通過如下方法檢驗是否安裝正確. 啟動
Time of Update: 2018-12-07
1. Python控制結構簡介2. 定義函數 <1>. Python控制結構 1.1 ifprint("#############if statement###############");x = int(input("Enter an integer :"));if x < 0 : x = 0; print("Negative changed to zero .");elif x == 0 : print("Zero");elif x == 1 :