This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| scripting:python [2023/08/09 17:27] – 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: |
| - | * All regex can be done with or without [[https:// | + | |
| - | Resources | + | **__SEARCH__** |
| - | https:// | + | |
| \\ | \\ | ||
| - | regex search ways in python: MATCH, SEARCH, FINDALL, and SUB \\ | + | A found 'yes or no'. Returns a Match object if there is a match anywhere |
| + | |||
| + | txt = "The rain in Spain" | ||
| + | x = re.search(" | ||
| + | |||
| + | More ellaborated: | ||
| + | |||
| + | name_regex = re.compile(r" | ||
| + | name_match = name_regex.search(vrf) | ||
| + | sub_dict = {} | ||
| + | vrf_dict = {name_match.group(" | ||
| + | |||
| \\ | \\ | ||
| - | **FINDALL: | ||
| - | | + | **FINDALL: |
| + | |||
| + | res_list1 = re.findall(' | ||
| [' | [' | ||
| - | Example: find any serial number 8 characters long after the pattern: " | ||
| - | file = fileh.read() | ||
| - | serials = re.findall(r' | ||
| \\ | \\ | ||
| **SUB:** Can replace a parameter.\\ | **SUB:** Can replace a parameter.\\ | ||
| Line 163: | Line 192: | ||
| 'did you find one turnip or many turnips' | 'did you find one turnip or many turnips' | ||
| - | **SEARCH: | + | |
| - | name_regex = re.compile(r" | + | |
| - | name_match = name_regex.search(vrf) | + | |
| - | sub_dict = {} | + | |
| - | vrf_dict = {name_match.group(" | + | |
| - | + | ||
| - | \\ | + | |
| **MATCH**: | **MATCH**: | ||
| - Compile the expressions | - Compile the expressions | ||
| Line 233: | Line 256: | ||
| | | ||
| - | To **show the current folder path** and open a file in it | + | To **show the current folder path** and open a file in it. own directory / own folder. |
| import os | import os | ||
| Line 307: | 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 643: | Line 681: | ||
| BELOW **typical work path**: | BELOW **typical work path**: | ||
| - Convert API response to json | - Convert API response to json | ||
| - | - Store json data into a file | + | - Store json data into a file (not pretty) |
| - Retrieve the file into dict format to work on it | - Retrieve the file into dict format to work on it | ||
| Line 652: | Line 690: | ||
| with open(" | with open(" | ||
| json.dump(json_data, | json.dump(json_data, | ||
| + | ! | ||
| + | with open(" | ||
| + | json.dump(fp) | ||
| POST method. More info [[https:// | POST method. More info [[https:// | ||
| Line 795: | Line 836: | ||
| ---- | ---- | ||
| - | NGROK:\\ | + | NGROK: |
| + | \\ | ||
| * | * | ||
| Line 811: | 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 818: | Line 860: | ||
| + | |||
| + | ---- | ||
| + | TIME COMPLEXITY: | ||
| + | \\ | ||
| + | [[https:// | ||
| + | \\ | ||
| + | * Best case O(1) ; Worst case: O(n!) | ||
| ---- | ---- | ||
| Line 827: | Line 876: | ||
| * Moving-window average algorithm | * Moving-window average algorithm | ||
| * Sorted lists of numbers | * Sorted lists of numbers | ||
| + | |||
| + | |||