0
class DSATreeNode:
def __init__(self, data):
    self.data = data
    self.left = None
    self.right = None

class DSABinarySearchTree:
def __init__(self):
    self.root = None

def insert(self, data):
    if self.root is None:
        self.root = DSATreeNode(data)
    else:
        self._insert(data, self.root)

This line of code is located in one python file

import searchtree


bst = DSABinarySearchTree()

# Test insertion
bst.insert(5)
bst.insert(3)
bst.insert(8)
bst.insert(2)
bst.insert(4)
bst.insert(7)
bst.insert(9)

This line of code is in a different python file. "searchtree" is the name of the first python file where the "class DSABinarySearchTree" is located. Note that the python program needs to run on the terminal

Jens
  • 67,715
  • 15
  • 98
  • 113
Rasal.A
  • 9
  • 4
  • 1
    If both file are in the same folder, try replacing `bst = DSABinarySearchTree()` with `bst = searchtree.DSABinarySearchTree()`. – Scarlet Feb 19 '23 at 11:46
  • Anyway, does this answer your question? [How do I call a function from another .py file?](https://stackoverflow.com/questions/20309456/how-do-i-call-a-function-from-another-py-file) – Scarlet Feb 19 '23 at 11:49

0 Answers0