Writing a File using Python
In the previous post we have seen that how to open and read a file using python script. Today, I have posting about how to write a file or create your own file using the script.
Reading a file is all well and good, but what if we want to create a file of our own? With Python we can do just that. It turns out that our open() function that we’re using to open a file to read needs another argument to open a file to write to.
script.py
This code creates a new file in the same folder as script.py and gives it the text What an incredible file!. It’s important to note that if there is already a file called generated_file.txt it will completely overwrite that file, erasing whatever its contents were before.
#QuarantineYourself #LearnPython #LearnDataScience
In the previous post we have seen that how to open and read a file using python script. Today, I have posting about how to write a file or create your own file using the script.
Reading a file is all well and good, but what if we want to create a file of our own? With Python we can do just that. It turns out that our open() function that we’re using to open a file to read needs another argument to open a file to write to.
script.py
with open('generated_file.txt', 'w') as gen_file:
gen_file.write("I love python!")
Here we pass the argument 'w' to open() **in order to indicate to open the file in write-mode. The default argument is 'r' and passing 'r' to **open() opens the file in read-mode as we’ve been doing.This code creates a new file in the same folder as script.py and gives it the text What an incredible file!. It’s important to note that if there is already a file called generated_file.txt it will completely overwrite that file, erasing whatever its contents were before.
#QuarantineYourself #LearnPython #LearnDataScience
What Is a CSV File?
Text files aren’t the only thing that Python can read, but they’re the only thing that we don’t need any additional parsing library to understand. CSV files are an example of a text file that impose a structure to their data. CSV stands for Comma-Separated Values and CSV files are usually the way that data from spreadsheet software (like Microsoft Excel or Google Sheets) is exported into a portable format. A spreadsheet that looks like the following
In a CSV file that same exact data would be rendered like this:
users.csv
Name,Username,Email, Asibeh Tenager, asibeh, asibeh@yahoo.com
Notice that the first row of the CSV file doesn’t actually represent any data, just the labels of the data that’s present in the rest of the file. The rest of the rows of the file are the same as the rows in the spreadsheet software, just instead of being separated into different cells they’re separated by… well I suppose it’s fair to say they’re separated by commas.
#FaceMask #KeepDistancing #LearnPython #LearnDatascience
Text files aren’t the only thing that Python can read, but they’re the only thing that we don’t need any additional parsing library to understand. CSV files are an example of a text file that impose a structure to their data. CSV stands for Comma-Separated Values and CSV files are usually the way that data from spreadsheet software (like Microsoft Excel or Google Sheets) is exported into a portable format. A spreadsheet that looks like the following
Name Username Email
Asibeh Tenager asibeh asibeh@yahoo.com
Asibeh Tenager asibeh asibeh@yahoo.comIn a CSV file that same exact data would be rendered like this:
users.csv
Name,Username,Email, Asibeh Tenager, asibeh, asibeh@yahoo.com
Notice that the first row of the CSV file doesn’t actually represent any data, just the labels of the data that’s present in the rest of the file. The rest of the rows of the file are the same as the rows in the spreadsheet software, just instead of being separated into different cells they’re separated by… well I suppose it’s fair to say they’re separated by commas.
#FaceMask #KeepDistancing #LearnPython #LearnDatascience
Forwarded from Epython Lab (Asibeh Tenager)
#Assignment
Guess The Number
Write a programme where the computer randomly generates a number between 0 and 20. The user needs to guess what the number is. If the user guesses wrong, tell them their guess is either too high, or too low. This will get you started with the random library if you haven't already used it.
Post your solution in the comment box
#LearnDataScience #LearnPython #StayHome
Guess The Number
Write a programme where the computer randomly generates a number between 0 and 20. The user needs to guess what the number is. If the user guesses wrong, tell them their guess is either too high, or too low. This will get you started with the random library if you haven't already used it.
Post your solution in the comment box
#LearnDataScience #LearnPython #StayHome
👍2
Python is a general-purpose programming language. It can do almost all of what other languages can do with comparable, or faster, speed. It is often chosen by Data Analysts and Data Scientists for prototyping, visualization, and execution of data analyses on datasets.
There’s an important question here. Plenty of other programming languages, like R, can be useful in the field of data science. Why are so many people choosing Python?
One major factor is Python’s versatility. There are over 125,000 third-party Python libraries. These libraries make Python more useful for specific purposes, from the traditional (e.g. web development, text processing) to the cutting edge (e.g. AI and machine learning). For example, a biologist might use the Biopython library to aid their work in genetic sequencing.
Additionally, Python has become a go-to language for data analysis. With data-focused libraries like pandas, NumPy, and Matplotlib, anyone familiar with Python’s syntax and rules can use it as a powerful tool to process, manipulate, and visualize data.
#FaceMask #KeepDistancing #LearnPython #LearnDataScience
Join @python4fds for more information
There’s an important question here. Plenty of other programming languages, like R, can be useful in the field of data science. Why are so many people choosing Python?
One major factor is Python’s versatility. There are over 125,000 third-party Python libraries. These libraries make Python more useful for specific purposes, from the traditional (e.g. web development, text processing) to the cutting edge (e.g. AI and machine learning). For example, a biologist might use the Biopython library to aid their work in genetic sequencing.
Additionally, Python has become a go-to language for data analysis. With data-focused libraries like pandas, NumPy, and Matplotlib, anyone familiar with Python’s syntax and rules can use it as a powerful tool to process, manipulate, and visualize data.
#FaceMask #KeepDistancing #LearnPython #LearnDataScience
Join @python4fds for more information
❤3👍3
Bubble Sort Algorithm Explained! Python Implementation & Step-by-Step Guide
https://www.youtube.com/watch?v=x6WGF8zDWZA
https://www.youtube.com/watch?v=x6WGF8zDWZA
YouTube
Bubble Sort Algorithm Explained! Python Implementation & Step-by-Step Guide
🚀 Want to master sorting algorithms? In this tutorial, we break down Bubble Sort with easy-to-follow examples and Python code! 📌
🔹 What you'll learn:
✔️ Step-by-step Bubble Sort explanation
✔️ Python code implementation
✔️ Optimization techniques
✔️ Complexity…
🔹 What you'll learn:
✔️ Step-by-step Bubble Sort explanation
✔️ Python code implementation
✔️ Optimization techniques
✔️ Complexity…
❤4👍1
Learn More About Algorithmic Thinking:
If you're interested in diving deeper into algorithmic problem-solving, check out these additional tutorials:
📌 Bubble Sort Algorithm Explained! Python Implementation & Step-by-Step Guide
https://www.youtube.com/watch?v=x6WGF8zDWZA
📌 Linear Search Algorithm: https://www.youtube.com/watch?v=f0KsENxdTGI
📌 Binary Search Algorithm: https://www.youtube.com/watch?v=_MjGCuwFDuw
🙏 Support My Work:
🎁 Send a thanks gift or become a member: https://www.youtube.com/channel/UCsFz0IGS9qFcwrh7a91juPg/join
💬 Join Our Telegram Discussion Group: https://t.me/epythonlab
If you're interested in diving deeper into algorithmic problem-solving, check out these additional tutorials:
📌 Bubble Sort Algorithm Explained! Python Implementation & Step-by-Step Guide
https://www.youtube.com/watch?v=x6WGF8zDWZA
📌 Linear Search Algorithm: https://www.youtube.com/watch?v=f0KsENxdTGI
📌 Binary Search Algorithm: https://www.youtube.com/watch?v=_MjGCuwFDuw
🙏 Support My Work:
🎁 Send a thanks gift or become a member: https://www.youtube.com/channel/UCsFz0IGS9qFcwrh7a91juPg/join
💬 Join Our Telegram Discussion Group: https://t.me/epythonlab
YouTube
Bubble Sort Algorithm Explained! Python Implementation & Step-by-Step Guide
🚀 Want to master sorting algorithms? In this tutorial, we break down Bubble Sort with easy-to-follow examples and Python code! 📌
🔹 What you'll learn:
✔️ Step-by-step Bubble Sort explanation
✔️ Python code implementation
✔️ Optimization techniques
✔️ Complexity…
🔹 What you'll learn:
✔️ Step-by-step Bubble Sort explanation
✔️ Python code implementation
✔️ Optimization techniques
✔️ Complexity…
👍1
💡 Researchers & Beginners in Python!
This step-by-step guide walks you through installing and setting up Python on Windows using the Microsoft Store, along with VS Code setup to get you coding in no time!
🔗 https://www.youtube.com/watch?v=EGdhnSEWKok
Like & share if you found this helpful!
#PythonForResearch #PythonSetup #DataScience #AI #MachineLearning #CodingForBeginners #ResearchTools #Academia #PythonOnWindows
This step-by-step guide walks you through installing and setting up Python on Windows using the Microsoft Store, along with VS Code setup to get you coding in no time!
🔗 https://www.youtube.com/watch?v=EGdhnSEWKok
Like & share if you found this helpful!
#PythonForResearch #PythonSetup #DataScience #AI #MachineLearning #CodingForBeginners #ResearchTools #Academia #PythonOnWindows
YouTube
How to Install Python on Windows: Beginner’s Guide (Step-by-Step)
Want to start coding in Python on Windows? This beginner-friendly guide walks you through the setup process—from installing Python and VS Code to writing your first Python script. 🚀 Whether you're a beginner or switching to Python, this tutorial makes it…
👍2
🚀 How to Become a Self-Taught AI Developer?
AI is transforming the world, and the best part? You don’t need a formal degree to break into the field! With the right roadmap and hands-on practice, anyone can become an AI developer. Here’s how you can do it:
1️⃣ Master the Fundamentals of Programming
Start with Python, as it’s the most popular language for AI. Learn data structures, algorithms, and object-oriented programming (OOP). Practice coding on LeetCode and HackerRank.
👉How to get started Python: https://www.youtube.com/watch?v=EGdhnSEWKok
How to Create & Use Python Virtual Environments | ML Project Setup + GitHub Actions CI/CD https://youtu.be/qYYYgS-ou7Q
👉Beginner's Guide to Python Programming. Getting started now: https://youtu.be/ISv6XIl1hn0
👉Data Structures with Projects full tutorial for beginners
https://www.youtube.com/watch?v=lbdKQI8Jsok
👉OOP in Python - beginners Crash Course https://www.youtube.com/watch?v=I7z6i1QTdsw
2️⃣ Build a Strong Math Foundation
AI relies on:
🔹 Linear Algebra – Matrices, vectors (used in deep learning) https://youtu.be/BNa2s6OtWls
🔹 Probability & Statistics – Bayesian reasoning, distributions https://youtube.com/playlist?list=PL0nX4ZoMtjYEl_1ONxAZHu65DPCQcsHmI&si=tAz0B3yoATAjE8Fx
🔹 Calculus – Derivatives, gradients (used in optimization)
📚 Learn from 3Blue1Brown, Khan Academy, or MIT OpenCourseWare.
3️⃣ Learn Machine Learning (ML)
Start with traditional ML before deep learning:
✔ Supervised Learning – Linear regression, decision trees https://youtube.com/playlist?list=PL0nX4ZoMtjYGV8Ff_s2FtADIPfwlHst8B&si=buC-eP3AZkIjzI_N
✔ Unsupervised Learning – Clustering, PCA
✔ Reinforcement Learning – Q-learning, deep Q-networks
🔗 Best course? Andrew Ng’s ML Course on Coursera.
4️⃣ Dive into Deep Learning
Once comfortable with ML, explore:
⚡ Neural Networks (ANNs, CNNs, RNNs, Transformers)
⚡ TensorFlow & PyTorch (Industry-standard deep learning frameworks)
⚡ Computer Vision & NLP
Try Fast.ai or the Deep Learning Specialization by Andrew Ng.
5️⃣ Build Real-World Projects
The best way to learn AI? DO AI. 🚀
💡 Train models with Kaggle datasets
💡 Build a chatbot, image classifier, or recommendation system
💡 Contribute to open-source AI projects
6️⃣ Stay Updated & Join the AI Community
AI evolves fast! Stay ahead by:
🔹 Following Google AI, OpenAI, DeepMind
🔹 Engaging in Reddit r/MachineLearning, LinkedIn AI discussions
🔹 Attending AI conferences like NeurIPS & ICML
7️⃣ Create a Portfolio & Apply for AI Roles
📌 Publish projects on GitHub
📌 Share insights on Medium/Towards Data Science
📌 Network on LinkedIn & Kaggle
No CS degree? No problem! AI is about curiosity, consistency, and hands-on experience. Start now, keep learning, and let’s build the future with AI. 🚀
Tagging AI learners & enthusiasts: What’s your AI learning journey like? Let’s connect!. 🔥👇
#AI #MachineLearning #DeepLearning #Python #ArtificialIntelligence #SelfTaught
AI is transforming the world, and the best part? You don’t need a formal degree to break into the field! With the right roadmap and hands-on practice, anyone can become an AI developer. Here’s how you can do it:
1️⃣ Master the Fundamentals of Programming
Start with Python, as it’s the most popular language for AI. Learn data structures, algorithms, and object-oriented programming (OOP). Practice coding on LeetCode and HackerRank.
👉How to get started Python: https://www.youtube.com/watch?v=EGdhnSEWKok
How to Create & Use Python Virtual Environments | ML Project Setup + GitHub Actions CI/CD https://youtu.be/qYYYgS-ou7Q
👉Beginner's Guide to Python Programming. Getting started now: https://youtu.be/ISv6XIl1hn0
👉Data Structures with Projects full tutorial for beginners
https://www.youtube.com/watch?v=lbdKQI8Jsok
👉OOP in Python - beginners Crash Course https://www.youtube.com/watch?v=I7z6i1QTdsw
2️⃣ Build a Strong Math Foundation
AI relies on:
🔹 Linear Algebra – Matrices, vectors (used in deep learning) https://youtu.be/BNa2s6OtWls
🔹 Probability & Statistics – Bayesian reasoning, distributions https://youtube.com/playlist?list=PL0nX4ZoMtjYEl_1ONxAZHu65DPCQcsHmI&si=tAz0B3yoATAjE8Fx
🔹 Calculus – Derivatives, gradients (used in optimization)
📚 Learn from 3Blue1Brown, Khan Academy, or MIT OpenCourseWare.
3️⃣ Learn Machine Learning (ML)
Start with traditional ML before deep learning:
✔ Supervised Learning – Linear regression, decision trees https://youtube.com/playlist?list=PL0nX4ZoMtjYGV8Ff_s2FtADIPfwlHst8B&si=buC-eP3AZkIjzI_N
✔ Unsupervised Learning – Clustering, PCA
✔ Reinforcement Learning – Q-learning, deep Q-networks
🔗 Best course? Andrew Ng’s ML Course on Coursera.
4️⃣ Dive into Deep Learning
Once comfortable with ML, explore:
⚡ Neural Networks (ANNs, CNNs, RNNs, Transformers)
⚡ TensorFlow & PyTorch (Industry-standard deep learning frameworks)
⚡ Computer Vision & NLP
Try Fast.ai or the Deep Learning Specialization by Andrew Ng.
5️⃣ Build Real-World Projects
The best way to learn AI? DO AI. 🚀
💡 Train models with Kaggle datasets
💡 Build a chatbot, image classifier, or recommendation system
💡 Contribute to open-source AI projects
6️⃣ Stay Updated & Join the AI Community
AI evolves fast! Stay ahead by:
🔹 Following Google AI, OpenAI, DeepMind
🔹 Engaging in Reddit r/MachineLearning, LinkedIn AI discussions
🔹 Attending AI conferences like NeurIPS & ICML
7️⃣ Create a Portfolio & Apply for AI Roles
📌 Publish projects on GitHub
📌 Share insights on Medium/Towards Data Science
📌 Network on LinkedIn & Kaggle
No CS degree? No problem! AI is about curiosity, consistency, and hands-on experience. Start now, keep learning, and let’s build the future with AI. 🚀
Tagging AI learners & enthusiasts: What’s your AI learning journey like? Let’s connect!. 🔥👇
#AI #MachineLearning #DeepLearning #Python #ArtificialIntelligence #SelfTaught
YouTube
How to Install Python on Windows: Beginner’s Guide (Step-by-Step)
Want to start coding in Python on Windows? This beginner-friendly guide walks you through the setup process—from installing Python and VS Code to writing your first Python script. 🚀 Whether you're a beginner or switching to Python, this tutorial makes it…
👍1
✅ Parse XML → Export to CSV using pure Python — no external libraries, no fluff. https://youtu.be/ii1UqhJwAkg
This beginner-friendly project walks you through:
🔍 Extracting structured data from XML files
⚙️ Automating file conversion and cleanup
📂 Working with realistic data formats used in enterprise tools, APIs, and fan databases
I used character data from the Dexter TV series as a sample XML source, making it fun and practical at the same time.
🎓 Perfect for:
Students & junior devs building portfolio projects
Data analysts working with legacy XML feeds
Anyone learning Python automation and data wrangling
#Python #Pandas #DataProjects #Automation #XMLtoCSV #DataExtraction #BeginnerFriendly #LearnPython #RealWorldPython #PortfolioProject #PythonForData
This beginner-friendly project walks you through:
🔍 Extracting structured data from XML files
⚙️ Automating file conversion and cleanup
📂 Working with realistic data formats used in enterprise tools, APIs, and fan databases
I used character data from the Dexter TV series as a sample XML source, making it fun and practical at the same time.
🎓 Perfect for:
Students & junior devs building portfolio projects
Data analysts working with legacy XML feeds
Anyone learning Python automation and data wrangling
#Python #Pandas #DataProjects #Automation #XMLtoCSV #DataExtraction #BeginnerFriendly #LearnPython #RealWorldPython #PortfolioProject #PythonForData
YouTube
How to Transform Complex Nested XML Data into CSV/Pandas in Python
Learn how to convert complex nested XML data into clean CSV or Pandas DataFrames using pure Python. This hands-on tutorial covers XML parsing, tree navigation, and flattening nested structures — perfect for data analysts, automation developers, and Python…
👍5
🚀 New Python Tutorial Alert!
Boolean logic is the foundation of every programming decision. Whether it’s controlling the flow of your code, building smarter conditions, or making algorithms more efficient—understanding it well is a must for every Python developer.
In my latest tutorial, I break down Boolean logic in Python step by step, with simple explanations and clear examples for beginners.
👉 Watch here: https://www.youtube.com/watch?v=DRiifF9SX2w
If you’re just starting out or want to sharpen your fundamentals, this one’s for you.
#Python #Programming #CodingForBeginners #LearnPython #BooleanLogic
Boolean logic is the foundation of every programming decision. Whether it’s controlling the flow of your code, building smarter conditions, or making algorithms more efficient—understanding it well is a must for every Python developer.
In my latest tutorial, I break down Boolean logic in Python step by step, with simple explanations and clear examples for beginners.
👉 Watch here: https://www.youtube.com/watch?v=DRiifF9SX2w
If you’re just starting out or want to sharpen your fundamentals, this one’s for you.
#Python #Programming #CodingForBeginners #LearnPython #BooleanLogic
YouTube
Python for Beginners | Understand Boolean Logic in Python
Learn Boolean Logic in Python step by step in this beginner-friendly tutorial!
We’ll cover Boolean values (True, False), comparison operators, logical operators (and, or, not), and truth tables with clear explanations and real-world examples.
By the end…
We’ll cover Boolean values (True, False), comparison operators, logical operators (and, or, not), and truth tables with clear explanations and real-world examples.
By the end…
👍5❤2
🚀 New Python Tutorial!
Python Lists | Beginner-Friendly Tutorial with Real-World Examples
https://youtu.be/KDZcMK7FoA0
Python Lists | Beginner-Friendly Tutorial with Real-World Examples
https://youtu.be/KDZcMK7FoA0
YouTube
Python for Beginners | Python Lists | Beginner-Friendly Tutorial with Real-World Examples
Dive into Python lists with this beginner-friendly tutorial! In just 15 minutes, you'll learn how to:
Create and access lists
Modify and slice data
Utilize stride for efficient data handling
Combine and remove list items
Work with nested lists for structured…
Create and access lists
Modify and slice data
Utilize stride for efficient data handling
Combine and remove list items
Work with nested lists for structured…
👍3