.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
CodeMirror
Home Manual Code
Language modes Python
Python mode
# Literals 1234 0.0e101 .123 0b01010011100 0o01234567 0x0987654321abcdef 7 2147483647 3L 79228162514264337593543950336L 0x100000000L 79228162514264337593543950336 0xdeadbeef 3.14j 10.j 10j .001j 1e100j 3.14e-10j
# String Literals 'For\'' "God\"" """so loved the world""" '''that he gave his only begotten\' ''' 'that whosoever believeth \ in him' ''
# Identifiers __a__ a.b a.b.c
#Unicode identifiers on Python3 # a = x\ddot a⃗ = ẍ # a = v\dot a⃗ = v̇
#F\vec = m \cdot a\vec F⃗ = m•a⃗
# Operators + - * / % & | ^ ~ == != = <> > // ** and or not in is
#infix matrix multiplication operator (PEP 465) A @ B
# Delimiters () [] {} , : ` = ; @ . # Note that @ and . require the proper context on Python 2. += -= *= /= %= &= |= ^= //= >>=
Cython mode
import numpy as np cimport cython from libc.math cimport sqrt
@cython.boundscheck(False) @cython.wraparound(False) def pairwise_cython(double[:, ::1] X): cdef int M = X.shape[0] cdef int N = X.shape[1] cdef double tmp, d cdef double[:, ::1] D = np.empty((M, M), dtype=np.float64) for i in range(M): for j in range(M): d = 0.0 for k in range(N): tmp = X[i, k] - X[j, k] d += tmp * tmp D[i, j] = sqrt(d) return np.asarray(D)
var editor = CodeMirror.fromTextArea(document.getElementById("code"), { mode: {name: "python", version: 3, singleLineStringErrors: false}, lineNumbers: true, indentUnit: 4, matchBrackets: true });
CodeMirror.fromTextArea(document.getElementById("code-cython"), { mode: {name: "text/x-cython", version: 2, singleLineStringErrors: false}, lineNumbers: true, indentUnit: 4, matchBrackets: true });
Configuration Options for Python mode
version - 2/3 - The version of Python to recognize. Default is 3. singleLineStringErrors - true/false - If you have a single-line string that is not terminated at the end of the line, this will show subsequent lines as errors if true, otherwise it will consider the newline as the end of the string. Default is false. hangingIndent - int - If you want to write long arguments to a function starting on a new line, how much that line should be indented. Defaults to one normal indentation unit.
Advanced Configuration Options
Usefull for superset of python syntax like Enthought enaml, IPython magics and questionmark help
singleOperators - RegEx - Regular Expression for single operator matching, default : ^[\+\-\*/%&|\^~<>!] including @ on Python 3 singleDelimiters - RegEx - Regular Expression for single delimiter matching, default : ^[\(\)\[\]\{\}@,:`=;\.] doubleOperators - RegEx - Regular Expression for double operators matching, default : ^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\*\*)) doubleDelimiters - RegEx - Regular Expression for double delimiters matching, default : ^((\+=)|(\-=)|(\*=)|(%=)|(/=)|(&=)|(\|=)|(\^=)) tripleDelimiters - RegEx - Regular Expression for triple delimiters matching, default : ^((//=)|(>>=)|(<<=)|(\*\*=)) identifiers - RegEx - Regular Expression for identifier, default : ^[_A-Za-z][_A-Za-z0-9]* on Python 2 and ^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]* on Python 3. extra_keywords - list of string - List of extra words ton consider as keywords extra_builtins - list of string - List of extra words ton consider as builtins
MIME types defined: text/x-python and text/x-cython .