How to Read and Write Files in Python | File Handling Tutorial in Python

preview_player
Показать описание
This is a tutorial video on how to read and write files in Python. This video covers all the basic concepts required to get started with file handling in Python. File objects in Python can be used to read the contents of a file and also file objects can be used to write or append data into a file.

In this video, we cover all the basic concepts required to get started with handing files in Python. We first look at how to read a file which is stored in our operating system. And then cover the concepts of how to write data into a file and also how to append data into a file.
We check out the different between using write and append in Python.

To open the file, we use context manager as well as the traditional method to open a file. We talk about the advantages of using context manager while opening a file in python and also explain why it is recommended in python to always use context manager when dealing with files.

Timestamps:
00:00 How to Read and Write Files in Python
00:39 How to Read a file in Python
02:55 How to use Context Manager to open a file in Python
07:16 How to Write a file in Python
09:09 How to Append a file in Python
10:20 Program to read a file and append data to another file
13:17 How to access files in different path in Python

In this video, we also talk about to how to read a file which is present in different paths or directories. By providing absolute path or relative path to the file we can tell python to look for the desired file in that specific location. However, we can also change the current working directory to point at the path where our desired file is placed.
If path is not mentioned, then Python always looks for the file in the current working directory. However, we can change the current working directory so as to point it to the location where our desired file is placed.
Alternatively, we can also provide the directory path of the file which we are trying to read. We can specify a path in two ways, one is by specifying the absolute path and second is by specifying the relative path.
In this video, we talk about relative and absolute path and also show how you can extract the current working directory and also how you can change the current working directory.

Hope you learnt something from this video. If yes, then please make sure to like and share the video with friends and colleagues who may be interested in learning about files in python.
Also, please do not hesitate to leave a comment if you have any questions related this topic. I would truly appreciate your feedback on this video in the comments section.
Finally, it would really help if you can subscribe to the channel and stay tuned for more useful video’s.

I hope this video was helpful and gives you a good understanding of regular expressions in python. If you liked what you saw, then please make sure to like, subscribe and comment any feedback you may have.
Also please do not hesitate to share the video with your friends and colleagues who may be interested in learning regular expression in python.

🔴 WATCH MORE VIDEOS HERE 👇

✅ SQL Tutorial - Basic concepts:

✅ SQL Tutorial - Intermediate concepts:

✅ SQL Tutorial - Advance concepts:

✅ Practice Solving Basic SQL Queries:

✅ Practice Solving Intermediate SQL Queries:

✅ Practice Solving Complex SQL Queries:

✅ Data Analytics Career guidance:

✅ SQL Course, SQL Training Platform Recommendations:

✅ Python Tutorial:

✅ Git and GitHub Tutorial:

✅ Data Analytics Projects:

THANK YOU,
Thoufiq
Рекомендации по теме
Комментарии
Автор

Best coding channel there is on YouTube by far, better than even channels with 2m subscribers. appreciate how you give examples and clearly explain things.

sophialikestocode
Автор

Your examples are very clear and I enjoyed your presentation very much. I am working through a chapter on Text Files in my book "Practical Programming 3rd Edition." This video is has helped me a lot, thank you for your teaching.

cookgs
Автор

This is the most important tutorial I have ever gone through in python
Thank for the effort and everything

gatjuatwicteatriek
Автор

Awesome clarity, great efforts, crisp explanation👌Keep up your good work. It sure is beneficial👌🏻

fathimafarahna
Автор

One thing that i like about your way of teaching is that you try to answer every question that may aries in mind of learner of any level and even if its too basic for someone who knows it already it doesn't bore them to learn again... Thanks for awesome videos. Keep up buddy ✌️.

shubhampatil
Автор

wow i finally found a good tutorial thanks!

cold
Автор

The quality of your videos is simply amazing in terms of content. 👍👍👍

MdRizwan-uudv
Автор

Hi, your explanation is really awesome with exact terminology and clarity in thoughts. It's my request too to continue making such technical stuff.. Thank you

aruntejareddy
Автор

Thx at least for u ur video is impactful

ssenyangeraymod
Автор

well explained for beginners as well !

fero___
Автор

Good channel👍 I'm one of your subscriber

shikhavarma
Автор

The statement `if line.startswith('Answer'):` works the same without the boolean declaration `is True`

dhex
Автор

what if my file is present in the desktop folder, and I want to access it using relative path, will the double dot(..) work as well...?

wollongar
Автор

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'hotel.csv' pls tell how to solve this problem, pls

mathewswilliams
Автор

Hi, Taufique, may I know which GUI are u using to run Python here..

sajjadsmeinbox
Автор

Please teach us web Automation using Python

therisingstars
Автор

bro give me my name pis way for your help jzkl

warraabbaamaarituu