一、打印项目路径
import osPROJECT_ROOT = os.path.dirname(os.path.realpath(__file__))print "项目路径是",PROJECT_ROOT
二、打开文件并按行读取
open()
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()