Posted by: Sourav | March 26, 2017

Basic write operation on text files in python 2.7,Python teacher Sourav,Kolkata 09748184075


print(“Creating a text file with the write() method.”)
text_file = open(“write_it.txt”, “w”)
text_file.write(“Line 1\n”)
text_file.write(“This is line 2\n”)
text_file.write(“That makes this line 3\n”)

text_file.close()

print(“\nReading the newly created file.”)
text_file = open(“write_it.txt”, “r”)
print(text_file.read())
text_file.close()

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: