Python Beginner Tutorial #9 - File Operations

Поділитися
Вставка
  • Опубліковано 21 лип 2024
  • In today's episode we will learn how to operate with files. How to write into files, how to read from files and much more.
    Python Documentation: docs.python.org/3/tutorial/in...
    Website: www.neuralnine.com/
    Instagram: / neuralnine
    Twitter: / neuralnine
    GitHub: github.com/NeuralNine
    Programming Books: www.neuralnine.com/books/
    Outro Music From: www.bensound.com/
    Subscribe and Like for more free content!
  • Наука та технологія

КОМЕНТАРІ • 35

  • @VypeReaper
    @VypeReaper 3 роки тому +11

    For those with issues, the .txt file must be in the same directory as your Python code/project. In other words, inside your Python project directory unless you specifically state in your code where the file is (I will give an example of it).
    Neuralnine has his project (files.py) on his desktop. The "f" is just a variable name. You can use any name you want. It ends in the colon ":" because it is a statement, just like using conditional statements; they end in the colon ":"
    # Inside the Python project:
    with open('file.txt', 'r') as c:
    content = c.read()
    print(content)
    # Outside the Python project/different directory:
    with open("/path/to/directory/myfile.txt", 'r') as variableName:
    content = variableName.read()
    print(content)

    • @imalex4543
      @imalex4543 3 роки тому +6

      dont get confused though, the "c" or "f" after 'as' is just a name, you can call it whatever you want, it doesnt have to be f or c, you can do: with open("file.txt", "r") as ThisIsAnAwesomeFile: (just make sure that the capitals match when you read the file, because it is case sensitive)

    • @maborarany7688
      @maborarany7688 6 місяців тому

      STILL DIDNT WORJK AAHHAHAHAHAH

    • @VypeReaper
      @VypeReaper 6 місяців тому +1

      @@imalex4543 Thank you for the accuracy, I have updated the comment.

  • @jrgomez
    @jrgomez Рік тому

    I love your videos! They are short and concise. Kudos!

  • @invinciblenoman
    @invinciblenoman 3 роки тому +2

    great job. my concept for open and with open is cleared now. thank you

  • @jrgomez
    @jrgomez Рік тому +1

    Great content! Love your teaching style.

  • @filipborring3239
    @filipborring3239 3 місяці тому

    This video helped me understand everything I didn’t understand from school. Wish me luck on the certificate

  • @chloetheragdollkitten9890
    @chloetheragdollkitten9890 Рік тому

    Thanks for all your great videos.

  • @Alex-jk1kd
    @Alex-jk1kd 3 роки тому

    Amazing content, greetings from brazil!

  • @G4shmaster
    @G4shmaster 3 місяці тому

    Thank you for this useful info😊

  • @prashantgoutam1798
    @prashantgoutam1798 Рік тому

    Great video helped alot🔥

  • @GriteKidsTV
    @GriteKidsTV 3 роки тому +11

    You can gradually see the number of views decreasing each video. WEAKLINGS...

    • @patjustpat8178
      @patjustpat8178 3 роки тому

      How many tutorial parts do you reckon someone will need to make so that the last part has 1 view? Should be a constant decrement based on the amount of views on the first chapter. On my desk by Monday.

    • @GriteKidsTV
      @GriteKidsTV 3 роки тому

      @@patjustpat8178 Humans are irrational, it is impossible to calculate the decrease rate.

  • @JyskMaker
    @JyskMaker Рік тому

    Can you copy files that way to?

  • @quantumlegend7991
    @quantumlegend7991 Рік тому

    Coming out of current directory?

  • @emanabdelhaleem7561
    @emanabdelhaleem7561 3 місяці тому

    Thanks a lot

  • @TheMarci201
    @TheMarci201 3 роки тому +1

    It makes no sense that these have so little views. I would have thought that a lot of people started to code at home during the pandemic.

  • @hammerheadofhorror6589
    @hammerheadofhorror6589 4 роки тому +1

    hey why do i have FileNotFoundError: [Errno 2] No such file or directory: 'file.txt' at 4:40 and it always says i can find any file i want to work on.

    • @StayViralMedia
      @StayViralMedia 4 роки тому

      make sure the file is in the same directory as your python project. python will not find the file if it isn't.

  • @parvjain3419
    @parvjain3419 4 роки тому +4

    great job sir

  • @uniquechannel.5168
    @uniquechannel.5168 28 днів тому

    excellent explanation but the screen is very small cant see clearly, better to zoom in a little bit

  • @Ghfhuchdufuc
    @Ghfhuchdufuc Рік тому

    Thanks

  • @trustToLove
    @trustToLove 3 роки тому +1

    Hi bro! You are great, thanks fol all videos and for the content) I had one problem with the file operations(Error: could not find a file), could you help plz?

    • @M8rix
      @M8rix 3 роки тому +1

      make sure your file is in the same directory as your python project as python can't find the file if it isn't

    • @trustToLove
      @trustToLove 3 роки тому

      @@M8rix not this problem, I knew that, but the problem is still with me

  • @teimoorbahrami8634
    @teimoorbahrami8634 3 роки тому

    alternative for IDLE?

    • @amulyaparitosh660
      @amulyaparitosh660 3 роки тому

      you can use other IDEs like Pycharm, VS Code...etc. I myself use vs code because it supports other languages as well. But if only just started lerning python then IDLE is advised and afterwords you can use othes IDEs.

  • @sameergupta3067
    @sameergupta3067 4 роки тому +2

    Hey, wanted to get in touch with you and discuss something about your channel. Can we connect on any social media platform?

    • @NeuralNine
      @NeuralNine  4 роки тому

      I'm available at Instagram

  • @nuhhurmanli4110
    @nuhhurmanli4110 8 місяців тому

    Hi my friend!
    Please Use bigger fonts when U capturing a video from your screen.
    I could watch U with more passion :D
    Have a nice day!

  • @Vertig_Pro
    @Vertig_Pro Рік тому

    your thing is super blurry

  • @wilsonjimmytuyishime300
    @wilsonjimmytuyishime300 8 місяців тому

    very small, difficult to see