TPTung Phaminsignal11.hashnode.dev·Dec 12, 2023 · 1 min readWho calls my func?Source: https://stackoverflow.com/questions/2654113/how-to-get-the-callers-method-name-in-the-called-method import inspect def f1(): f2() def f2(): curframe = inspect.currentframe() calframe = inspect.getouterframes(curframe, 2) print('...00
TPTung Phaminsignal11.hashnode.dev·Aug 2, 2023 · 1 min read2D slice in Gopackage main import "fmt" func main() { height := 6 width := 5 foo := make([][]int, height) fmt.Println("foo slice: ", foo) for row := range foo { if len(foo[row]) < 1 { foo[row] = make([]int, width) ...00
TPTung Phaminsignal11.hashnode.dev·Jun 27, 2023 · 1 min readPython `getter` & `setter` examplesSource: https://realpython.com/python-getter-setter/ A simple example # employee.py from datetime import date class Employee: def __init__(self, name, birth_date, start_date): self.name = name self.birth_date = birth_date ...00
TPTung Phaminsignal11.hashnode.dev·May 18, 2022 · 1 min readConvert Python `OrderedDict` to standard `dict`Easy peasy import json to_dict = json.dumps(json.load(ordered_dict))00
TPTung Phaminsignal11.hashnode.dev·May 6, 2022 · 1 min readDiff 2 dictsA case of extracting the diff of 2 dicts in Python # DICT DIFF EXAMPLE data = { "fee": 1, "fi": 2, "fo": 3, "fum": 4, } new_data = { "fee": 1, "fi": "2", "fo": { "foo": "bar" }, "fum": 4, } diff = {k: v...00