File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments