Skip to content

Commit 6c1a1a2

Browse files
authored
Create unit9_ex9.2.2.py
1 parent a7de566 commit 6c1a1a2

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

unit9_ex9.2.2.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# exersice 9.2.2 from unit 9
2+
'''
3+
Write a function called copy_file_content defined as follows:
4+
5+
def copy_file_content(source, destination):
6+
The function accepts as parameters two strings representing file paths.
7+
The function copies the contents of the source file to the destination file.
8+
9+
An example of an input file and the execution of the copy_file_content function:
10+
A file called copy.txt:
11+
12+
Copy this text to another file.
13+
A file called paste.txt:
14+
15+
-- some random text --
16+
Running the function copy_file_content with the files copy.txt and paste.txt:
17+
18+
>>> copy_file_content("copy.txt", "paste.txt")
19+
The paste.txt file after the above run of the copy_file_content function:
20+
21+
Copy this text to another file.
22+
'''
23+
24+
def copy_file_content(source, destination):
25+
with open(source, 'r') as src_file:
26+
with open(destination, 'w') as dest_file:
27+
dest_file.write(src_file.read())
28+
29+
def main():
30+
copy_file_content("copy.txt", "paste.txt")
31+
32+
if __name__ == "__main__":
33+
main()
34+

0 commit comments

Comments
 (0)