- #获取脚本所在目录
print os.path.split( os.path.realpath( sys.argv[0] ) )[0]
- #获取脚本运行目录
print os.getcwd()
- 本地目录读取
import os.path import sys root=‘/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!"
时间: 2024-11-06 09:36:02