Skip to main content
deleted 357 characters in body
Source Link

I was experimenting with graphs in python and i felt into a problem.

Here is the code :

class IspNetwork :
    def __init__(self) -> None:
        self.root : Node = Node("isp")

    def add_node(self, obj) :
        node = ObjectEncoder().encode(obj)
        self.root.left = Node(node)
        pass

The output is as expected, one root node and a node on the left branch.

Now my question is, how to dynamically set multiple nodes on the left branch, it should be something like : self.left.left...left.left = Node(node)

But I cant figure out how to do it the right way.

I tried to use __setattr__(), some gibberish like self.left. + 3*"left" = Node(node).

But none of those worked so any help would be highly appreciated !

EDIT : To add a branch to a specific node we can set the index of the node we want to expand.

class IspNetwork :
    def __init__(self) -> None:
        self.root : Node = Node("isp")

    def add_node(self, index, obj) :
        self.root[index].__setattr__("left", Node(obj))

Thank's to @trincot for helping me solve the issue !

I was experimenting with graphs in python and i felt into a problem.

Here is the code :

class IspNetwork :
    def __init__(self) -> None:
        self.root : Node = Node("isp")

    def add_node(self, obj) :
        node = ObjectEncoder().encode(obj)
        self.root.left = Node(node)
        pass

The output is as expected, one root node and a node on the left branch.

Now my question is, how to dynamically set multiple nodes on the left branch, it should be something like : self.left.left...left.left = Node(node)

But I cant figure out how to do it the right way.

I tried to use __setattr__(), some gibberish like self.left. + 3*"left" = Node(node).

But none of those worked so any help would be highly appreciated !

EDIT : To add a branch to a specific node we can set the index of the node we want to expand.

class IspNetwork :
    def __init__(self) -> None:
        self.root : Node = Node("isp")

    def add_node(self, index, obj) :
        self.root[index].__setattr__("left", Node(obj))

Thank's to @trincot for helping me solve the issue !

I was experimenting with graphs in python and i felt into a problem.

Here is the code :

class IspNetwork :
    def __init__(self) -> None:
        self.root : Node = Node("isp")

    def add_node(self, obj) :
        node = ObjectEncoder().encode(obj)
        self.root.left = Node(node)
        pass

The output is as expected, one root node and a node on the left branch.

Now my question is, how to dynamically set multiple nodes on the left branch, it should be something like : self.left.left...left.left = Node(node)

But I cant figure out how to do it the right way.

I tried to use __setattr__(), some gibberish like self.left. + 3*"left" = Node(node).

But none of those worked so any help would be highly appreciated !

deleted 678 characters in body
Source Link

I was experimenting with graphs in python and i felt into a problem.

Here is the code :

class IspNetwork :
    def __init__(self) -> None:
        self.root : Node = Node("isp")

    def add_node(self, obj) :
        node = ObjectEncoder().encode(obj)
        self.root.left = Node(node)
        pass

The output is as expected, one root node and a node on the left branch.

Now my question is, how to dynamically set multiple nodes on the left branch, it should be something like : self.left.left...left.left = Node(node)

But I cant figure out how to do it the right way.

I tried to use __setattr__(), some gibberish like self.left. + 3*"left" = Node(node).

But none of those worked so any help would be highly appreciated !

EDIT : Issue barrely fixed using the method build() provided by BinaryTree. Now iTo add a branch to a specific node we can transform my arrayset the index of objects in a graph. Here is the code I used :node we want to expand.

class IspNetwork :
    def __init__(self, range=None) -> None:
        self.values = [
            ObjectEncoder().encode(Isp(name="IT Complex", location="USA", network="xxxx")), 
            ObjectEncoder().encode(Isp(name="Telecom", location="USA",  network="xxxx")), 
            ObjectEncoder().encode(Isp(name="Primo Communications", location="USA", network="xxxx"))
        ]
        self.root = build(self.values)
     : Node = self.print_graphNode("isp") 

    def print_graph(self):
        print(self.root)

