I was very frustrated with this one.
Introduction
Hello there, coders! I was completely surprised, flabbergasted, and astonished, since this lesson was completely different from the others.
I was going to have to do actual work instead of learning things. Frightening, I know.
Having to skim through hundreds of lines of text to find that one email can be very frustrating, so python reading the text files can save hours off of your life.
![Shocked man finding out coding exists](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6qJhdqxzY98bFI4pwTx2ZZ80JdjbUIOsZLYaqOrwWJvvoQ9pcwetvktmSgaxecXjBej31KGS7KpLKZyUS5xNZh7IeyqtG-VcfscYq4k0xb-3ffn6epw-E3XqjEHTV2diEZBwpl1-vQBEHwsIQ-MtS5iNlZy8Y71JOs0C399KKM_vCqb22hWhyxtsdDHA/w275-h220/image_2024-04-19_150856033.png) |
Real-Time Reaction of a business man finding this out |
Deep Dive
So, python (as I've heard), is a very special language as it reads text files and has a function specifically for that (as I found out from Mr. Charles).
This all can happen because of one function: open() . It basically, well, opens the text file and you can just do everything you want with it.
(p.s. apparently it can open other types of files but I still don't know that... )
The variable the function happens in is called the handle, but I just called it a portal since it was easier to visualize.
When you start to print out the text files (I encountered this problem, more on that later), there are spaces everywhere.
This is because of the \n thing which makes your text\n
go to the next line! You have to use the almighty sword of\n rsplit() to get rid of it, since it is categorized as\n whitespace!\n
By the way, there are text file functions like close(), write(), read(), and probably many more I don't know since I'm a beginner.
Disaster
I was doing this exercise where Mr. Charles gave me a text file to turn it into an uppercased text file.
BUT, as a beginner would, I made a horrible mistake. I put the portal (handle for boring people) before the .upper() function, and kept me wondering why my code wasn't working.
Obviously, YOU CAN'T USE STRING FUNCTIONS ON PORTALS (handle for boring people)! I quickly edited my code to fix it and wallowed in despair.
Conclusion
Well, that's all folks! If you guys want to share your aggravating moments coding, feel free to comment your misfortune!
By the way! AI can be quite good for explaining a certain annoying mistakes that took you 15 minutes to figure out.
Before I forget, here's the code snippet of the day!
and with that,
signing off,
Stewie
Comments
Post a Comment