This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| scripting:python [2023/08/10 07:28] – jotasandoku | scripting:python [2024/12/23 13:46] (current) – S jotasandoku | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| **__PYTHON__**\\ | **__PYTHON__**\\ | ||
| - | \\ | + | |
| + | |||
| + | == FOLLOW PYTHON CODE (WIP) === | ||
| + | |||
| + | This is just covering the simple case of an installed python program which is invoked via interactive cli.\\ | ||
| + | I take [[https:// | ||
| + | |||
| + | The executable archive for the main command (argv[0]) must be present in a location contained in ' | ||
| + | |||
| + | # | ||
| + | import netsim | ||
| + | import netsim.cli | ||
| + | netsim.cli.lab_commands(__file__) | ||
| + | |||
| + | '' | ||
| + | |||
| + | * Inside netsim/ | ||
| + | * we have the function '' | ||
| + | * the standard module '' | ||
| + | |||
| + | ---- | ||
| **Python virtual environment**: | **Python virtual environment**: | ||
| \\ | \\ | ||
| Line 138: | Line 159: | ||
| ---- | ---- | ||
| - | __**REGEX**__ | + | __**REGEX |
| - | \\ | + | |
| * [[https:// | * [[https:// | ||
| * [[https:// | * [[https:// | ||
| - | * ALL INFO [[https:// | + | * regex search ways in python: MATCH, SEARCH, FINDALL, and SUB |
| - | * All regex can be done with or without [[https:// | + | |
| - | Resources | + | |
| - | https:// | + | |
| - | \\ | + | |
| - | regex search ways in python: MATCH, SEARCH, FINDALL, and SUB \\ | + | |
| - | \\ | + | |
| - | **FINDALL: | + | |
| - | re.findall( | + | **__SEARCH__** |
| - | [' | + | |
| - | + | ||
| - | Example: find any serial number 8 characters long after the pattern: " | + | |
| - | file = fileh.read() | + | |
| - | serials = re.findall(r' | + | |
| \\ | \\ | ||
| - | **SUB:** Can replace a parameter.\\ | + | A found 'yes or no'. Returns a Match object |
| - | First you need to find the parts of the string that need to be rewritten (you do this with re.sub). Then you rewrite that parts.\\ | + | |
| - | re.sub( | + | |
| - | 'did you find one turnip or many turnips' | + | |
| - | + | ||
| - | **SEARCH: | + | |
| - | \\ | + | |
| - | Tells us if the match is or isn' | + | |
| txt = "The rain in Spain" | txt = "The rain in Spain" | ||
| Line 177: | Line 178: | ||
| vrf_dict = {name_match.group(" | vrf_dict = {name_match.group(" | ||
| | | ||
| + | |||
| \\ | \\ | ||
| + | |||
| + | **FINDALL: | ||
| + | |||
| + | res_list1 = re.findall(' | ||
| + | [' | ||
| + | |||
| + | \\ | ||
| + | **SUB:** Can replace a parameter.\\ | ||
| + | First you need to find the parts of the string that need to be rewritten (you do this with re.sub). Then you rewrite that parts.\\ | ||
| + | re.sub( ' | ||
| + | 'did you find one turnip or many turnips' | ||
| + | |||
| + | |||
| **MATCH**: | **MATCH**: | ||
| - Compile the expressions | - Compile the expressions | ||
| Line 315: | Line 330: | ||
| """ | """ | ||
| \\ | \\ | ||
| - | Slicing lists\\ | + | == SLICING === |
| - | print namelist[:2] | + | |
| + | # [:2] - First 2 elements | ||
| + | print("[:2] ->", | ||
| + | |||
| + | # [2:] - Everything from index 2 onwards | ||
| + | print(" | ||
| + | |||
| + | # [-2:] - Last 2 elements | ||
| + | print(" | ||
| + | |||
| + | # [:-2] - Everything EXCEPT last 2 elements | ||
| + | print(" | ||
| + | |||
| + | |||
| + | |||
| \\ | \\ | ||
| Updating list | Updating list | ||
| Line 806: | Line 836: | ||
| ---- | ---- | ||
| - | NGROK:\\ | + | NGROK: |
| + | \\ | ||
| * | * | ||
| Line 822: | Line 853: | ||
| __CODING NOTES__ | __CODING NOTES__ | ||
| * [[https:// | * [[https:// | ||
| - | * Use a 'list of unchecked cells'' | + | * Use a ''list of unchecked cells'' |
| pages_qty = len(page_numbers) + 1 | pages_qty = len(page_numbers) + 1 | ||
| Line 829: | Line 860: | ||
| + | |||
| + | ---- | ||
| + | TIME COMPLEXITY: | ||
| + | \\ | ||
| + | [[https:// | ||
| + | \\ | ||
| + | * Best case O(1) ; Worst case: O(n!) | ||
| ---- | ---- | ||
| Line 838: | Line 876: | ||
| * Moving-window average algorithm | * Moving-window average algorithm | ||
| * Sorted lists of numbers | * Sorted lists of numbers | ||
| + | |||
| + | |||