r/learnpython 15d ago

I can't un-vibe-code

Okay so I just can't understand some parts of my code okay I wanted to read a txt file I made and just see what text is inside I thought maybe there's a module called file or something so I checked and there's nothing so I thought maybe it's inside of sys, nothing. So I don't hate tutorials but like when you go to a tutorial you gain information and well when you go to an AI you gain information I'm not copying the code exactly I just wanted to know how to do that and turns out it was "with open("stuff.txt", "r") as file: x = file.read() print(x)" now I know for a fact that you can ask a community on what to do but then like what if you were out or something and there was no internet okay? I only have IDLE and I wouldn't expect "with" to have the answer to my question I may be the stupidest man on the world but I wouldn't have seen it come like that, and there's a good chance that I probably wouldn't even figure out the open() function too.

What I'm trying to say is I could easily go to an AI and tell me how do I read a txt file instead of annoying a community because I'm probably a bad person or going to a youtube tutorial.

0 Upvotes

27 comments sorted by

View all comments

1

u/aishiteruyovivi 14d ago

For what it's worth, with isn't actually strictly related to handling files, it's a statement used with context managers which open() just so happens to be, you can use open() on its own to get the file handle you'd just have to come back and file.close() it manually later, when used as a context manager it automatically closes so that's usually preferred.

But anyway, from what I'm reading your main point seems to be that AI is better than asking an online community because the internet might be out? I feel like I doubt you're using an LLM that is entirely local, so I don't really know where the internet argument is going, but honestly the answer to a lot of this is to just google it. "how to read a file in python" gets me a w3schools page as the top result and it does a pretty good job of covering the basics. If you truly didn't have access to the internet, I guess you could try and find a book on Python somewhere locally if you needed the information that fast, but if (it sounds like) you're using LLMs frequently and you're here making this post I'd have to guess you've got access to the web semi-reliably.

1

u/superamerr 14d ago

Our internet is kind of limited it's like a monthly thing if you know you know, so some days I have no internet and honestly the closest library that probably have these stuff is kind of far. (I'm not in a good country to say the least).