Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.

Link zu der Vergleichsansicht

Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung
Nächste Überarbeitung
Vorherige Überarbeitung
user:hof:pyeditor [2026-04-24 14:22] – [Shared Sessions] hofuser:hof:pyeditor [2026-04-24 14:29] (aktuell) hof
Zeile 1: Zeile 1:
 # Bottom Python Editor # Bottom Python Editor
-<html><script type="module" src="https://bottom.ch/editor/latest/bottom-exercise.js"></script></html> 
  
 Bottom Editor offers a standalone editor version at [[https://bottom.ch/editor/]] and a web component embeddable as normal HTML elements after loading the module once. See the [[https://bottom.ch/editor/stable/doc/|public documentation]] for all options. Bottom Editor offers a standalone editor version at [[https://bottom.ch/editor/]] and a web component embeddable as normal HTML elements after loading the module once. See the [[https://bottom.ch/editor/stable/doc/|public documentation]] for all options.
  
 Also see [[~kara]] for a Kara shim on top of bottom-editor. Also see [[~kara]] for a Kara shim on top of bottom-editor.
- 
 ## Basic Usage ## Basic Usage
 +
 +### Direct HTML
 +Requires HTML-authoring (which may be a security risk with broad authorship).
  
 Within Dokuwiki, the HTML needs to be embedded into `<html>` tags for verbatim HTML. Within Dokuwiki, the HTML needs to be embedded into `<html>` tags for verbatim HTML.
Zeile 20: Zeile 21:
 </bottom-editor></html> </bottom-editor></html>
 </code> </code>
 +
 +### With Plugin
 +To avoid needing raw trusted HTML access, install the [[https://www.dokuwiki.org/plugin:bottomeditor|bottomeditor plugin]] and create editors without `<html>`:
 +
 +<code html>
 +<bottom-editor style="min-height: 6lh;" autorun>
 +print(42)
 +</bottom-editor>
 +</code>
 +
 +
 ## Shared Sessions ## Shared Sessions
 By default, all editors on a page share a single python runtime. Functions defined in one execution are available in all editors afterwards, similar to jupyter notebooks. If you want an editor to have a separate python runtime, use the `session` attribute: By default, all editors on a page share a single python runtime. Functions defined in one execution are available in all editors afterwards, similar to jupyter notebooks. If you want an editor to have a separate python runtime, use the `session` attribute:
Zeile 55: Zeile 67:
  
 <code html> <code html>
-<html><bottom-editor layout="canvas" autorun>+<bottom-editor layout="canvas" autorun id="turtle">
 import turtle import turtle
  
Zeile 65: Zeile 77:
     t.forward(i * 0.5)     t.forward(i * 0.5)
     t.left(59)     t.left(59)
-</bottom-editor></html>+</bottom-editor>
 </code> </code>
  
-<html><bottom-editor layout="canvas" autorun>+<bottom-editor layout="canvas" autorun id="turtle">
 import turtle import turtle
  
Zeile 78: Zeile 90:
     t.forward(i * 0.5)     t.forward(i * 0.5)
     t.left(59)     t.left(59)
-</bottom-editor></html>+</bottom-editor>
  
 ## Matplotlib ## Matplotlib
Zeile 84: Zeile 96:
  
 <code html> <code html>
-<html><bottom-editor layout="canvas" autorun>+<bottom-editor layout="canvas" autorun id="matplotlib">
 # Load packages from within python using micropip # Load packages from within python using micropip
 import micropip import micropip
Zeile 100: Zeile 112:
 plt.tight_layout() plt.tight_layout()
 plt.show() plt.show()
-</bottom-editor></html>+</bottom-editor>
 </code> </code>
  
-<html><bottom-editor layout="canvas" autorun>+<bottom-editor layout="canvas" autorun id="matplot">
 # Load packages from within python using micropip # Load packages from within python using micropip
 import micropip import micropip
Zeile 119: Zeile 131:
 plt.tight_layout() plt.tight_layout()
 plt.show() plt.show()
-</bottom-editor></html>+</bottom-editor>
  
 ## OpenCV ## OpenCV
Zeile 125: Zeile 137:
  
 <code html> <code html>
-<html><bottom-editor layout="canvas" autorun>+<bottom-editor layout="canvas" autorun id="opencv">
 # Load packages from within python using micropip # Load packages from within python using micropip
 import micropip import micropip
Zeile 142: Zeile 154:
 cv2.putText(img, 'OpenCV', (75, 160), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,255,255), 2) cv2.putText(img, 'OpenCV', (75, 160), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,255,255), 2)
 cv2.imshow('result', img) cv2.imshow('result', img)
-</bottom-editor></html>+</bottom-editor>
 </code> </code>
  
-<html><bottom-editor layout="canvas" autorun>+<bottom-editor layout="canvas" autorun id="opencv">
 # Load packages from within python using micropip # Load packages from within python using micropip
 import micropip import micropip
Zeile 162: Zeile 174:
 cv2.putText(img, 'OpenCV', (75, 160), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,255,255), 2) cv2.putText(img, 'OpenCV', (75, 160), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,255,255), 2)
 cv2.imshow('result', img) cv2.imshow('result', img)
