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

  Рет қаралды 14,180

techTFQ

techTFQ

Күн бұрын

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 - Basic c...
✅ SQL Tutorial - Intermediate concepts:
• SQL Tutorial - Interme...
✅ SQL Tutorial - Advance concepts:
• SQL Tutorial - Advance...
✅ Practice Solving Basic SQL Queries:
• Practice Solving BASIC...
✅ Practice Solving Intermediate SQL Queries:
• Practice Solving INTER...
✅ Practice Solving Complex SQL Queries:
• Practice Solving COMPL...
✅ Data Analytics Career guidance:
• Data Analytics career ...
✅ SQL Course, SQL Training Platform Recommendations:
• SQL Course / Training
✅ Python Tutorial:
• Python Tutorial
✅ Git and GitHub Tutorial:
• Git and GitHub
✅ Data Analytics Projects:
• Data Analytics Projects
THANK YOU,
Thoufiq

Пікірлер: 38
@MdRizwan-uu9dv
@MdRizwan-uu9dv Жыл бұрын
The quality of your videos is simply amazing in terms of content. 👍👍👍
@gatjuatwicteatriek4590
@gatjuatwicteatriek4590 Жыл бұрын
This is the most important tutorial I have ever gone through in python Thank for the effort and everything
@sophialikestocode
@sophialikestocode 11 ай бұрын
Best coding channel there is on KZbin by far, better than even channels with 2m subscribers. appreciate how you give examples and clearly explain things.
@techTFQ
@techTFQ 11 ай бұрын
Thank you very much Tris .. So glad you like the content 🙏🏼
@user-ny1fs9qq1w
@user-ny1fs9qq1w Жыл бұрын
Great video! Thank You!
@aruntejareddy3067
@aruntejareddy3067 Жыл бұрын
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
@005_manav_paneliya2
@005_manav_paneliya2 Жыл бұрын
Damn good explanation as usual ❤❤❤
@moody_moon_coder
@moody_moon_coder Жыл бұрын
Great video Mr techTFQ.
@rahamathansari
@rahamathansari 8 ай бұрын
excellent
@cold9694
@cold9694 2 жыл бұрын
wow i finally found a good tutorial thanks!
@techTFQ
@techTFQ 2 жыл бұрын
Thank you so much 🙏🏼 Glad you liked it ..
@ssenyangeraymod2047
@ssenyangeraymod2047 Жыл бұрын
Thx at least for u ur video is impactful
@nurlansalkinbayev3890
@nurlansalkinbayev3890 2 жыл бұрын
Thanks for your work.
@techTFQ
@techTFQ 2 жыл бұрын
Your welcome 🙏🏼 Glad you liked it..
@fathimafarahna2633
@fathimafarahna2633 3 жыл бұрын
Awesome clarity, great efforts, crisp explanation👌Keep up your good work. It sure is beneficial👌🏻
@techTFQ
@techTFQ 3 жыл бұрын
Thank you 🥰😍
@fero___3005
@fero___3005 2 жыл бұрын
well explained for beginners as well !
@techTFQ
@techTFQ 2 жыл бұрын
Thank you Geoffrey
@diegomartin5250
@diegomartin5250 2 жыл бұрын
Excelente!!! 👍👍👍👍
@techTFQ
@techTFQ 2 жыл бұрын
Thank you :)
@girishnaveen9059
@girishnaveen9059 3 жыл бұрын
Explanation was good thanks for this
@techTFQ
@techTFQ 3 жыл бұрын
Thank you so much for the feedback 😊 Glad it was helpful to you..
@vishvajeetsolanke6648
@vishvajeetsolanke6648 3 жыл бұрын
Awesome 👏
@techTFQ
@techTFQ 3 жыл бұрын
Thank you Vishva garu ...😀
@shubhampatil3301
@shubhampatil3301 2 жыл бұрын
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 ✌️.
@techTFQ
@techTFQ 2 жыл бұрын
Thank you Shubham :) Really happy to read this feeback. Glad you noticed :)
@shikhavarma4049
@shikhavarma4049 3 жыл бұрын
Good channel👍 I'm one of your subscriber
@techTFQ
@techTFQ 3 жыл бұрын
Thank you so much.. means a lot ☺️
@amishasrivastava6518
@amishasrivastava6518 2 жыл бұрын
Thank you so much
@amishasrivastava6518
@amishasrivastava6518 2 жыл бұрын
Your explanation is awesome.....I could understand each and everything
@techTFQ
@techTFQ 2 жыл бұрын
Awesome.. i am so glad to hear that :)
@dhex8122
@dhex8122 Жыл бұрын
The statement `if line.startswith('Answer'):` works the same without the boolean declaration `is True`
@wollongar2014
@wollongar2014 2 жыл бұрын
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...?
@therisingstars8110
@therisingstars8110 Жыл бұрын
Please teach us web Automation using Python
@sajjadsmeinbox
@sajjadsmeinbox Жыл бұрын
Hi, Taufique , may I know which GUI are u using to run Python here..
@techTFQ
@techTFQ Жыл бұрын
Its visual studio code
@mathewswilliams9919
@mathewswilliams9919 6 ай бұрын
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
@user-wu3uk7nv9r
@user-wu3uk7nv9r 11 ай бұрын
bro give me my name pis ;;;;;;;;;;;;;;any way for your help jzkl
I PEELED OFF THE CARDBOARD WATERMELON!#asmr
00:56
HAYATAKU はやたく
Рет қаралды 34 МЛН
Uma Ki Super Power To Dekho 😂
00:15
Uma Bai
Рет қаралды 53 МЛН
File Handling in Python | Python Tutorials for Beginners #lec95
45:32
Jenny's Lectures CS IT
Рет қаралды 67 М.
Python Beginner Tutorial #9 - File Operations
15:39
NeuralNine
Рет қаралды 27 М.
Learn Python With This ONE Project!
55:04
Tech With Tim
Рет қаралды 1,6 МЛН
Python Tutorial: Using Try/Except Blocks for Error Handling
10:34
Corey Schafer
Рет қаралды 677 М.
Python Object Oriented Programming (OOP) - For Beginners
53:06
Tech With Tim
Рет қаралды 3,2 МЛН