Getting Invalid Sytax Error Try Fh Open Test W Try Fhwrite Test File Print Closing File Fh Q37286823

why am i getting invalid sytax error?

try:
fh = open(“test”, “w”)
try:
fh.write(“Test file!!”)
print(“Closing the file”)
fh.close()
except IOError:
print (“Error: File not found or is read-only” )

#2. cio_write-
#this code opens a file and read in all the lines into a listcalled test.
import sys
file_name = sys.argv[1]
text = []
try:
fh = open(file_name, ‘r’)
text = fh.readlines()
fh.close()
except IOError:
print(‘cannot open’, file_name)
if text:
print(text[100])

#3.cio read
import sys
file_name = “integer.txt”
text = []
try:
fh = open(file_name, ‘r’)
except IOError:
print(‘cannot open’, file_name)
else:
text = fh.readlines()
fh.close()
if text:
print(text[100])

#cio seek function
import os;
new file=open(cio_py.txt”,”w”)
for I in range (1 to 10):
newfile.write(“nwelcome”)
for i in range (1 to 10):
print((newfile.read())
newfile.seek(0)
print (newfile.tell())//setting the cursor at 0 position.
os.rename(“cio.text” ,”python.txt”)
os.remove(“cio.txt”)
newfile.close()


Answer


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.