-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParser.py
More file actions
65 lines (56 loc) · 1.99 KB
/
Parser.py
File metadata and controls
65 lines (56 loc) · 1.99 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import array
print(
"Программа сканирует файл file.csv в папке запуска скрипта, сканирует каждую строку и выводит отсутствующие значения согласно введенных крайних номеров")
def start_end():
first = input("Отсчет ОТ #: ")
last = input("Отсчет ДО #: ")
i = int(first)
j = int(last)
# i = 0
num = array.array('i', [])
while i < j:
num.append(i)
i += 1
# print(num)
return num
def parseFile():
with open("file.csv") as fp: #you can replace file.csv
File = fp.readlines()
count = 0
# print(start_end())
arrayList = start_end()
# print(arrayList)
for everyLine in File: # parse csv file STR into INT and remove from array
try:
count += 1
nextI = int(everyLine.format(count, everyLine.strip()))
# print(nextI)
try:
arrayList.remove(nextI)
# print(arrayList)
except ValueError:
continue
except ValueError:
continue
# print(arrayList)
return arrayList
def finish(a):
x = 0
# print(a)
length = a.__len__()
try:
with open("output.csv", "w") as delete:
delete.writelines("")
except PermissionError:
print("\n---- Нет доступа к записи файла. Возможно файл открыт ----\n")
# print("\nГотово. Загляните в output.csv")
else:
while x < length:
with open("output.csv", "a") as fileAppendData:
fileAppendData.writelines("{}\n".format(arr[x]))
# print("PPC :", arr[x])
x += 1
fileAppendData.close()
print("\nГотово. Загляните в output.csv")
arr = parseFile()
finish(arr)