Python Programming Tutorial #13 - How to Read a Text File

preview_player
Показать описание
This is the 13th video in my python programming series. Today I talk about how to read from a text file using python.

Note: Make sure your file in in the directory as your python script or else this will not work! Also make sure you use the 'r' file mode.

Please LIKE and SUBSCRIBE for more content.

Video Tags:
python,python tutorial,python language,python full course,python course,learn python,learn python programming,python tutorial for beginners,python tutorial 2018,python programming tutorial,python programming language,software development,programming tutorial,tech with tim, reading a text file
Рекомендации по теме
Комментарии
Автор

Your are really awesome ! I had a hard time digesting these in school curriculum and you managed to enlighten me in minutes. Thank you so much.

jloo
Автор

You can also do it like this

file = open('name.txt', 'r')
data = file.read()
ans = data.split(\n)

print(ans)

It should give you the list without adding the \n in it

sheyzi_
Автор

for anyone watching way in the future, windows automatically hides file extensions (such as .txt) by default. You can change this by opening any folder, clicking on the "View" tab, and checking the "File name extensions" box.

AliAliOxenFree
Автор

I honestly felt like giving up on python, you've made it so easy to understand!

yusufallie
Автор

I am working on a project right now and you helped me a lot! Thank you

dljjspb
Автор

Found your channel yesterday and subscribed... just starting my python journey so I am a bit late to the party lol, been at it a few weeks now and find your style of teaching is helping things stick so thank you. Subbed :)

Creativesnooker
Автор

well thx man for the great introduction into learning how to code.

jonnymue
Автор

Thanks Tim! helped me with the capture the flag game I was playing.

BALJIT
Автор

Hey all i'm using python 3.9 and this no longer works. Use the following instead.

file = open('file.txt', 'r')
print(file.read())
file.close()

__kel
Автор

read in 1st attempt, thank you master.

ldgaming
Автор

Only needed the first 1;23 seconds of the video but thank ya very much mister

jacksonwing
Автор

Recommend using the "with" key to open and write.

khomikoow
Автор

Do you have a video to show how to path join with files (txt in my case)? If so could you please show me/anyone else that needs this video? Thank you for this video as well.

dwaynethedistinguiseddinos
Автор

Nice video
Watched at 2x
Meet you in next one

eswarspython
Автор

"r" argument is not necessary in the open() function because r is the default option.

petrosstyle
Автор

I just LOL'd when Tim wrote "easy" at the end but didn't hit enter to leave the EOF (end of file) at the bottom, and a newline character after "easy". As a teenager I developed a habit of always having a blank line at the bottom, and this video is why. Tim's tutorial is good though, he demonstrates how to handle any scenario. Next lesson: why to never use whitespace characters on your files ;-)

Jeff--vqzb
Автор

Can you use .splitlines() to remove the \n?

nashfpv
Автор

after I put -1 first time it doesn't work anymore :( (3.8 version)

DunjaLife
Автор

Can we create 5 folders {hello, tim, python, learning, easy} reading from text file??

abdullahmamun
Автор

When using linux python always places my text file in /home/myUsername directory instead of next to the .py file, why is this?

hackercop