python 读取目录文件

  1. #获取脚本所在目录  

    print os.path.split( os.path.realpath( sys.argv[0] ) )[0]  

  2. #获取脚本运行目录  

    print os.getcwd()  

  3. 本地目录读取

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!"


郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。