User Tools

Site Tools


scripting:python

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
scripting:python [2023/08/10 10:09] jotasandokuscripting: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://github.com/ipspace/netlab]] installed in a virtual environment in Ubuntu.\\ 
 + 
 +The executable archive for the main command (argv[0]) must be present in a location contained in 'PATH'. For example  ''./bin/netlab''. This is what the executable looks like: 
 + 
 +  #!/home/jaime/netsim-labs/bin/python3 
 +  import netsim 
 +  import netsim.cli 
 +  netsim.cli.lab_commands(__file__) 
 + 
 +''netsim'' and ''cli'' are a folder and subfolder under ''./lib/python3.12/site-packages/''. The folders are ''packages'' because, together with a lot of .py files, we have the file ''__init__.py''. It contains common logic 
 + 
 +  * Inside netsim/cli/__init__.py: 
 +    * we have the function ''lab_commands''. Note this function is invoked from the main executable ''netlab'' 
 +    * the standard module ''argparse'' which is a library for common management of interactive cli. See tutorials like  [[https://www.youtube.com/watch?v=aGy7U5ItLRk|this]] 
 + 
 +---- 
 **Python virtual environment**: Isolated "environments" where specific versions of Python can be installed along with independent sets of libraries and dependencies. **Python virtual environment**: Isolated "environments" where specific versions of Python can be installed along with independent sets of libraries and dependencies.
 \\ \\
Line 309: Line 330:
   """)   """)
 \\ \\
-Slicing lists\\ +== SLICING === 
-  print namelist[:2]   prints up to but not including index 2. So and 1.+ 
 +  # [:2] - First 2 elements 
 +  print("[:2] ->",  x[:2])  [0, 1] 
 + 
 +  # [2:] - Everything from index 2 onwards 
 +  print("[2:] ->", x[2:])  # [2, 3, 4, 5, 6, 7, 8, 9] 
 + 
 +  # [-2:] - Last 2 elements 
 +  print("[-2:] ->", x[-2:])  # [8, 9] 
 + 
 +  # [:-2] - Everything EXCEPT last 2 elements 
 +  print("[:-2] ->", x[:-2])  # [01, 2, 3, 4, 5, 6, 7] 
 + 
 + 
 + 
 \\ \\
 Updating list Updating list
Line 800: Line 836:
  
 ---- ----
-NGROK:\\+NGROK: 
 +\\
  
   *     Demoing web sites without deploying   *     Demoing web sites without deploying
Line 816: Line 853:
 __CODING NOTES__ __CODING NOTES__
   * [[https://app.coderpad.io/dashboard/questions/examples/]]   * [[https://app.coderpad.io/dashboard/questions/examples/]]
-  * Use a 'list of unchecked cells''... At the end, the index of the only unchecked cell will be the missing page number.+  * Use a ''list of unchecked cells''... At the end, the index of the only unchecked cell will be the missing page number.
  
     pages_qty = len(page_numbers) + 1     pages_qty = len(page_numbers) + 1
Line 823: Line 860:
  
  
 +
 +----
 +TIME COMPLEXITY:
 +\\
 +[[https://towardsdatascience.com/understanding-time-complexity-with-python-examples-2bda6e8158a7]]
 +\\
 +  * Best case O(1) ; Worst case: O(n!)
  
 ---- ----
Line 832: Line 876:
   * Moving-window average algorithm   * Moving-window average algorithm
   * Sorted lists of numbers   * Sorted lists of numbers
 +
 +
scripting/python.1691662170.txt.gz · Last modified: (external edit)