But I dont figure out how to explicitly say that I want all the objects on the left branch.

EDIT 2 : To add a branch to a specific node we can set the index of the node we want to expand.

def add_node(self, index, obj) :
        self.root[index].__setattr__("left", Node(obj))

Thank's to @trincot for helping me solve the issue !

I was experimenting with graphs in python and i felt into a problem.

Here is the code :

class IspNetwork :
    def __init__(self) -> None:
        self.root : Node = Node("isp")

    def add_node(self, obj) :
        node = ObjectEncoder().encode(obj)
        self.root.left = Node(node)
        pass

The output is as expected, one root node and a node on the left branch.

Now my question is, how to dynamically set multiple nodes on the left branch, it should be something like : self.left.left...left.left = Node(node)

But I cant figure out how to do it the right way.

I tried to use __setattr__(), some gibberish like self.left. + 3*"left" = Node(node).

But none of those worked so any help would be highly appreciated !

EDIT : Issue barrely fixed using the method build() provided by BinaryTree. Now i can transform my array of objects in a graph. Here is the code I used :

class IspNetwork :
    def __init__(self, range=None) -> None:
        self.values = [
            ObjectEncoder().encode(Isp(name="IT Complex", location="USA", network="xxxx")), 
            ObjectEncoder().encode(Isp(name="Telecom", location="USA",  network="xxxx")), 
            ObjectEncoder().encode(Isp(name="Primo Communications", location="USA", network="xxxx"))
        ]
        self.root = build(self.values)
        self.print_graph() 

    def print_graph(self):
        print(self.root)

But I dont figure out how to explicitly say that I want all the objects on the left branch.

EDIT 2 : To add a branch to a specific node we can set the index of the node we want to expand.

def add_node(self, index, obj) :
    self.root[index].__setattr__("left", Node(obj))

Thank's to @trincot for helping me solve the issue !

I was experimenting with graphs in python and i felt into a problem.

Here is the code :

class IspNetwork :
    def __init__(self) -> None:
        self.root : Node = Node("isp")

    def add_node(self, obj) :
        node = ObjectEncoder().encode(obj)
        self.root.left = Node(node)
        pass

The output is as expected, one root node and a node on the left branch.

Now my question is, how to dynamically set multiple nodes on the left branch, it should be something like : self.left.left...left.left = Node(node)

But I cant figure out how to do it the right way.

I tried to use __setattr__(), some gibberish like self.left. + 3*"left" = Node(node).

But none of those worked so any help would be highly appreciated !

EDIT : To add a branch to a specific node we can set the index of the node we want to expand.

class IspNetwork :
    def __init__(self) -> None:
        self.root : Node = Node("isp")

    def add_node(self, index, obj) :
        self.root[index].__setattr__("left", Node(obj))

Thank's to @trincot for helping me solve the issue !

added 2 characters in body
Source Link

I was experimenting with graphs in python and i felt into a problem.

Here is the code :

class IspNetwork :
    def __init__(self) -> None:
        self.root : Node = Node("isp")

    def add_node(self, obj) :
        node = ObjectEncoder().encode(obj)
        self.root.left = Node(node)
        pass

The output is as expected, one root node and a node on the left branch.

Now my question is, how to dynamically set multiple nodes on the left branch, it should be something like : self.left.left...left.left = Node(node)

But I cant figure out how to do it the right way.

I tried to use __setattr__(), some gibberish like self.left. + 3*"left" = Node(node).

But none of those worked so any help would be highly appreciated !

EDIT : Issue barrely fixed using the method build() provided by BinaryTree. Now i can transform my array of objects in a graph. Here is the code I used :

