Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 005caf0

Browse files
Merge pull request #134 from lironmiz/unit9-Ex9.2.2
Create unit9_ex9.2.2.py
2 parents a7de566 + 6c1a1a2 commit 005caf0

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

‎unit9_ex9.2.2.py

Lines changed: 34 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /