一、背景:
有个文本文件,内容不多,想将每行数据的首字母大写。
$ cat test
map
filter
flatMap
mapPartitions
mapPartitionsWithIndex
sample
union
intersection
distinct
groupByKey
reduceByKey
aggregateByKey
sortByKey
join
cogroup
cartesian
pipe
coalesce
repartition
repartitionAndSortWithinPartitions
二、处理办法
1.使用python处理,目前想到两种处理办法:
$ cat dlw.py
#!/usr/bin/python
# -*- coding: UTF-8 -*-
class Capfile:
def __init__(self, f):
self.f = f
# 方法1,使用python函数capitalize()来处理,这个处理的结果数据会变成首字母大写,其它字母都小写了
def capfile1(self):
of = open(file1)
wf = open(file2, 'w')
for i in of.readlines():
d = i.capitalize()