我有这种格式的用户名RSmith。我可以将它们放在所有的upercase或标题中看起来像这样,Rsmith,但我需要RSmith。
当前脚本:
import csv
app_csv = ('/tmp/lowerAccounts.csv')
app_csv_upper = ('/tmp/Identity_Accounts.csv')
in_app_csv = open(app_csv)
out_app_csv = open(app_csv_upper, 'w')
inreader = csv.reader(in_app_csv)
outwriter = csv.writer(out_app_csv)
for row in inreader:
outwriter.writerow(row)
row[0] = row[0].upper()
outwriter.writerow(row)
row[0] = row[0].title(row)
outwriter.writerow(row)
答案 0 :(得分:18)
您可以使用基本的字符串切片:
s = 'rsmith'
s = s[:2].upper() + s[2:]
print(s)
输出:
RSmith