Say I have an file describing a graph in a format like this:
Directional:True
Simplicity:True
{
1:[2,3]
2:[1,3]
}
and I have a graph class defined like below:
class Graph:
def __init__(self,directional = False,simple=True,Filename=None):
self.adjacencyList = {}
self.directional = directional
self.simple = simple
if not Filename:
_readFile(Filename)
Is there anyway to convert this file to this class easily . I know I can write a function to read from the file line by line and do the thing myself. But since python is a highly developed language is there any easy way to do it?
Thanks in advance.
No, since the file doesn't adhere to any standard/popular format. It's close to YAML, but not close enough for direct parsing.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.