37,721
社区成员
发帖
与我相关
我的任务
分享
>>> import os
>>> help(os.getcwd)
Help on built-in function getcwd in module nt:
getcwd()
Return a unicode string representing the current working directory.
>>> help(os.path.realpath)
Help on function abspath in module ntpath:
abspath(path)
Return the absolute version of a path.
>>> help(os.path.dirname)
Help on function dirname in module ntpath:
dirname(p)
Returns the directory component of a pathname
import os.path
base_path = os.path.dirname(os.path.realpath(__file__)) # 获取当前路径
file_path = os.path.join(base_path, "piDigits.txt")
with open(file_path,'r') as file_object:
lines = file_object.readlines()
for line in lines:
print line.rstrip()