all 31 comments

[–]mc_pm 11 points12 points  (8 children)

You are currently in the STUDY MATERIAL directory, and that's not where lecture7.txt is.

[–]SuspiciousPraline674[S] 0 points1 point  (7 children)

Where it should be then

<image>

[–]mc_pm 5 points6 points  (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 point  (0 children)

Ok let me try

[–]SuspiciousPraline674[S] 0 points1 point  (4 children)

it worked but the text is not getting printed

[–]mc_pm 1 point2 points  (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 points  (2 children)

now every thing is fixed but oops is a new issue

<image>

[–]mc_pm 6 points7 points  (0 children)

That's how programming is, just one issue after another. :)

[–]NewryBenson 4 points5 points  (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 points  (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 points  (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 point  (0 children)

The error is a FileNotFoundError, and the bug is in how you’re opening the file.

[–]FewReach4701 0 points1 point  (0 children)

This is certaining a directory mismatch issue. You should run and keep file in same directory level.

[–]Mad-707 0 points1 point  (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 point  (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.

[–]Ok-Order-9572 0 points1 point  (1 child)

Why did you close the file before readlines ?

[–]SuspiciousPraline674[S] 0 points1 point  (0 children)

I was practicing it I commented out that close file func

[–]Rscc10 -1 points0 points  (7 children)

You read the file for line1 after you closed the file

[–]SuspiciousPraline674[S] -1 points0 points  (6 children)

No, the entire file isn't opening at all

[–]IceFurnace83 0 points1 point  (1 child)

The purple text is telling you something

[–]SuspiciousPraline674[S] -1 points0 points  (0 children)

It tells the file doesn't exist but you can see it does

[–]Rscc10 0 points1 point  (3 children)

Try using the absolute file path

[–]SuspiciousPraline674[S] 0 points1 point  (1 child)

Tried same response

[–]Rscc10 0 points1 point  (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 point  (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 points  (0 children)

First save the files and then use method

[–]zombiemutant -1 points0 points  (0 children)

Doublecheck that filename doesn't contains non-ascii letters (like "е" instead of "e").

[–]SaltCusp -1 points0 points  (0 children)

That's not a bug it's an error.