index.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <!doctype html>
  2. <title>CodeMirror: Python mode</title>
  3. <meta charset="utf-8"/>
  4. <link rel=stylesheet href="../../doc/docs.css">
  5. <link rel="stylesheet" href="../../lib/codemirror.css">
  6. <script src="../../lib/codemirror.js"></script>
  7. <script src="../../addon/edit/matchbrackets.js"></script>
  8. <script src="python.js"></script>
  9. <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
  10. <div id=nav>
  11. <a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a>
  12. <ul>
  13. <li><a href="../../index.html">Home</a>
  14. <li><a href="../../doc/manual.html">Manual</a>
  15. <li><a href="https://github.com/marijnh/codemirror">Code</a>
  16. </ul>
  17. <ul>
  18. <li><a href="../index.html">Language modes</a>
  19. <li><a class=active href="#">Python</a>
  20. </ul>
  21. </div>
  22. <article>
  23. <h2>Python mode</h2>
  24. <div><textarea id="code" name="code">
  25. # Literals
  26. 1234
  27. 0.0e101
  28. .123
  29. 0b01010011100
  30. 0o01234567
  31. 0x0987654321abcdef
  32. 7
  33. 2147483647
  34. 3L
  35. 79228162514264337593543950336L
  36. 0x100000000L
  37. 79228162514264337593543950336
  38. 0xdeadbeef
  39. 3.14j
  40. 10.j
  41. 10j
  42. .001j
  43. 1e100j
  44. 3.14e-10j
  45. # String Literals
  46. 'For\''
  47. "God\""
  48. """so loved
  49. the world"""
  50. '''that he gave
  51. his only begotten\' '''
  52. 'that whosoever believeth \
  53. in him'
  54. ''
  55. # Identifiers
  56. __a__
  57. a.b
  58. a.b.c
  59. # Operators
  60. + - * / % & | ^ ~ < >
  61. == != <= >= <> << >> // **
  62. and or not in is
  63. # Delimiters
  64. () [] {} , : ` = ; @ . # Note that @ and . require the proper context.
  65. += -= *= /= %= &= |= ^=
  66. //= >>= <<= **=
  67. # Keywords
  68. as assert break class continue def del elif else except
  69. finally for from global if import lambda pass raise
  70. return try while with yield
  71. # Python 2 Keywords (otherwise Identifiers)
  72. exec print
  73. # Python 3 Keywords (otherwise Identifiers)
  74. nonlocal
  75. # Types
  76. bool classmethod complex dict enumerate float frozenset int list object
  77. property reversed set slice staticmethod str super tuple type
  78. # Python 2 Types (otherwise Identifiers)
  79. basestring buffer file long unicode xrange
  80. # Python 3 Types (otherwise Identifiers)
  81. bytearray bytes filter map memoryview open range zip
  82. # Some Example code
  83. import os
  84. from package import ParentClass
  85. @nonsenseDecorator
  86. def doesNothing():
  87. pass
  88. class ExampleClass(ParentClass):
  89. @staticmethod
  90. def example(inputStr):
  91. a = list(inputStr)
  92. a.reverse()
  93. return ''.join(a)
  94. def __init__(self, mixin = 'Hello'):
  95. self.mixin = mixin
  96. </textarea></div>
  97. <h2>Cython mode</h2>
  98. <div><textarea id="code-cython" name="code-cython">
  99. import numpy as np
  100. cimport cython
  101. from libc.math cimport sqrt
  102. @cython.boundscheck(False)
  103. @cython.wraparound(False)
  104. def pairwise_cython(double[:, ::1] X):
  105. cdef int M = X.shape[0]
  106. cdef int N = X.shape[1]
  107. cdef double tmp, d
  108. cdef double[:, ::1] D = np.empty((M, M), dtype=np.float64)
  109. for i in range(M):
  110. for j in range(M):
  111. d = 0.0
  112. for k in range(N):
  113. tmp = X[i, k] - X[j, k]
  114. d += tmp * tmp
  115. D[i, j] = sqrt(d)
  116. return np.asarray(D)
  117. </textarea></div>
  118. <script>
  119. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  120. mode: {name: "python",
  121. version: 2,
  122. singleLineStringErrors: false},
  123. lineNumbers: true,
  124. indentUnit: 4,
  125. tabMode: "shift",
  126. matchBrackets: true
  127. });
  128. CodeMirror.fromTextArea(document.getElementById("code-cython"), {
  129. mode: {name: "text/x-cython",
  130. version: 2,
  131. singleLineStringErrors: false},
  132. lineNumbers: true,
  133. indentUnit: 4,
  134. tabMode: "shift",
  135. matchBrackets: true
  136. });
  137. </script>
  138. <h2>Configuration Options for Python mode:</h2>
  139. <ul>
  140. <li>version - 2/3 - The version of Python to recognize. Default is 2.</li>
  141. <li>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.</li>
  142. </ul>
  143. <h2>Advanced Configuration Options:</h2>
  144. <p>Usefull for superset of python syntax like Enthought enaml, IPython magics and questionmark help</p>
  145. <ul>
  146. <li>singleOperators - RegEx - Regular Expression for single operator matching, default : <pre>^[\\+\\-\\*/%&amp;|\\^~&lt;&gt;!]</pre></li>
  147. <li>singleDelimiters - RegEx - Regular Expression for single delimiter matching, default : <pre>^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]</pre></li>
  148. <li>doubleOperators - RegEx - Regular Expression for double operators matching, default : <pre>^((==)|(!=)|(&lt;=)|(&gt;=)|(&lt;&gt;)|(&lt;&lt;)|(&gt;&gt;)|(//)|(\\*\\*))</pre></li>
  149. <li>doubleDelimiters - RegEx - Regular Expressoin for double delimiters matching, default : <pre>^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&amp;=)|(\\|=)|(\\^=))</pre></li>
  150. <li>tripleDelimiters - RegEx - Regular Expression for triple delimiters matching, default : <pre>^((//=)|(&gt;&gt;=)|(&lt;&lt;=)|(\\*\\*=))</pre></li>
  151. <li>identifiers - RegEx - Regular Expression for identifier, default : <pre>^[_A-Za-z][_A-Za-z0-9]*</pre></li>
  152. <li>extra_keywords - list of string - List of extra words ton consider as keywords</li>
  153. <li>extra_builtins - list of string - List of extra words ton consider as builtins</li>
  154. </ul>
  155. <p><strong>MIME types defined:</strong> <code>text/x-python</code> and <code>text/x-cython</code>.</p>
  156. </article>