A special variant of the Code Completion feature invoked by pressing ⌃Space twice allows you to complete the name of any class no matter if it was imported in the current file or not. If the class is not imported yet, the import statement is generated automatically.
Python
Python: Binary Search Tree
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import random class TreeNode: def __init__(self, key): self.key = key self.left = None self.right = None self.p = None class BinaryTree: def __init__(self): self.root = None def length(self): return self.size def inorder(self, node): if node == None: return None else: self.inorder(node.left) print node.key, self.inorder(node.right) |
Python: Static, Class, and Abstract Methods
Julien Danjou has a great guide on how to use static, class, or abstract methods in python.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# class method class TrackedObject: __id__ = 0 def __init__(self, x, id = None): self.x = x if id != None: self.id = id else: self.id = self.__class__.__id__ self.__class__.__id__ += 1 @classmethod def reset(cls): cls.__id__ = 0 # |