I am having this code where I am reading all the JSON files stored:
json_files = glob.glob('testproject/JSON/*.json', recursive=True)
print(json_files)
Now I am creating a UML diagram for which I am creating a new file and giving the same name as the JSON file which is loaded without the .json extension.
I have this code doing that for me:
for single_file in json_files:
with open(single_file, 'r') as f:
json_data = json.load(f)
name = single_file.split('.')
# From JSON, create GANTT Diagram
with open(name[0].split('/')[-1] + ".uml", "w") as f:
#some logic inside this part
When I run the code it gives me this error:
['testproject/JSON\\abc.json', 'testproject/JSON\\xyz.json']
Traceback (most recent call last):
File "c:\Project\testproject\extract.py", line 28, in <module>
with open(name[0].split('/')[-1] + ".uml", "w") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'JSON\\abc.uml'
as it can been seen that when i print the json_files variable the path is something like this testproject/JSON\abc.json and because of that the split is not working properly maybe. Can someone guide me here? Thanks in advance.