Answer to Question #4694 in Python for Will

Question #4694
How do you create a function that takes all the letters of a text file and writes them in all caps into a new file?
1
Expert's answer
2012-04-10T07:34:06-0400
def up_case(inpFileName, outFileName):
inFile = open(inpFileName,
'r');
outFile = open(outFileName, 'w');
d=ord('A')-ord('a');
for line
in inFile:
nline='';
for i in range(len(line)):
if line[i]>='a' and
line[i]<='z':
nline = nline + chr(ord(line[i])+d);
else:
nline =
nline + line[i];
outFile.write(nline);



## TEST.
# Before
running it create file 'a.txt'
up_case('a.txt', 'b.txt')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS