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 [2024/09/24 05:32] jotasandokuscripting:python [2024/12/23 13:46] (current) – S jotasandoku
Line 14: Line 14:
   netsim.cli.lab_commands(__file__)   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]]
  
 ---- ----
Line 325: 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
scripting/python.1727155945.txt.gz · Last modified: by jotasandoku