Python操作HDFS封装类,拷贝过去直接用

本文介绍了一种Python封装类,用于便捷地操作Hadoop分布式文件系统(HDFS)。通过这个类,开发者可以轻松实现HDFS上的文件拷贝、读写等操作,提升工作效率。
摘要由CSDN通过智能技术生成
from hdfs.client import Client

from conf.settings import DFS


# 关于python操作hdfs的API可以查看官网:
# https://hdfscli.readthedocs.io/en/latest/api.html

# client = Client(url, root=None, proxy=None, timeout=None, session=None)
# client = Client("http://hadoop:50070")
# client = InsecureClient("http://120.78.186.82:50070", user='ann');

class hdfsOperator(object):
    def __init__(self, client):
        self.client = client

    # 读取hdfs文件内容,将每行存入数组返回
    def read_hdfs_file(self, filename):
        # with client.read('samples.csv', encoding='utf-8', delimiter='\n') as reader:
        #  for line in reader:
        # pass
        lines = []
        with self.client.read(filename, encoding='utf-8', delimiter='\n') as reader:
            for line in reader:
                # pass
                # print line.strip()
                lines.append(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值