標籤:
#擷取指令碼所在目錄
print os.path.split( os.path.realpath( sys.argv[0] ) )[0]
#擷取指令碼運行目錄
print os.getcwd()
本地目錄讀取
import os.pathimport sysroot=‘/home/work/‘for parent,dirnames,filenames in os.walk(root): for filename in filenames: path=os.path.join(parent,filename) print path
4.python 流的使用 run.py
import os.path
import sys
hadoop_home_path = "/home/work/hadoop-client-stoff/hadoop"
hadoop_streaming_file = "streaming"
outputpath = ‘hdfs路徑‘
inputpath=‘hdfs路徑‘
command = hadoop stream
" -input " + inputpath +\
" -output " + outputpath + \
" -mapper \"./python/python2.6/bin/python2.6 mapper.py\" " +\
" -reducer \"./python/python2.6/bin/python2.6 reducer.py\" " + \
" -file " + "mapper.py" +\
" -file " + "reducer.py"
print command,‘\n‘
status=os.system(command)
if status>>8==0:
print "hadoop process successfully"
else:
print "sorry,try again!"
python 讀取目錄檔案