'ReadFile Error: invalid literal for int() with base 10: '\n'
I'm trying to create a MST with Prim's algorithm, but when I try to read the .txt file which holds the nodes and their weights this error pops: ValueError: invalid literal for int() with base 10: '\n' my .txt file has a format like this:
- 6
- 0 0 1
- 0 1 6
- 0 1 9
- 0 2 3 (the number.dot is for formatting reasons, original text file is without them)
and the first part of the code that reads the .txt file is this :
import heapq
mst=[]
usedVertices=set()
with open("C:/Users/DESPACITOOOOOOOOO/AppData/Local/Programs/Python/Python39/text.txt") as f:
numVertices=int(f.readline())
edges=[[]for _ in range(numVertices)]
for line in f.readlines():
edge=tuple(map(int,line.split(" ")))
if edge[0]==edge[1]:continue
heapq.heappush(edges[edge[0]],(edge[2],edge[1]))
heapq.heappush(edges[edge[1]],(edge[2],edge[0]))
Any Ideas? Thank you in advance
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
