-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunit9_ex9.2.2.py
34 lines (24 loc) · 998 Bytes
/
unit9_ex9.2.2.py
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
30
31
32
33
34
# exersice 9.2.2 from unit 9
'''
Write a function called copy_file_content defined as follows:
def copy_file_content(source, destination):
The function accepts as parameters two strings representing file paths.
The function copies the contents of the source file to the destination file.
An example of an input file and the execution of the copy_file_content function:
A file called copy.txt:
Copy this text to another file.
A file called paste.txt:
-- some random text --
Running the function copy_file_content with the files copy.txt and paste.txt:
>>> copy_file_content("copy.txt", "paste.txt")
The paste.txt file after the above run of the copy_file_content function:
Copy this text to another file.
'''
def copy_file_content(source, destination):
with open(source, 'r') as src_file:
with open(destination, 'w') as dest_file:
dest_file.write(src_file.read())
def main():
copy_file_content("copy.txt", "paste.txt")
if __name__ == "__main__":
main()