Python Tutorial: How to Read and Write Text Files

Kludgeware
Kludgeware
35.1 هزار بار بازدید - 4 سال پیش - GitHub source code:
GitHub source code: https://tinyurl.com/y343vbuu

This video teaches the basics of how to read and write basic text files using Python 3. The basic "template" uses an open block, with the template:
    with open("filename.txt", "mode") as file:      
           var = file.read().       -- this reads the file and stores in the variable "var" as a string.  
           file.close()                -- this closes the file to prevent unwanted access.

The available modes are read (r) write(w) and append (a). Read will give the user read only access. No contents of the file can be over written. Write mode (w) gives the user the ability to create new files. Append (a) gives the user access to the file to add contents to the end. Make sure to not use w mode and accidentally delete your files!

Please feel free to leave any questions, suggestions, or feedback in the comments below. Good luck!

ABOUT ME: I am a recent graduate from the University of Tennessee Knoxville, and I am on a mission to provide educational and informative content in the realm of engineering. This can range from programming lessons to videos about mechanics of materials, to circuits, and beyond! Most of the lessons I learned in college came not through the classroom, but the time I spent learning things by myself through online communities such as YouTube. I hope to give back to the community by providing valuable content to my viewers. Feel free to subscribe and I promise you'll learn something new with every video!
4 سال پیش در تاریخ 1399/06/04 منتشر شده است.
35,113 بـار بازدید شده
... بیشتر