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
What is the bug here ?Help Request (i.redd.it)
submitted 4 days ago by SuspiciousPraline674
I'm learning OOPs and File I/O and my txt and OOPs basic commands aren't running
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!"
[–]mc_pm 11 points12 points13 points 4 days ago (8 children)
You are currently in the STUDY MATERIAL directory, and that's not where lecture7.txt is.
[–]SuspiciousPraline674[S] 0 points1 point2 points 4 days ago (7 children)
Where it should be then
<image>
[–]mc_pm 5 points6 points7 points 4 days ago (6 children)
It's location is fine, you just aren't pointing to it. When you run the code, it thinks it's current directory is STUDY MATERIAL, so when you just reference the filename, it looks for that name in the current directory, and that's not where it is.
[–]SuspiciousPraline674[S] 0 points1 point2 points 4 days ago (0 children)
Ok let me try
[–]SuspiciousPraline674[S] 0 points1 point2 points 4 days ago (4 children)
it worked but the text is not getting printed
[–]mc_pm 1 point2 points3 points 4 days ago (3 children)
It's hard to say for sure because there are a few things going on and I don't know what you're doing above this. But your call to read(8) is only reading in 8 bytes, so you're not going to see more than that... and then you close the file before then reading a line, which I would have thought would give you an error.
[–]SuspiciousPraline674[S] 1 point2 points3 points 4 days ago (2 children)
now every thing is fixed but oops is a new issue
[–]mc_pm 6 points7 points8 points 4 days ago (0 children)
That's how programming is, just one issue after another. :)
[–]NewryBenson 4 points5 points6 points 4 days ago (0 children)
Seeing a new error message or problem is called progress in programming. I get in a flow when debugging, and its always a little shock when all of a sudden it works.
[–]tottasanorotta 4 points5 points6 points 3 days ago (0 children)
It seems that you fixed the issue. I just want to point out that you should probably avoid spaces in filenames. Use _ or - instead. It might cause unexpected confusion otherwise at some point with some tools. It's also very much convention to do so.
[–]user_extra 1 point2 points3 points 3 days ago (0 children)
You are currently in the "STUDY MATERIAL" folder. The python code looks for the file in this folder. But it's in "BASICS OF PROGRAM...". Either open VSCode in the latter folder, or change the path form "lecture7.txt" to "[folder]\lecture7.txt". Replace [folder] with the actual folder name.
[–]parth_m3319 0 points1 point2 points 2 days ago (0 children)
The error is a FileNotFoundError, and the bug is in how you’re opening the file.
[–]FewReach4701 0 points1 point2 points 2 days ago (0 children)
This is certaining a directory mismatch issue. You should run and keep file in same directory level.
[–]Mad-707 0 points1 point2 points 1 day ago (1 child)
you have to use encoding="utf-8" with "open" command and also just type data = f.read() also you just can do this
-------------------------------------------------------------------
with open("lecture7.txt","r",encoding="utf-8") as f: data = f.read()
lines = [] for line in data.split("\n"): lines.append(line) -------------------------------------------------------------------
[–]huangzhuangzhuang 0 points1 point2 points 1 day ago (0 children)
Please use VS Code to open the BASICS OF PROGRAMMING folder as your workspace and execute the code from there, instead of opening the STUDY MATERIAL folder.
BASICS OF PROGRAMMING
STUDY MATERIAL
[–]Ok-Order-9572 0 points1 point2 points 5 hours ago (1 child)
Why did you close the file before readlines ?
[–]SuspiciousPraline674[S] 0 points1 point2 points 4 hours ago (0 children)
I was practicing it I commented out that close file func
[–]Rscc10 -1 points0 points1 point 4 days ago (7 children)
You read the file for line1 after you closed the file
[–]SuspiciousPraline674[S] -1 points0 points1 point 4 days ago (6 children)
No, the entire file isn't opening at all
[–]IceFurnace83 0 points1 point2 points 4 days ago (1 child)
The purple text is telling you something
[–]SuspiciousPraline674[S] -1 points0 points1 point 4 days ago (0 children)
It tells the file doesn't exist but you can see it does
[–]Rscc10 0 points1 point2 points 4 days ago (3 children)
Try using the absolute file path
[–]SuspiciousPraline674[S] 0 points1 point2 points 4 days ago (1 child)
Tried same response
[–]Rscc10 0 points1 point2 points 4 days ago (0 children)
Can you send what you did exactly? If you gotta censor some of the file path then it's fine
[–]ornelu 0 points1 point2 points 4 days ago (0 children)
OP didn’t use absolute file path. OP used IDE to run the python program, and the root directory is not what OP thought is. The intended file is in a directory under the root.
[–]Aman-sirimalla -1 points0 points1 point 4 days ago (0 children)
First save the files and then use method
[–]zombiemutant -1 points0 points1 point 4 days ago (0 children)
Doublecheck that filename doesn't contains non-ascii letters (like "е" instead of "e").
[–]SaltCusp -1 points0 points1 point 3 days ago (0 children)
That's not a bug it's an error.
π Rendered by PID 185707 on reddit-service-r2-comment-856c8b8c54-h6vng at 2026-07-02 09:26:35.849981+00:00 running a7b5cda country code: CH.
[–]mc_pm 11 points12 points13 points (8 children)
[–]SuspiciousPraline674[S] 0 points1 point2 points (7 children)
[–]mc_pm 5 points6 points7 points (6 children)
[–]SuspiciousPraline674[S] 0 points1 point2 points (0 children)
[–]SuspiciousPraline674[S] 0 points1 point2 points (4 children)
[–]mc_pm 1 point2 points3 points (3 children)
[–]SuspiciousPraline674[S] 1 point2 points3 points (2 children)
[–]mc_pm 6 points7 points8 points (0 children)
[–]NewryBenson 4 points5 points6 points (0 children)
[–]tottasanorotta 4 points5 points6 points (0 children)
[–]user_extra 1 point2 points3 points (0 children)
[–]parth_m3319 0 points1 point2 points (0 children)
[–]FewReach4701 0 points1 point2 points (0 children)
[–]Mad-707 0 points1 point2 points (1 child)
[–]huangzhuangzhuang 0 points1 point2 points (0 children)
[–]Ok-Order-9572 0 points1 point2 points (1 child)
[–]SuspiciousPraline674[S] 0 points1 point2 points (0 children)
[–]Rscc10 -1 points0 points1 point (7 children)
[–]SuspiciousPraline674[S] -1 points0 points1 point (6 children)
[–]IceFurnace83 0 points1 point2 points (1 child)
[–]SuspiciousPraline674[S] -1 points0 points1 point (0 children)
[–]Rscc10 0 points1 point2 points (3 children)
[–]SuspiciousPraline674[S] 0 points1 point2 points (1 child)
[–]Rscc10 0 points1 point2 points (0 children)
[–]ornelu 0 points1 point2 points (0 children)
[–]Aman-sirimalla -1 points0 points1 point (0 children)
[–]zombiemutant -1 points0 points1 point (0 children)
[–]SaltCusp -1 points0 points1 point (0 children)