This is where I am at so far and keeps giving me an error Ca
Solution
The code written is correct only, the error you are getting is because the file which you are given to read f1.txt is not present in your present working directory. In order this program to work either you have to give proper path of the file f1.txt or move the f1.txt file to your present working directory.
Please find the required program along with its output. Please see the comments against each line to understand the step.
def fileRead(filename):
file_ = open(filename,\'r\')
filecontent = file_.read()
return filecontent
def fileWrite(filename,filecontent):
file_ = open(filename,\'w\')
file_.write(filecontent)
file_.close()
file1content = fileRead(\'f1.txt\') #read contents of the file f1.txt and save it to variable filecontent
fileWrite(\'f2.txt\',file1content) #write the variable filecontent\'s data to a new f2.txt file
------------------------------------------
OUTPUT:
Files in present working directory:
sh-4.3$ ls f1.txt main.py
Fie f1.txt content:
sh4.3$ cat f1.txt
Hi Hello...
Files in present working directory after program ran :
sh-4.3$ python main.py
sh-4.3$
sh-4.3$ ls
f1.txt f2.txt main.py
sh-4.3$
File f2.txt(created after program ran) contents :
sh-4.3$ cat f2.txt
Hi Hello...
sh-4.3$
![This is where I am at so far and keeps giving me an error. Can you please do this step by step using python. file-open(filename,r ileNotFoundError: [Errno 2] N This is where I am at so far and keeps giving me an error. Can you please do this step by step using python. file-open(filename,r ileNotFoundError: [Errno 2] N](/WebImages/20/this-is-where-i-am-at-so-far-and-keeps-giving-me-an-error-ca-1043138-1761542208-0.webp)