Pārlūkot izejas kodu

buildin removeprefix is only available in >= 3.9

Rodja Trappe 2 gadi atpakaļ
vecāks
revīzija
3a37903940
1 mainītis faili ar 5 papildinājumiem un 1 dzēšanām
  1. 5 1
      website/example.py

+ 5 - 1
website/example.py

@@ -20,6 +20,10 @@ BROWSER_BGCOLOR = '#00000010'
 BROWSER_COLOR = '#ffffff'
 BROWSER_COLOR = '#ffffff'
 
 
 
 
+def remove_prefix(text, prefix):
+    return text[len(prefix):] if text.startswith(prefix) else text
+
+
 class example:
 class example:
 
 
     def __init__(self,
     def __init__(self,
@@ -49,7 +53,7 @@ class example:
                 code = inspect.getsource(f).split('# END OF EXAMPLE')[0].strip().splitlines()
                 code = inspect.getsource(f).split('# END OF EXAMPLE')[0].strip().splitlines()
                 while not code[0].startswith(' ' * 8):
                 while not code[0].startswith(' ' * 8):
                     del code[0]
                     del code[0]
-                code = ['from nicegui import ui'] + [line[8:].removeprefix('# ') for line in code]
+                code = ['from nicegui import ui'] + [remove_prefix(line[8:], '# ') for line in code]
                 code = ['' if line == '#' else line for line in code]
                 code = ['' if line == '#' else line for line in code]
                 if not code[-1].startswith('ui.run('):
                 if not code[-1].startswith('ui.run('):
                     code.append('')
                     code.append('')