-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathManage_TXT.py
More file actions
34 lines (25 loc) · 841 Bytes
/
Copy pathManage_TXT.py
File metadata and controls
34 lines (25 loc) · 841 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
# Manage TXT using different approach
text = 'Sample text to save\nNew line!'
saveFile = open('exampleFile.txt','w')
saveFile.write(text)
saveFile.close()
# Appending Files
appendMe = '\nNew bit of information'
appendFile = open('exampleFile.txt','a')
appendFile.write(appendMe)
appendFile.close()
# Load TXT using numpy==============================================================
import numpy as np #looks like this only works for numbers but not string!
a = np.loadtxt("grade.txt")
print(a)
print(a[2, 1])
# Load TXT using csv==============================================================
import csv
with open('example.bin.txt', 'r') as myfile:
rows = csv.reader(myfile, delimiter='\t')
data = [row for row in rows]
data_dict = dict()
for i in data:
data_dict[i[0]]=i[1]
print(data_dict)
print(data)