-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_file_text_case.py
More file actions
30 lines (25 loc) · 967 Bytes
/
Copy pathconvert_file_text_case.py
File metadata and controls
30 lines (25 loc) · 967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python3
""" A Simple File Processing Program.
Combines Python’s string objects and file objects to create a file processing
program.
Features:
* open one file,
* read its contents,
* and write a modified form of its contents to a second file.
Module provides a simple utility function, capitalize, that capitalizes
the text within a file.
"""
def capitalize(filename):
"""
Creates a new file with the prefix 'upper_' added to the name of the
original file <filename>.
All the alphabetic characters in the new are capitalized.
This function does not disturb the contents of the original file.
"""
with open(filename, 'r') as input_file:
with open('upper_{0}'.format(filename), 'w') as output_file:
for line in input_file:
line = line.strip().upper()
print(line, file=output_file)
if __name__ == '__main__':
capitalize('declaration.txt')