-</bottom-editor></html>+</bottom-editor>
  
 ## Installing files ## Installing files
Zeile 168: Zeile 180:
  
 <code html> <code html>
-<html><bottom-editor zip='https://bottom.ch/ksr/py/files/2m.zip'>+<bottom-editor zip='https://bottom.ch/ksr/py/files/2m.zip' id="zip">
 with open('gemeinden.csv', 'r') as infile: with open('gemeinden.csv', 'r') as infile:
     for line in infile:     for line in infile:
Zeile 175: Zeile 187:
         if town == 'Romanshorn':         if town == 'Romanshorn':
             print(f'Romanshorn hat {tokens[2]} Einwohner')             print(f'Romanshorn hat {tokens[2]} Einwohner')
-</bottom-editor></html>+</bottom-editor>
 </code> </code>
  
-<html><bottom-editor zip='https://bottom.ch/ksr/py/files/2m.zip'>+<bottom-editor zip='https://bottom.ch/ksr/py/files/2m.zip' id="zip">
 with open('gemeinden.csv', 'r') as infile: with open('gemeinden.csv', 'r') as infile:
     for line in infile:     for line in infile:
Zeile 185: Zeile 197:
         if town == 'Romanshorn':         if town == 'Romanshorn':
             print(f'Romanshorn hat {tokens[2]} Einwohner')             print(f'Romanshorn hat {tokens[2]} Einwohner')
-</bottom-editor></html>+</bottom-editor> 
 ## Exercises ## Exercises
  
 <code html> <code html>
-<html><script type="module" src="https://bottom.ch/editor/stable/bottom-exercise.js"></script></html> +<bottom-exercise id="sum-to_n">
-<html><bottom-exercise id="sum-to_n">+
             Write a function <tt>sum_to(n)</tt> that returns             Write a function <tt>sum_to(n)</tt> that returns
             <tt>1 + 2 + &hellip; + n</tt>. Return <tt>0</tt> for             <tt>1 + 2 + &hellip; + n</tt>. Return <tt>0</tt> for
Zeile 207: Zeile 219:
     return sum(range(n+1))     return sum(range(n+1))
         </script>                 </script>        
-</bottom-exercise></html>+</bottom-exercise>
 </code> </code>
  
-<html><bottom-exercise id="sum-to_n">+<bottom-exercise id="sum-to_n">
             Write a function <tt>sum_to(n)</tt> that returns             Write a function <tt>sum_to(n)</tt> that returns
             <tt>1 + 2 + &hellip; + n</tt>. Return <tt>0</tt> for             <tt>1 + 2 + &hellip; + n</tt>. Return <tt>0</tt> for
Zeile 227: Zeile 239:
     return sum(range(n+1))     return sum(range(n+1))
         </script>                 </script>        
-</bottom-exercise></html>+</bottom-exercise> 
 ## Persistence ## Persistence
  
Zeile 233: Zeile 246:
  
 <code html> <code html>
-<html><bottom-editor style="min-height: 6lh;" id="storage-42">+<bottom-editor style="min-height: 6lh;" id="storage-42">
 print(42) print(42)
-</bottom-editor></html>+</bottom-editor>
 </code> </code>
  
  
-<html><bottom-editor style="min-height: 6lh;" id="storage-42">+<bottom-editor style="min-height: 6lh;" id="storage-42">
 print(42) print(42)
-</bottom-editor></html>+</bottom-editor>
  
  • user/hof/pyeditor.1777040534.txt.gz
  • Zuletzt geändert: 2026-04-24 14:22
  • von hof