-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClass_ListToText.py
More file actions
32 lines (30 loc) · 989 Bytes
/
Class_ListToText.py
File metadata and controls
32 lines (30 loc) · 989 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
#coding=utf-8 测试通过:将数组保存为txt,从txt读出数组 2017-12-26
import os
class ListTextHelp:
ipTable = []
Return_List = []
#txtFileName = "IpTable.txt"
txtFileName = os.path.abspath('../ip.txt')
if not os.path.exists(txtFileName):
print '[ '+ str(txtFileName) + ' ] does not exist !'
exit()
def ToText(self):
if self.ipTable :
fileObject = open(self.txtFileName, 'w')
for ip in self.ipTable:
fileObject.write(ip)
fileObject.write('\n')
fileObject.close()
else:
print ("No List!")
def ReadText(self):
file = open(self.txtFileName)
for line in file:
self.Return_List.append(line.replace("\n",""))
if __name__ == '__main__':
ipTable = ['11', '222', '33']
td = ListTextHelp()
# td.ipTable = ipTable
td.ReadText()
arr = td.Return_List
print (arr)