码迷,mamicode.com
首页 > 编程语言 > 详细

python 读取目录文件

时间:2015-05-14 12:25:18      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

  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 读取目录文件

标签:

原文地址:http://my.oschina.net/u/1782622/blog/414679

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!