This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import sys | |
class IPythonPromptPS1(object): | |
def __init__(self): | |
self.line = 0 | |
def __str__(self): | |
self.line += 1 | |
return "\033[92mIn [%d]:\033[0m " % (self.line) | |
sys.ps1 = IPythonPromptPS1() | |
sys.ps2 = " \033[91m...\033[0m " |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
sys.ps1 = "\033[1;33m>>>\033[0m " | |
sys.ps2 = "\033[1;34m...\033[0m " |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> import sys | |
>>> sys.ps1 = '::: ' | |
::: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> def foo(a, b): | |
... return a + b | |
... | |
>>> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Python 2.7.10 (default, Feb 22 2019, 21:55:15) | |
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@overload | |
def area(l, b): | |
return l * b | |
@overload | |
def area(r): | |
import math | |
return math.pi * r ** 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def __call__(self, *args, **kwargs): | |
"""Overriding the __call__ function which makes the | |
instance callable. | |
""" | |
# fetching the function to be invoked from the virtual namespace | |
# through the arguments. | |
fn = Namespace.get_instance().get(self.fn, *args) | |
if not fn: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get(self, fn, *args): | |
"""get returns the matching function from the virtual namespace. | |
return None if it did not fund any matching function. | |
""" | |
func = Function(fn) | |
return self.function_map.get(func.key(args=args)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def overload(fn): | |
"""overload is the decorator that wraps the function | |
and returns a callable object of type Function. | |
""" | |
return Namespace.get_instance().register(fn) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
def my_decorator(fn): | |
"""my_decorator is a custom decorator that wraps any function | |
and prints on stdout the time for execution. | |
""" | |
def wrapper_function(*args, **kwargs): | |
start_time = time.time() |