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

Поделиться
HTML-код
  • Опубликовано: 27 сен 2024

Комментарии • 79

  • @yusufallie3089
    @yusufallie3089 2 года назад +7

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

  • @AliAliOxenFree
    @AliAliOxenFree Год назад +7

    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.

    • @notfound-vk6nc
      @notfound-vk6nc Месяц назад +1

      Omg you saved me!! Thank u❤️
      I've been on this for two days😭✨

  • @jloo1900
    @jloo1900 2 года назад +4

    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.

  • @__kel
    @__kel 3 года назад +10

    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()

    • @JiggyJiggy21
      @JiggyJiggy21 2 года назад +1

      this is so easy to understand and short at the same time! Thank you so much !

    • @quynhdiem9446
      @quynhdiem9446 2 года назад +1

      you're the best!!! thanks

  • @l2dgaming490
    @l2dgaming490 4 года назад +3

    read in 1st attempt, thank you master.

  • @ruarkpotgieter7891
    @ruarkpotgieter7891 5 лет назад +17

    now this is epic!!

  • @BALJIT147
    @BALJIT147 2 года назад +1

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

  • @Jeff--vq4zb
    @Jeff--vq4zb Год назад

    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 ;-)

  • @basicallybrand
    @basicallybrand 3 года назад +4

    I don't get this

  • @petrosstyle2981
    @petrosstyle2981 3 года назад +3

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

  • @יעלליפשיץ-ס6ש
    @יעלליפשיץ-ס6ש 3 года назад +2

    Thank you 🤩🙏🏼

  • @LucaLinders
    @LucaLinders 7 месяцев назад +1

    I keep getting an error: FileNotFoundError: [Errno 2] No such file or directory: 'file.txt' but I checked the files place and the name and it should be al fine. are there other reasons why this doesn't work?

  • @khomikoow5994
    @khomikoow5994 2 года назад

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

  • @jonnymue6869
    @jonnymue6869 4 года назад

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

  • @hamoodhabibi7026
    @hamoodhabibi7026 5 лет назад +6

    my internet !!!! it keeps buffering T^T..... i have to watch in 360p

  • @DunjaLife
    @DunjaLife 4 года назад +2

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

  • @tomasmartini105
    @tomasmartini105 5 лет назад +2

    Perfect for beginners like me! Ty!

    • @isaacirwin8628
      @isaacirwin8628 4 года назад +2

      I suggest you use
      file .close()
      on line 3 so you avoid over loading your ram.

  • @dwaynethedistinguiseddinos1968
    @dwaynethedistinguiseddinos1968 3 года назад

    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.

  • @EricRobb
    @EricRobb 3 года назад

    Great Video!

  • @emanuelfolorunsho9881
    @emanuelfolorunsho9881 11 месяцев назад

    I'm putting together a quiz for an assignment, and it requires the use of a text file.

  • @Sciencedoneright
    @Sciencedoneright 3 года назад

    1:02 It's not random
    It's the description of your series

  • @haris7521
    @haris7521 2 года назад

    Just awesome

  • @eswarspython2743
    @eswarspython2743 4 года назад

    Nice video
    Watched at 2x
    Meet you in next one

  • @nauji
    @nauji 4 года назад

    Awesome !

  • @kyleyoung2768
    @kyleyoung2768 2 года назад

    can someone give me an example of what this could be used for when working on a project?

  • @smokedd9052
    @smokedd9052 3 года назад

    it's always saying No such file when I made the file already and I made it in Quick access

  • @damonchase1922
    @damonchase1922 3 года назад

    line is just your word choice for item correct?

  • @MrRahul15937
    @MrRahul15937 3 года назад

    I used rstrip('
    ')

  • @isaacirwin8628
    @isaacirwin8628 4 года назад +1

    He didn't "file.close()" which means his ram will fill up really quickly.

    • @isaiah7310
      @isaiah7310 4 года назад

      Looks like it auto-closes for me. Each time I used the file.readlines() I had to reopen the file if I wanted to call it in another instance.

    • @tinpot1978
      @tinpot1978 3 года назад +1

      @@isaiah7310 It doesn't auto-close using the method he used to open. You should use "with open("file.txt", "r").

    • @isaiah7310
      @isaiah7310 3 года назад

      @@tinpot1978 Thanks

  • @mskyba
    @mskyba 4 года назад +2

    file.read() is a lot easier

    • @isaiah7310
      @isaiah7310 4 года назад +1

      I just tested that out a few different ways. It looks like file.read() returns one large string while the file.readlines() returns each line as a separate string, which makes it easier to manipulate into a list.

  • @basicallybrand
    @basicallybrand 3 года назад

    I thought append meant add

  • @anilterapalli3894
    @anilterapalli3894 2 года назад

    I saved both textfile & idle file in same folder,
    even after that it shows me file not found😐

    • @Polshani_keshf_et
      @Polshani_keshf_et 2 года назад

      having the same issue. Could you solve it?

    • @tomoe6227
      @tomoe6227 2 года назад

      @@Polshani_keshf_et why not post the code here.... i can help

  • @armadeuzmaze3675
    @armadeuzmaze3675 3 года назад

    how to do math with files?

  • @sri4sg3
    @sri4sg3 2 года назад

    gold

  • @justifyl
    @justifyl Месяц назад

    this was an terrible jump from vid 12 to 13 , feels like a new world..

  • @yaboyisbadatfortnut3158
    @yaboyisbadatfortnut3158 4 года назад

    not working on thonny. someone help please

  • @shantanupatil7323
    @shantanupatil7323 2 года назад

    iluvu

  • @TheDickw
    @TheDickw 4 года назад +1

    Great Video.
    Thank You.

  • @leobozkir5425
    @leobozkir5425 3 года назад

    "random words"

  • @mukeshkanwarmukeshkanwar2749
    @mukeshkanwarmukeshkanwar2749 Год назад

    ऐप का क्या नाम है

  • @abhijatpandey1490
    @abhijatpandey1490 4 года назад +1

    huh...

  • @MinerMends
    @MinerMends 4 года назад

    your code is wrong lol and outdated

    • @garrybeck216
      @garrybeck216 4 года назад +4

      Instead of making unhelpful comments, how about telling us why it's wrong and outdated?

    • @templetherapy
      @templetherapy 4 года назад +2

      can you tell me please becuase mine is not working

    • @prettylou2010
      @prettylou2010 4 года назад +2

      the code does work guys.. are you putting [ ] when you start the newList or you putting () ?
      you have to put [ ] not ()

    • @WildclawsDK
      @WildclawsDK 4 года назад

      @@prettylou2010 Works for me, P3.8

    • @Sciencedoneright
      @Sciencedoneright 3 года назад

      I'm P 3.9 and it's working fine

  • @shitoshitt
    @shitoshitt 3 года назад +1

    which mode can i use to read as well as write in a text file. this to save and access data of a game

  • @sheyzi_
    @sheyzi_ 3 года назад +24

    You can also do it like this
    file = open('name.txt', 'r')
    data = file.read()
    ans = data.split(
    )
    print(ans)
    It should give you the list without adding the
    in it

    • @The.Radiance
      @The.Radiance 2 года назад

      How do you get rid of the [" "] around the text? my output is this:
      ['hello world']

    • @sheyzi_
      @sheyzi_ 2 года назад

      @@The.Radiance Cannot really remember what I was talking about... But if it's a list you should be able to do a quick for loop and then print the string individually
      If you are sure the value will only be 1 you can just print ans[0]

  • @devon6039
    @devon6039 4 года назад +5

    You're so helpful!! Thank you!!

  • @mrcoldshower465
    @mrcoldshower465 2 года назад +1

    This is outdated, I recommend watching the 'Python Tutorial: How to Read and Write Text Files' tutorial, from Essential Engineering. His code works fine

  • @abdullahmamun1777
    @abdullahmamun1777 3 года назад +1

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

  • @hackercop
    @hackercop 3 года назад

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

  • @jacksonwing5789
    @jacksonwing5789 Год назад

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

  • @DianaGwinn
    @DianaGwinn 7 месяцев назад

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

  • @Mythologos
    @Mythologos 2 года назад

    "name read is not defined".

  • @HeroesOfAesthetics
    @HeroesOfAesthetics 3 года назад

    great video Tim!! Just what I needed!

  • @Creativesnooker
    @Creativesnooker 2 года назад

    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 :)

    • @aphelelembukwana9146
      @aphelelembukwana9146 8 месяцев назад +1

      you were earlier than the next person which is me .....hope you still going and for sure you good at it now

  • @vorador4365
    @vorador4365 5 лет назад +3

    So
    = 1 character? Did not expect that hehe

  • @procerusgigas
    @procerusgigas 5 лет назад +1

    So why the hell do you start a tutorial in python 3.6 and than in the middle you switch to 3.5 WITH NO WARNING??? Just lost HOURS because I thought I went crazy, had the same code but it wasn't working....

    • @TechWithTim
      @TechWithTim  5 лет назад +7

      What code did I use that works in 3.6 that doesn’t work In 3.5 or other way around