Python Tutorial for Beginners 41 – Create a Text File and Write in It Using Python

///Python Tutorial for Beginners 41 – Create a Text File and Write in It Using Python

Python Tutorial for Beginners 41 – Create a Text File and Write in It Using Python

FavoriteLoadingAdd to favorites

In this Python Tutorial for Beginners video I am going to show you How to Create a Text File and Write in It Using Python . To open a file in Python we use open() function.open() returns a file object, and is most commonly used with two arguments: open(filename, mode).Before we can write to the file we must tell Python which file we are going to work with and what we will be doing with the file. This is done with the open() function. open() returns a “file handle” – a variable used to perform operations on the file
Kind of like “File – Open” in a Word Processor.
name = open(“filename”)- opens the given file for reading, and returns a file object
name.read() – file’s entire contents as a string
name.readline() – next line from file as a string
name.readlines() – file’s contents as a list of lines
The “r” is called the “access mode”. r is for reading, if the file does not exist, an error is raised
w is for writing- If the file exists, the contents are overwritten. If the file does not exist, it will be created
a is for appending- If the file exists new data is appended to the end of the file. If the file does not exist, it will be created

#PythonTutorialforBeginners #ProgrammingKnowledge #LearnPython #PythonCourse
——————-Online Courses to learn—————————-
Blockchain Course –
Big Data Hadoop Course –
Java –
C++ –
AngularJS –
Python –
C-
Android –
Linux –
AWS Certified Solutions Architect –
Modern React with Redux –
MySQL –
———————-Follow———————————————
My Website –
My Blog –
My Facebook Page –
Google+ –
Twitter –
Pinterest –
Text Case Converter –
————————-Stuff I use to make videos ——————-
Stuff I use to make videos
Windows notebook –
Apple MacBook Pro –
Ubuntu notebook –
Desktop –
Microphone –
notebook mouse –
——————Facebook Links —————————————-

source

By |2019-05-05T18:45:14+00:00May 5th, 2019|Python Video Tutorials|6 Comments

6 Comments

  1. ProgrammingKnowledge May 5, 2019 at 6:45 pm - Reply
  2. B N May 5, 2019 at 6:45 pm - Reply

    Sorry but this did not print oit for me. I am using Spyder editor and console instead I get runfile('C:/Users/John/Documents/WinPython-64bit-3.5.3.0Qt5/hello5.py', wdir='C:/Users/Ben/Documents/WinPython-64bit-3.5.3.0Qt5'). Whhat am I doing wrong? Thank you

  3. SHAKIF RAUF May 5, 2019 at 6:45 pm - Reply

    how do i create a word file or a excel file in a folder of my liking?

  4. Subhajit Roy May 5, 2019 at 6:45 pm - Reply

    Can u cover SQL in a single video and php in another single video……

  5. ujwal krishna May 5, 2019 at 6:45 pm - Reply

    Sir can you do a tutorial on php sql?

  6. ᴛᴏᴜᴄʜ ᴛʏᴘᴇʀ May 5, 2019 at 6:45 pm - Reply

    Due to irritating people like u i am discouraged.you know everything you want to and no matter how hard i try i dont learn anything. You are irritating motherfucker. You will do undergraduation in electronics and master in computer science. This is what most irritaing to me. Always studying.

Leave A Comment

*