IOError: [Errno 2] No such file or directory: 'A.json'

IOError: [Errno 2] No such file or directory: 'A.json'



could you please let me know how to fix this error, I'm try to run a python code, but when I run the code it gave the about error. I don't have a lot coding experiences and I really need to fix this.
please help and advise me on how to fix it.


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'])



I got this error:


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'



please if you need the whole code let me know so I can send it to you.
Thank you for your help and supports.





First, do you actually have a file named A.json? (Remember that filenames are case-sensitive on Linux.) If so, is it in the same directory as your current working directory when you run your Python script?
– abarnert
Aug 24 at 23:29


A.json





It's just missing the file "A.json" -- do you have that file? It's trying to open and load it on line 42, but is failing because it can't find it.
– payne
Aug 24 at 23:29





I don't have ut, could you please check the code now, I just add the whole code. Thank you.
– murat bingol
Aug 25 at 1:23









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)