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


你可能感兴趣的:(python 读取目录文件)