mktime()方法是localtime()反函數。它的參數是struct_time或全9元組,它返回一個浮點數,為了相容時time()。如果輸入值不能表示為有效時間,那麼OverflowError或ValueError錯誤將被引發。Syntax以下是mktime()方法的文法:time.mktime(t)參數 t --
tell()方法返回的檔案內的檔案讀/寫指標的當前位置。文法以下是tell()方法的文法:fileObject.tell()參數 NA傳回值此方法返回該檔案中讀出的檔案/寫指標的當前位置。例子下面的例子顯示了tell()方法的使用。#!/usr/bin/python# Open a filefo = open("foo.txt", "rw+")print "Name of the file: ", fo.name# Assuming file has following 5
write()方法把字串str寫入檔案。沒有傳回值。由於緩衝,字串可能不實際顯示檔案,直到flush()或close()方法被調用。文法以下是write()方法的文法:fileObject.write( str )參數 str -- 這是要被寫入的檔案中的字串。傳回值此方法不返回任何值。例子下面的例子顯示write()方法的使用。#!/usr/bin/python# Open a file in write modefo = open("foo.txt", "rw+")print
strftime()方法轉換成一個元組或struct_time表示時間所指定的格式參數所返回gmtime()或localtime()為一個字串。當t不設定,所返回目前時間使用localtime()方法。格式必須是字串。異常ValueError被掛起,如果t在任何欄位的允許範圍之外。文法以下是strftime()方法的文法:time.strftime(format[, t])參數 t -- 這是以秒為單位來進行格式化的時間。 format --
如果檔案已串連(與終端裝置相關聯)到一個tty(狀)的裝置,isatty()方法返回True,否則返回False。文法以下是isatty()方法的文法:fileObject.isatty();參數 NA傳回值如果該檔案被串連(與終端裝置相關聯)到一個tty(類似終端)裝置此方法返回true,否則返回false。例子下面的例子顯示了isatty()方法的使用。#!/usr/bin/python# Open a filefo = open("foo.txt", "wb")print
fileno()方法返回所使用的底層實現,要求從作業系統I/O操作的整數檔案描述符。文法以下是fileno()方法的文法:fileObject.fileno(); 參數 NA傳回值此方法返回整數檔案描述符。例子下面的例子顯示fileno()方法的使用。#!/usr/bin/python# Open a filefo = open("foo.txt", "wb")print "Name of the file: ", fo.namefid = fo.fileno()print
自己寫的方法,適用於linux,#!/usr/bin/python#coding=utf-8import sysimport os, os.pathimport dircacheimport commandsdef add(x,y): return x*ydef trans(dirname): lis = dircache.opendir(dirname) for a in lis:af=dirname+os.sep+a## print af if os.path.isdir(af):##