Day 8 of #30DaysOfPython ✅ Until today, every single thing I built vanished the moment I closed the terminal. Run the script, see the output, close it — gone. No trace. No memory. Nothing. File handling changed that completely. I can now write a script that creates a file, puts data inside it, and saves it to my computer — permanently. I can open that same file an hour later and read every line back. My code has storage now. That shift in what Python can do hit harder than I expected. The concept itself isn't complicated. But the details will get you. I spent 20 minutes wondering why my file kept getting wiped every time I ran my script. Turns out I was opening it in "w" mode — which doesn't add to a file. It replaces it. Completely. Every. Single. Time. Switched to "a" for append. Problem solved. Data survived. Lesson learned permanently. 😅 The other habit I picked up today: always use with open() instead of plain open(). It automatically closes the file when you're done — even if your code crashes midway. I didn't think it mattered until I read about what happens to files that never get closed properly. Now I will never skip it. What I covered today: "r" to read, "w" to write, "a" to append with open() as the safe, correct way to handle files .read(), .readlines(), and looping line by line Checking if a file exists before trying to open it Day 8 done. My code has a memory now. 🧠 👇 What was the first script you wrote that actually saved data to a file? I'd love to know what made file handling click for you — drop it below! #Python #30DaysOfPython #FileHandling #BuildInPublic #PythonProjects
Day 8 of 30DaysOfPython: Mastering File Handling in Python
More Relevant Posts
-
🚀 Day 8/30 of My LeetCode Journey (Python + SQL) Staying consistent and leveling up every day! 💻🔥 🔹 **SQL Problem of the Day** 👉 *Find Customer Referee* Given a `Customer` table, write a query to find the names of customers who are either: • Not referred by customer with id = 2 • OR not referred by anyone 💡 *Key Concept:* Filtering with conditions (`!= 2` OR `IS NULL`). 🔹 **Python Problem of the Day** 👉 *Merge Sorted Array* Given two sorted arrays, merge them into a single sorted array in-place without returning a new array. 💡 *Key Concept:* Two-pointer approach from the end for efficient in-place merging. Every problem is helping me think more efficiently and write better code ⚡ Day 8 done ✅ #LeetCode #30DaysChallenge #Python #SQL #CodingJourney #Consistency #ProblemSolving #Learning
To view or add a comment, sign in
-
3MTT Week 6 Reflection Week 6 hit different. When my Python code kept throwing errors, my first thought was — it must be the phone.I genuinely believed the phone was giving me a different experience from a computer and that was the problem.That assumption had me looking in the completely wrong direction. The real issue? I didn't understand that every data type in Python plays by its own rules.Strings need quotation marks. Integers and floats don't.Items in a list or dictionary need to be separated by commas. Simple rules but until you truly get them,nothing works and you don't even know why. Once that clarity hit,everything shifted. Now before I write anything, I ask myself:what data type am I working with, and what does it expect from me? That one question has saved me from so many errors. I also made mistakes with Pandas; writing the import but forgetting to call the variable properly under it. My tutor corrected me in class and it stuck so hard that I've since corrected two of my classmates making the same mistake. That felt good.Really good. The assumption I had to kill this week: that my tools were the problem. The real work was always in understanding the rules.#My3MTT #3MTTWeeklyReflection
To view or add a comment, sign in
-
Day 10/365: Building a List from User Input & Finding Basic Stats 🔢📥 Today I wrote a Python program that takes numbers from the user, stores them in a list, and then calculates some basic statistics: sum, average, minimum, and maximum. What the code does step by step: First, I ask the user how many elements they want to enter and store that in n. I create an empty list l and a variable total to keep track of the sum. Using a for loop, I take n inputs from the user: Each number is added to the list using append(). At the same time, I keep adding each number to total to calculate the sum. After the loop: I print the full list. I print the sum using the total variable. Then I calculate the average as total / n and print it. To find the minimum and maximum: I start by assuming both min and max are the first element of the list. I loop through the list and update min if I find a smaller value. Similarly, I update max if I find a larger value. In the end, I print the minimum and maximum numbers in the list. What I learned from this exercise: How to take multiple inputs from a user and store them in a list. How to maintain a running sum while taking inputs. How to manually compute average, minimum, and maximum without using built‑in functions like sum(), min(), or max(). How loops and variables can work together to build simple but useful statistics — a basic idea used a lot in data analysis. Day 10 done ✅ 355 more to go. If you have ideas like extending this to find median, mode, or standard deviation, send them to me — I’d love to try them next. #100DaysOfCode #365DaysOfCode #Python #LogicBuilding #Lists #UserInput #CodingJourney #LearnInPublic #AspiringDeveloper
To view or add a comment, sign in
-
-
🚀 Day 3/30 of My LeetCode Journey (Python + SQL) Showing up daily and building consistency, one problem at a time! 💻🔥 🔹 **Python Problems of the Day** 👉 *1. Move Zeroes* Given an integer array, move all 0’s to the end while maintaining the relative order of non-zero elements. Do it in-place without making a copy. 💡 *Key Concept:* Two-pointer technique for efficient in-place rearrangement. 👉 *2. Remove Element* Given an array and a value, remove all occurrences of that value in-place and return the number of remaining elements. 💡 *Key Concept:* In-place filtering using pointer overwrite approach. 🔹 **SQL Problem of the Day** 👉 *Find Duplicate Emails* Given a `Person` table with an email column, write a query to report all duplicate emails. 💡 *Key Concept:* GROUP BY with HAVING COUNT > 1. Small steps daily = Big progress over time 📈 Staying consistent and enjoying the process! #LeetCode #30DaysChallenge #Python #SQL #CodingJourney #Consistency #ProblemSolving #LearnInPublic
To view or add a comment, sign in
-
I did not expect a Python topic about “unique items” to feel this useful… but sets changed that fast. 🐍 Day 7 of my #30DaysOfPython journey was all about sets, and this one felt different because it was less about storing data and more about controlling it. A set is an unordered collection of distinct items. It cannot hold duplicates, which makes it super handy in real-world coding. Today I explored: 1. Creating sets with set() built-in function and {} 2. Checking length with len() 3. Using in to check if an item exists 4. Adding items with add() to add a single item and update() for multiple items 5. Removing items with remove() (raise error if item not present), discard() (does not raise error), and pop() (removes a random item) 6. Clearing a set with clear() 7. Deleting a set with del 8. Converting a list to a set to remove duplicates 9. Set operations like union(), intersection(), difference(), and symmetric_difference() 10. Checking issubset(), issuperset(), and isdisjoint() What made sets interesting to me today was how practical they are when you want uniqueness, comparison, or clean data without duplicates. They may look simple on the surface, but they solve a very specific kind of problem really well. Which Python data type has surprised you the most so far: lists, tuples, or sets? Github Link - https://lnkd.in/eJfTX-HQ #Python #LearnPython #CodingJourney #30DaysOfPython #Programming #DeveloperJourney
To view or add a comment, sign in
-
Day 11/365: Finding the Smallest & Second Smallest Element in a List 🔍📉 Today I worked on a classic list problem in Python: finding the smallest and second smallest elements in a list, along with their indexes — without sorting the list. What this code does step by step: I start with a list L containing different numbers. I initialize two variables: smallest and s_smallest (second smallest) with a value larger than most of the elements in the list. I also track their positions using smallest_index and second_smallest_index. Then I loop through the list using indexes: If the current element is less than or equal to smallest, I: move the current smallest to s_smallest, update smallest with the new value, and update both indexes accordingly. Else if the current element is only smaller than s_smallest, I update just the second smallest and its index. In the end, I print both the smallest and second smallest values with their positions in the list. What I learned from this exercise: How to track not just one, but two minimum values in a single pass through the list. How important it is to maintain both the value and the index while updating. How careful initialization of variables (like smallest and s_smallest) affects the correctness of the logic. How this pattern can be extended to find top-k smallest or largest elements efficiently without sorting. Day 11 done ✅ 354 more to go. If you have ideas like handling edge cases (e.g., duplicates, negative numbers, very large lists) or finding the k-th smallest element, send them my way — I’d love to build on this next. #100DaysOfCode #365DaysOfCode #Python #LogicBuilding #Lists #Indexing #CodingJourney #LearnInPublic #AspiringDeveloper
To view or add a comment, sign in
-
-
This SATURDAY. Yes, SATURDAY. The most requested video - "Python Advanced Tutorial For Data Domain" - goes live at 6:00 PM! A few days ago, I shared some facts about why you need to know way more than just the basics, and you guys literally showed so much LOVE in the comments. It’s clear: Everyone knows they need to learn Python (beyond just the FUNDAMENTALS). So, in this tutorial, we are going deep into the Python that is actually used in the industry. Quickly brush up on your basics (loops, functions, if-else) because we are diving into: ✅ Classes & Objects ✅ Constructors & Decorators ✅ Inheritance & Encapsulation ✅ Test Cases With PyTest ✅ Parallel Processing ✅ Incremental Data Loading ✅ Async Python ✅ Fetching Data From APIs ...And a lot of hands-on practical stuff! I literally put my HEART into this tutorial because I know how important it is for YOU. People were asking me to make this a paid course, but I chose to keep it a FREE tutorial for my DATA FAM. I want everyone on YouTube to be able to LEARN and GROW without barriers. Are you EXCITEDDD??? - If yes, simply write "We love Python" in the comments! 📍 See you this Saturday at 6:00 PM!
To view or add a comment, sign in
-
-
Day 14/365: Rotating a List by k Positions in Python 🔁📦 Today I worked on a classic array/list problem: rotating a list to the right by k positions without using built‑in shortcuts. The goal: Given a list l = [1, 2, 3, 4, 5] and k = 2, the output should be: [4, 5, 1, 2, 3] Here’s the logic I used: I run a loop k times, because I want to rotate the list to the right by k positions. In each rotation: I first store the last element: last = l[-1] Then I shift every element one step to the right: Starting from the end and moving backwards: for j in range(len(l)-1, 0, -1): I set l[j] = l[j-1] so each position takes the value from its previous index. After this loop, the first position l[0] is empty (logically), so I place the old last element there: l[0] = last After repeating this process k times, the list is rotated right by k positions. 💡 What I learned: How to manually rotate a list step by step, instead of relying on slicing tricks. How backward loops work in Python using range(start, stop, step) with a negative step. Why thinking in terms of “shifting” elements helps in many array/list problems (rotations, circular buffers, games, etc.). How repeating a simple transformation k times can solve problems without complex math. Next, I’d like to explore: Handling large k values efficiently (e.g., using k % len(l)). Rotating to the left instead of the right. Solving the same problem using slicing and comparing both approaches. Day 14 done ✅ 351 more to go. Got any other list/array transformation problems (like cyclic shifts, sliding windows, or in‑place rearrangements)? Drop them in the comments—I’d love to try them next. #100DaysOfCode #365DaysOfCode #Python #Lists #LogicBuilding #DataStructures #CodingJourney #LearnInPublic #AspiringDeveloper
To view or add a comment, sign in
-
-
Day 9 of #30DaysOfPython ✅ Today I stopped letting my code crash. Exception handling. Here's what my scripts looked like before today. You type the wrong thing, Python throws a wall of red text at you, the whole program dies, and you sit there feeling personally attacked. Today I learned how to catch those errors before they explode. Wrap the risky code in a try block, tell Python exactly what to do if something goes wrong in the except block, and your program keeps running like nothing happened. The moment that sold me: I wrote a simple division script. Without exception handling, typing 0 as the divisor crashed everything with a ZeroDivisionError. With a try/except block, it just printed "hey, you can't divide by zero" and moved on. Same error. Completely different experience. The thing that tripped me up: I was writing bare except blocks — catching every possible error without specifying which one. My mentor's voice in my head (okay, it was a Stack Overflow answer) told me that's bad practice. If you catch everything, you also catch errors you didn't know existed and hide real bugs from yourself. Always name the exception. except ValueError, except FileNotFoundError, except ZeroDivisionError. Be specific. The finally block was the other thing that clicked today. Code inside finally runs no matter what — whether the try succeeded or the except caught something. Perfect for cleanup tasks. Closing a connection. Printing a summary. Saying goodbye gracefully. What I covered today: try / except — the basic safety net Catching specific exceptions by name else block — runs only if no error occurred finally block — runs always, no matter what Raising your own errors with raise Today's mini project: a safe calculator. It handles division by zero, invalid inputs, and unknown operations — all without crashing once. Day 9 done. My code finally fails gracefully. 🎯 👇 What's the most unexpected error you've ever had to catch in Python? I want to know what's waiting for me further down this road! #Python #30DaysOfPython #ExceptionHandling #BuildInPublic #CleanCode
To view or add a comment, sign in
-
-
#Flask turns 16 today 🎉 Did you know Flask started as an April Fools’ joke by Armin Ronacher? What began as a small experiment became one of the most widely used Python web frameworks. 16 years later, it’s still powering everything from quick prototypes to production apps. 💡 About the original “Denied” microframework: Armin created “Denied” to poke fun at early microframeworks that avoided dependencies by packing everything into a single file. So he did exactly that – embedding Jinja2 and Werkzeug as a base64-encoded `.zip` inside a single Python file. A month later, the idea evolved into something real. That project became Flask – turning a joke into a framework developers still rely on today. What do you use Flask for the most?
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development