1、打印項目路徑spa
import os PROJECT_ROOT = os.path.dirname(os.path.realpath(__file__)) print "項目路徑是",PROJECT_ROOT
2、打開文件並按行讀取ip
open()test
def testopenFile(fileName): import os PROJECT_ROOT = os.path.dirname(os.path.realpath(__file__)) fo = open(fileName) print "項目路徑是",PROJECT_ROOT print "文件名是",fo.name print "文件的行數是:",len(fo.readline()) for line in fo.readlines(): line = line.strip() print "data is: %s" %(line) fo.close()