Skip to main content

Taming Text Files in Python!

 


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
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.

Python. how shocking.

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

Popular posts from this blog

The Beginning

  Coding was always something I was interested in. Introduction I used to be super interested in coding as a kid, because who wouldn't want to make games, create web pages? I obviously signed up for coding tuition when I was around 10, and just could not keep up at all. The teacher was fine, but I guess I just got bored trying to understand and remember the "functions". Recently, I decided to change this, by trying to learn coding again. I still have some basic knowledge for coding, for example loops, conditionals, data types, but other than that, I just forgot everything. After this, I found this incredible website called freecodecamp.org . If you're learning to code, which I think you are doing since you're reading this, you'll probably find this website to be incredibly useful. Other than that, I realized that, "I could probably help some future coding beginners if they saw a blog from a person learning to code." and I set up this blog. I really h

What are Strings? A Beginner's Guide Into Programming Strings in Python

  What is the meaning of a string in coding? Introduction Hello there, coders! This was definitely one of the weirdest concepts I had to understand when I was learning to code.  It is so simple, but I spent an entire evening understand strings! It was ver y embarrassing , but at least I know now!  To hopefully regain my pride, I'm going to explain what strings are in programming as a beginner. What even are strings? Strings are data that you can print out. It's basically text. You might be confused if 9 is a string or an integer (number), but you can just change it! You can type in your code editor to turn a certain variable or a number into a string, in our case 9, by using the str() function. You can put anything in there and it will turn into something you can print out! You can't perform math on the string '9' though. My Experience Aside from the usual data types, I was a bit stumped when I reached the string functions. There were just so many string functions,

A Complete Overhaul of My Text-Based CYOA Game in Python!

  Everything changed. Introduction Hello there, coders! Today, I'm going to be sharing my experiences with planning and coding a text-based CYOA game in Python! The Overhaul I overhauled everything. Why? Well, it all started when I felt some doubt about my game. I felt like everything was going alright, when I took a closer look, and saw that there was no CYOA elements in it whatsoever!  The problem with it, was the fact that you chose 4 items in the beginning, and the story unfolds right in front of your eyes. There was only one single choice in the entire game. This was why I started version 2, where the player wouldn't choose any items in the beginning and make the choices inside of the haunted mansion. When I got into writing the story, I just kept overcomplicating it with souls, and arrogant mansion owners, that I just decided to scrap it completely. There was also a version 3 but I completely forgot about it. I think I scrapped it since there were just too many choices to