我已經把python文件和'g1.txt'放在同一個目錄下。 代碼運行正常,當我不使用SublimeREPLpython:IOError:[Errno 2]使用sublime時沒有這樣的文件或目錄REEL
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'