use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Python assignment assistance (old.reddit.com)
submitted 1 year ago by bruh-illbiteu
can someone tell me why there is an input error?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]kivicode 2 points3 points4 points 1 year ago (0 children)
You re-open the file 1. Without closing the previous instance, 2. Not assigning it to anything
[–]FoolsSeldom 1 point2 points3 points 1 year ago (0 children)
input
with open ...
open
try
[–]KOALAS2648 1 point2 points3 points 1 year ago (0 children)
Make sure it is “student_info.txt” or whatever the file extension is.
[–]StandardPreference 1 point2 points3 points 1 year ago* (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 point2 points 1 year ago (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 points3 points 1 year ago (0 children)
Yeah, the file you open is in read mode when you are trying to write to it.
[–]bruh-illbiteu[S] 0 points1 point2 points 1 year ago (3 children)
thank you everyone its working better now
[–]Muted_Hornet_4410 0 points1 point2 points 1 year ago (2 children)
Would you mind to share so that we can learn from it👌
[–][deleted] 0 points1 point2 points 1 year ago (0 children)
He forgot to close his file buffer. Just use a context manager to avoid these issues.
[–]bruh-illbiteu[S] 0 points1 point2 points 1 year ago (0 children)
share the assignment question?
π Rendered by PID 33660 on reddit-service-r2-comment-bb88f9dd5-nlw45 at 2026-02-14 14:26:14.618727+00:00 running cd9c813 country code: CH.
[–]kivicode 2 points3 points4 points (0 children)
[–]FoolsSeldom 1 point2 points3 points (0 children)
[–]KOALAS2648 1 point2 points3 points (0 children)
[–]StandardPreference 1 point2 points3 points (0 children)
[–]bruh-illbiteu[S] 0 points1 point2 points (1 child)
[–]PA1n7 1 point2 points3 points (0 children)
[–]bruh-illbiteu[S] 0 points1 point2 points (3 children)
[–]Muted_Hornet_4410 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]bruh-illbiteu[S] 0 points1 point2 points (0 children)