我已将 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'