Python mode
x
1
# Literals
2
1234
3
0.0e101
4
.123
5
0b01010011100
6
0o01234567
7
0x0987654321abcdef
8
7
9
2147483647
10
3L
11
79228162514264337593543950336L
12
0x100000000L
13
79228162514264337593543950336
14
0xdeadbeef
15
3.14j
16
10.j
17
10j
18
.001j
19
1e100j
20
3.14e-10j
21
22
23
# String Literals
24
'For\''
25
"God\""
26
"""so loved
27
the world"""
28
'''that he gave
29
his only begotten\' '''
30
'that whosoever believeth \
31
in him'
32
''
33
34
# Identifiers
35
__a__
36
a.b
37
a.b.c
38
39
#Unicode identifiers on Python3
40
# a = x\ddot
41
a⃗ = ẍ
42
# a = v\dot
43
a⃗ = v̇
44
45
#F\vec = m \cdot a\vec
46
F⃗ = m•a⃗
47
48
# Operators
49
+ - * / % & | ^ ~ < >
50
== != <= >= <> << >> // **
51
and or not in is
52
53
#infix matrix multiplication operator (PEP 465)
54
A @ B
55
56
# Delimiters
57
() [] {} , : ` = ; @ . # Note that @ and . require the proper context on Python 2.
58
+= -= *= /= %= &= |= ^=
59
//= >>= <<= **=
60
61
# Keywords
62
as assert break class continue def del elif else except
63
finally for from global if import lambda pass raise
64
return try while with yield
65
66
# Python 2 Keywords (otherwise Identifiers)
67
exec print
68
69
# Python 3 Keywords (otherwise Identifiers)
70
nonlocal
71
72
# Types
73
bool classmethod complex dict enumerate float frozenset int list object
74
property reversed set slice staticmethod str super tuple type
75
76
# Python 2 Types (otherwise Identifiers)
77
basestring buffer file long unicode xrange
78
79
# Python 3 Types (otherwise Identifiers)
80
bytearray bytes filter map memoryview open range zip
81
82
# Some Example code
83
import os
84
from package import ParentClass
85
86
87
def doesNothing():
88
pass
89
90
class ExampleClass(ParentClass):
91
92
def example(inputStr):
93
a = list(inputStr)
94
a.reverse()
95
return ''.join(a)
96
97
def __init__(self, mixin = 'Hello'):
98
self.mixin = mixin
99
100
# Python 3.6 f-strings (https://www.python.org/dev/peps/pep-0498/)
101
f'My name is {name}, my age next year is {age+1}, my anniversary is {anniversary:%A, %B %d, %Y}.'
102
f'He said his name is {name!r}.'
103
f"""He said his name is {name!r}."""
104
f'{"quoted string"}'
105
f'{{ {4*10} }}'
106
f'This is an error }'
107
f'This is ok }}'
108
fr'x={4*10}\n'
109
Cython mode
22
1
2
import numpy as np
3
cimport cython
4
from libc.math cimport sqrt
5
6
boundscheck(False) .
7
wraparound(False) .
8
def pairwise_cython(double[:, ::1] X):
9
cdef int M = X.shape[0]
10
cdef int N = X.shape[1]
11
cdef double tmp, d
12
cdef double[:, ::1] D = np.empty((M, M), dtype=np.float64)
13
for i in range(M):
14
for j in range(M):
15
d = 0.0
16
for k in range(N):
17
tmp = X[i, k] - X[j, k]
18
d += tmp * tmp
19
D[i, j] = sqrt(d)
20
return np.asarray(D)
21
22
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
.