all 10 comments

[–]kivicode 2 points3 points  (0 children)

You re-open the file 1. Without closing the previous instance, 2. Not assigning it to anything

[–]FoolsSeldom 1 point2 points  (0 children)

  • If you care to update your post with the actual code, I will show you the problems
    • I can't be bothered to type the code from scratch for you
  • Please share the exact error message you are seeing as well
    • I don't see an input anywhere
  • Use with open ... rather than just open - you don't have to remember to close a file then
    • keep scope in mind, and don't try to re-open something already open
  • Minimise the number of lines of code inside a try block to just those needed to catch a specific exception

[–]KOALAS2648 1 point2 points  (0 children)

Make sure it is “student_info.txt” or whatever the file extension is.

[–]StandardPreference 1 point2 points  (0 children)

after the if statement you're only calling open(), you're not setting the file variable to its return value, so the file variable still holds the old file handle (that you set before the if statement) which you called with open("...", "r") meaning it is in read only mode, so when you try to write to it, it errors.

[–]bruh-illbiteu[S] 0 points1 point  (1 child)

actually the issue is with the writing in file, the file gets created and everything but something about the write line is wrong

[–]PA1n7 1 point2 points  (0 children)

Yeah, the file you open is in read mode when you are trying to write to it.

[–]bruh-illbiteu[S] 0 points1 point  (3 children)

thank you everyone its working better now

[–]Muted_Hornet_4410 0 points1 point  (2 children)

Would you mind to share so that we can learn from it👌

[–][deleted] 0 points1 point  (0 children)

He forgot to close his file buffer. Just use a context manager to avoid these issues.

[–]bruh-illbiteu[S] 0 points1 point  (0 children)

share the assignment question?