-
-
Save roman-on/1f5d3004e0f4fec97cd621c0db1a0275 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
The function receives as parameters two strings representing file paths. | |
The function copies the contents of the source file to the destination file. | |
Example of an input file and running the copy_file_content function: | |
A file called copy.txt: | |
Copy this text to another file. | |
A file called paste.txt: | |
- some random text - | |
Run the copy_file_content function with the copy.txt and paste.txt files: | |
>>> 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. | |
""" | |
source = r"C:\....." | |
destination = r"C:\....." | |
""" | |
The function receives as parameters two strings representing file paths. | |
The function copies the contents of the source file to the destination file. | |
""" | |
def copy_file_content(source, destination): | |
a = "" # New variable | |
with open (source, "r") as source: # Open the file and closing automatically | |
for line in source: # Opens all the lines in the file at once by for loop | |
a += line # Adding the lines to the new variable "a" | |
with open (destination, "w") as destination: # Opening another destination file to paste the information from file source | |
destination.write(a) # Write method, paste the information from first destination to the second | |
def main(): | |
copy_file_content(source, destination) | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment