IOError: [Errno 2] Нет такого файла или каталога: 'A.json' - PullRequest
0 голосов
/ 25 августа 2018

Не могли бы вы дать мне знать, как исправить эту ошибку, я пытаюсь запустить код Python, но когда я запускаю код, он выдает ошибку about.У меня нет большого опыта программирования, и мне действительно нужно это исправить.пожалуйста, помогите и посоветуйте мне, как это исправить.

import networkx as nx

def path_valid(g, p):
""" Checks whether the list nodes p is a valid path in g."""
plen = len(p)
for i in range(plen-1):
 if not g.has_edge(p[i],p[i+1]):
     return False
return True

if __name__ == '__main__':
g = nx.Graph()  # Create an empty undirected graph
g.add_node(1); g.add_node(2); g.add_node(3)
g.add_edge(1,2); g.add_edge(1,3); g.add_edge(2,3)
print "Graph nodes are: {}".format(g.nodes())
print "Graph edges are: {}".format(g.edges())
print "Is edge (2,1) in the graph? {}".format(g.has_edge(2,1))
print "Is edge (3,2) in the graph? {}".format(g.has_edge(3,2))
print "Is path [1,3,2] valid? {}".format(path_valid(g, [1,3,2]))
print "Is path [1,4,2] valid? {}".format(path_valid(g, [1,4,2]))

from networkx.readwrite import json_graph
import json
g = nx.Graph()
# Don't need to add nodes separately.
g.add_edge(1,2, capacity=10)  # add a "capacity" parameter
g.add_edge(1,3, capacity=10)  # can have any name you like
g.add_edge(2,3, capacity=15)
print "Graph nodes are: {}".format(g.nodes())
print "Graph edges are: {}".format(g.edges(data=True))
print "Is edge (2,1) in the graph? {}".format(g.has_edge(2,1))
print "Is edge (3,2) in the graph? {}".format(g.has_edge(3,2))
print "The capacity of edge (2,3) is {}".format(g[2][3]["capacity"])
# print graph as a JSON string
# print graph as a JSON string
print json.dumps(json_graph.node_link_data(g),indent=4)
from networkx.readwrite import json_graph
import networkx as nx
import json
# Read in a JSON formatted graph file
g = json_graph.node_link_graph(json.load(open("A.json")))
print "graph nodes: {}".format(g.nodes())  # Lists nodes
print "graph links: {}".format(g.edges(data=True))  #  Shows link info
for n in g.nodes():  # See that hosts are assigned addresses
if g.node[n]["type"] == 'host':
    print "Host {}, IP = {}, MAC = {}".format(n, g.node[n]['ip'], g.node[n]['mac'])

Я получил эту ошибку:

File "/home/ubuntu/Desktop/my_python.py", line 42, in <module>
g = json_graph.node_link_graph(json.load(open("A.json")))
IOError: [Errno 2] No such file or directory: 'A.json'

пожалуйста, если вам нужен весь код, дайте мне знать, чтобы я мог отправить еговы.Спасибо за вашу помощь и поддержку.

...