This file contains 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
# When you want to add a new parameter, you only need to add in 2 places: | |
# In params.py: | |
class Params: | |
... | |
my_new_param: float = 42 | |
# At the "end-point" where this parameter is used: | |
class VeryDeepModule: |
This file contains 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
from my_project_params import Params | |
class SomeMidProcessModule: | |
def __init__(self, params: Params): | |
self.params: Params = params # Now, if params is None, we will get an error! | |
def run(self): | |
do_somaething(self.params.some_configurable_value) |
This file contains 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
from my_project_params import Params | |
class SomeMidProcessModule: | |
def __init__(self, params: Params = None): | |
self.params: Params = params or Params() # NO! BAD! if we don't input an instace of Params, | |
# we will create a new instance with only default values. | |
def run(self): | |
do_somaething(self.params.some_configurable_value) |
This file contains 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
#!/usr/bin/env python3 | |
from optparse import OptionParser | |
from my_project import MyProject | |
from my_project_params import Params | |
if __name__ == "__main__": | |
parser = OptionParser() |
This file contains 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
from my_project_params import Params | |
class MyProject: | |
def __init__(self, params: Params): | |
self.params: Params = params | |
def run(self): | |
... |
This file contains 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 json | |
import os | |
from datetime import datetime | |
from optparse import OptionParser | |
from dataclasses import dataclass | |
@dataclass | |
class Params: |
This file contains 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
from IPython.core.display import display, HTML | |
display(HTML("<style>.container { width:95% !important; }</style>")) | |
display(HTML("<style>.output_result { max-width:90% !important; }</style>")) | |
import numpy as np | |
np.set_printoptions(precision=3) | |
np.set_printoptions(linewidth=170) | |
np.set_printoptions(suppress=True) | |
np.random.seed(42) |
This file contains 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
#include <iostream> | |
using namespace std; | |
int main() { | |
int arr[5]; | |
arr[0] = 1; | |
cout << "arr[0]=" << arr[0] << endl; | |
*arr = 2; | |
cout << "arr[0]=" << arr[0] << endl; |
This file contains 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
#include <iostream> | |
using namespace std; | |
void change_val(int &z); | |
int main() { | |
int a = 1; | |
int *b = &a; | |
int &c = *b; | |
cout << "c is an alias of whatever b points to\n"; |
This file contains 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
#include <iostream> | |
using namespace std; | |
void change_val(int &z); | |
int main() { | |
int a = 1; | |
int *b = &a; | |
int c = *b; | |
cout << "c is an integer that takes the value that b points to\n"; |
NewerOlder