class IspNetwork :
    def __init__(self, range=None) -> None:
        self.values = [
            ObjectEncoder().encode(Isp(name="IT Complex", location="USA", network="xxxx")), 
            ObjectEncoder().encode(Isp(name="Telecom", location="USA",  network="xxxx")), 
            ObjectEncoder().encode(Isp(name="Primo Communications", location="USA", network="xxxx"))
        ]
        self.root = build(self.values)
        self.print_graph() 

    def print_graph(self):
        print(self.root)

But I dont figure out how to explicitly say that I want all the objects on the left branch. EDIT

EDIT 2 : To add a branch to a specific node we can set the index of the node we want to expand.

def add_node(self, index, obj) :
    self.root[index].__setattr__("left", Node(obj))

Thank's to @trincot for helping me solve the issue !

I was experimenting with graphs in python and i felt into a problem.

Here is the code :

class IspNetwork :
    def __init__(self) -> None:
        self.root : Node = Node("isp")

    def add_node(self, obj) :
        node = ObjectEncoder().encode(obj)
        self.root.left = Node(node)
        pass

The output is as expected, one root node and a node on the left branch.

Now my question is, how to dynamically set multiple nodes on the left branch, it should be something like : self.left.left...left.left = Node(node)

But I cant figure out how to do it the right way.

I tried to use __setattr__(), some gibberish like self.left. + 3*"left" = Node(node).

But none of those worked so any help would be highly appreciated !

EDIT : Issue barrely fixed using the method build() provided by BinaryTree. Now i can transform my array of objects in a graph. Here is the code I used :

class IspNetwork :
    def __init__(self, range=None) -> None:
        self.values = [
            ObjectEncoder().encode(Isp(name="IT Complex", location="USA", network="xxxx")), 
            ObjectEncoder().encode(Isp(name="Telecom", location="USA",  network="xxxx")), 
            ObjectEncoder().encode(Isp(name="Primo Communications", location="USA", network="xxxx"))
        ]
        self.root = build(self.values)
        self.print_graph() 

    def print_graph(self):
        print(self.root)

But I dont figure out how to explicitly say that I want all the objects on the left branch. EDIT 2 : To add a branch to a specific node we can set the index of the node we want to expand.

def add_node(self, index, obj) :
    self.root[index].__setattr__("left", Node(obj))

Thank's to @trincot for helping me solve the issue !

I was experimenting with graphs in python and i felt into a problem.

Here is the code :

class IspNetwork :
    def __init__(self) -> None:
        self.root : Node = Node("isp")

    def add_node(self, obj) :
        node = ObjectEncoder().encode(obj)
        self.root.left = Node(node)
        pass

The output is as expected, one root node and a node on the left branch.

Now my question is, how to dynamically set multiple nodes on the left branch, it should be something like : self.left.left...left.left = Node(node)

But I cant figure out how to do it the right way.

I tried to use __setattr__(), some gibberish like self.left. + 3*"left" = Node(node).

But none of those worked so any help would be highly appreciated !

EDIT : Issue barrely fixed using the method build() provided by BinaryTree. Now i can transform my array of objects in a graph. Here is the code I used :

class IspNetwork :
    def __init__(self, range=None) -> None:
        self.values = [
            ObjectEncoder().encode(Isp(name="IT Complex", location="USA", network="xxxx")), 
            ObjectEncoder().encode(Isp(name="Telecom", location="USA",  network="xxxx")), 
            ObjectEncoder().encode(Isp(name="Primo Communications", location="USA", network="xxxx"))
        ]
        self.root = build(self.values)
        self.print_graph() 

    def print_graph(self):
        print(self.root)

But I dont figure out how to explicitly say that I want all the objects on the left branch.

EDIT 2 : To add a branch to a specific node we can set the index of the node we want to expand.

def add_node(self, index, obj) :
    self.root[index].__setattr__("left", Node(obj))

Thank's to @trincot for helping me solve the issue !

added 256 characters in body
Source Link
Loading
added 101 characters in body
Source Link
Loading
added 2 characters in body
Source Link
Loading
added 678 characters in body
Source Link
Loading
Source Link
Loading