Pythonファイルと「g1.txt」を同じディレクトリに置きました。SublimeREPL を使用しない場合、コードは正しく実行されます
def build_graph(file_name):
new_file = open(file_name, 'r')
n, m = [int(x) for x in new_file.readline().split()]
graph = {}
for line in new_file:
# u, v, w is the tail, head and the weight of the a edge
u, v, w = [int(x) for x in line.split()]
graph[(u, v)] = w
return n, graph
if __name__ == '__main__':
print build_graph('g1.txt')
>>> >>> Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 18, in <module>
File "<string>", line 6, in build_graph
IOError: [Errno 2] No such file or directory: 'g1.txt'