-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile-input-output.py
More file actions
executable file
·41 lines (32 loc) · 909 Bytes
/
file-input-output.py
File metadata and controls
executable file
·41 lines (32 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python
############################################
# #
# Program: simple-math.py #
# Author: Asanka Sayakkara #
# Description: #
# This script demonstrates the basic #
# methematical functionalities with #
# Python. #
# #
############################################
print("==File Input and Output==")
# Writing to a file to write
myFile = open("temp.txt", "w")
myFile.write("Here's the first line\n")
myFile.write("Here's the second line\n")
myFile.write("Here's the third line\n")
myFile.close()
# Reading from a file
myFile = open("temp.txt", "r")
text = myFile.read()
print("File content: %s" % text)
myFile.close()
myFile = open("temp.txt", "r")
textLines = myFile.readlines()
print("The Lines: %s" % text)
myFile.close()
myFile = open("temp.txt", "r")
textLines = myFile.readlines()
for line in textLines:
print("Line: %s" % line)
myFile.close()