-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintOut.py
More file actions
33 lines (24 loc) · 873 Bytes
/
intOut.py
File metadata and controls
33 lines (24 loc) · 873 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
myfile = open('myfile.txt')
print(myfile.read())
myfile.seek(0) #To read the file again you need to bring cursor back to the beggining of the file
print(myfile.read())
contents = myfile.read()
myfile.seek(0)
contents = myfile.readline() # use readline to grab a list
print(contents)
myfile.close() #Remember to close file
with open('myfile.txt', 'w') as f:
f.write(contents)
# mode='r' Read only
# mode='w' Write only (can create new file)
# mode='a' Appending only (will add on to files
# mode='r+' reading and writing
# mode='w+' writing and reading (Overwrites existing files or creates a new file!)
with open('myTestFile.txt', 'w+') as f:
f.write('This is a first line \n And a second line')
print(f)
f.close()
#Windows
# NewPathFile = open("C:\\Users\\UserName\\Folder\\test.txt")
#LINUX
# NewPathFile = ("/Users/YouUserName/Folder/myfile.txt