{
    "mode": "pydoc",
    "parameter": "tokenize",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/pydoc/tokenize/json",
    "generated": "2026-06-02T13:20:08Z",
    "sections": {
        "NAME": {
            "content": "tokenize - Tokenization help for Python programs.\n",
            "subsections": []
        },
        "MODULE REFERENCE": {
            "content": "https://docs.python.org/3.10/library/tokenize.html\n\nThe following documentation is automatically generated from the Python\nsource files.  It may be incomplete, incorrect or include features that\nare considered implementation detail and may vary between Python\nimplementations.  When in doubt, consult the module reference at the\nlocation listed above.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "",
            "subsections": [
                {
                    "name": "tokenize",
                    "content": "Python tokens.  It decodes the bytes according to PEP-0263 for\ndetermining source file encoding.\n\nIt accepts a readline-like method which is called repeatedly to get the\nnext line of input (or b\"\" for EOF).  It generates 5-tuples with these\nmembers:\n\nthe token type (see token.py)\nthe token (a string)\nthe starting (row, column) indices of the token (a 2-tuple of ints)\nthe ending (row, column) indices of the token (a 2-tuple of ints)\nthe original line (string)\n\nIt is designed to match the working of the Python tokenizer exactly, except\nthat it produces COMMENT tokens for comments and gives type OP for all\noperators.  Additionally, all token lists start with an ENCODING token\nwhich tells you which encoding was used to decode the bytes stream.\n"
                }
            ]
        },
        "CLASSES": {
            "content": "TokenInfo(builtins.tuple)\nTokenInfo\n",
            "subsections": [
                {
                    "name": "class TokenInfo",
                    "content": "|  TokenInfo(type, string, start, end, line)\n|\n|  Method resolution order:\n|      TokenInfo\n|      TokenInfo\n|      builtins.tuple\n|      builtins.object\n|\n|  Methods defined here:\n|\n|  repr(self)\n|      Return a nicely formatted representation string\n|\n|  ----------------------------------------------------------------------\n|  Readonly properties defined here:\n|\n|  exacttype\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors defined here:\n|\n|  dict\n|      dictionary for instance variables (if defined)\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from TokenInfo:\n|\n|  getnewargs(self)\n|      Return self as a plain tuple.  Used by copy and pickle.\n|\n|  asdict(self)\n|      Return a new dict which maps field names to their values.\n|\n|  replace(self, /, kwds)\n|      Return a new TokenInfo object replacing specified fields with new values\n|\n|  ----------------------------------------------------------------------\n|  Class methods inherited from TokenInfo:\n|\n|  make(iterable) from builtins.type\n|      Make a new TokenInfo object from a sequence or iterable\n|\n|  ----------------------------------------------------------------------\n|  Static methods inherited from TokenInfo:\n|\n|  new(cls, type, string, start, end, line)\n|      Create new instance of TokenInfo(type, string, start, end, line)\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors inherited from TokenInfo:\n|\n|  type\n|      Alias for field number 0\n|\n|  string\n|      Alias for field number 1\n|\n|  start\n|      Alias for field number 2\n|\n|  end\n|      Alias for field number 3\n|\n|  line\n|      Alias for field number 4\n|\n|  ----------------------------------------------------------------------\n|  Data and other attributes inherited from TokenInfo:\n|\n|  matchargs = ('type', 'string', 'start', 'end', 'line')\n|\n|  fielddefaults = {}\n|\n|  fields = ('type', 'string', 'start', 'end', 'line')\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.tuple:\n|\n|  add(self, value, /)\n|      Return self+value.\n|\n|  contains(self, key, /)\n|      Return key in self.\n|\n|  eq(self, value, /)\n|      Return self==value.\n|\n|  ge(self, value, /)\n|      Return self>=value.\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  getitem(self, key, /)\n|      Return self[key].\n|\n|  gt(self, value, /)\n|      Return self>value.\n|\n|  hash(self, /)\n|      Return hash(self).\n|\n|  iter(self, /)\n|      Implement iter(self).\n|\n|  le(self, value, /)\n|      Return self<=value.\n|\n|  len(self, /)\n|      Return len(self).\n|\n|  lt(self, value, /)\n|      Return self<value.\n|\n|  mul(self, value, /)\n|      Return self*value.\n|\n|  ne(self, value, /)\n|      Return self!=value.\n|\n|  rmul(self, value, /)\n|      Return value*self.\n|\n|  count(self, value, /)\n|      Return number of occurrences of value.\n|\n|  index(self, value, start=0, stop=9223372036854775807, /)\n|      Return first index of value.\n|\n|      Raises ValueError if the value is not present.\n|\n|  ----------------------------------------------------------------------\n|  Class methods inherited from builtins.tuple:\n|\n|  classgetitem(...) from builtins.type\n|      See PEP 585\n"
                }
            ]
        },
        "FUNCTIONS": {
            "content": "ISEOF(x)\n\nISNONTERMINAL(x)\n\nISTERMINAL(x)\n",
            "subsections": [
                {
                    "name": "detect_encoding",
                    "content": "The detectencoding() function is used to detect the encoding that should\nbe used to decode a Python source file.  It requires one argument, readline,\nin the same way as the tokenize() generator.\n\nIt will call readline a maximum of twice, and return the encoding used\n(as a string) and a list of any lines (left as bytes) it has read in.\n\nIt detects the encoding from the presence of a utf-8 bom or an encoding\ncookie as specified in pep-0263.  If both a bom and a cookie are present,\nbut disagree, a SyntaxError will be raised.  If the encoding cookie is an\ninvalid charset, raise a SyntaxError.  Note that if a utf-8 bom is found,\n'utf-8-sig' is returned.\n\nIf no encoding is specified, then the default of 'utf-8' will be returned.\n"
                },
                {
                    "name": "generate_tokens",
                    "content": "Tokenize a source reading Python code as unicode strings.\n\nThis has the same API as tokenize(), except that it expects the *readline*\ncallable to return str objects instead of bytes.\n"
                },
                {
                    "name": "tokenize",
                    "content": "The tokenize() generator requires one argument, readline, which\nmust be a callable object which provides the same interface as the\nreadline() method of built-in file objects.  Each call to the function\nshould return one line of input as bytes.  Alternatively, readline\ncan be a callable function terminating with StopIteration:\nreadline = open(myfile, 'rb').next  # Example of alternate readline\n\nThe generator produces 5-tuples with these members: the token type; the\ntoken string; a 2-tuple (srow, scol) of ints specifying the row and\ncolumn where the token begins in the source; a 2-tuple (erow, ecol) of\nints specifying the row and column where the token ends in the source;\nand the line on which the token was found.  The line passed is the\nphysical line.\n\nThe first token sequence will always be an ENCODING token\nwhich tells you which encoding was used to decode the bytes stream.\n"
                },
                {
                    "name": "untokenize",
                    "content": "Transform tokens back into Python source code.\nIt returns a bytes object, encoded using the ENCODING\ntoken, which is the first token sequence output by tokenize.\n\nEach element returned by the iterable must be a token sequence\nwith at least two elements, a token number and token value.  If\nonly two tokens are passed, the resulting output is poor.\n\nRound-trip invariant for full input:\nUntokenized source will match input source exactly\n\nRound-trip invariant for limited input:\n# Output bytes will tokenize back to the input\nt1 = [tok[:2] for tok in tokenize(f.readline)]\nnewcode = untokenize(t1)\nreadline = BytesIO(newcode).readline\nt2 = [tok[:2] for tok in tokenize(readline)]\nassert t1 == t2\n"
                }
            ]
        },
        "DATA": {
            "content": "AMPER = 19\nAMPEREQUAL = 41\nASYNC = 56\nAT = 49\nATEQUAL = 50\nAWAIT = 55\nCIRCUMFLEX = 32\nCIRCUMFLEXEQUAL = 43\nCOLON = 11\nCOLONEQUAL = 53\nCOMMA = 12\nCOMMENT = 61\nDEDENT = 6\nDOT = 23\nDOUBLESLASH = 47\nDOUBLESLASHEQUAL = 48\nDOUBLESTAR = 35\nDOUBLESTAREQUAL = 46\nELLIPSIS = 52\nENCODING = 63\nENDMARKER = 0\nEQEQUAL = 27\nEQUAL = 22\nERRORTOKEN = 60\nGREATER = 21\nGREATEREQUAL = 30\nINDENT = 5\nLBRACE = 25\nLEFTSHIFT = 33\nLEFTSHIFTEQUAL = 44\nLESS = 20\nLESSEQUAL = 29\nLPAR = 7\nLSQB = 9\nMINEQUAL = 37\nMINUS = 15\nNAME = 1\nNEWLINE = 4\nNL = 62\nNOTEQUAL = 28\nNTOFFSET = 256\nNUMBER = 2\nNTOKENS = 64\nOP = 54\nPERCENT = 24\nPERCENTEQUAL = 40\nPLUS = 14\nPLUSEQUAL = 36\nRARROW = 51\nRBRACE = 26\nRIGHTSHIFT = 34\nRIGHTSHIFTEQUAL = 45\nRPAR = 8\nRSQB = 10\nSEMI = 13\nSLASH = 17\nSLASHEQUAL = 39\nSOFTKEYWORD = 59\nSTAR = 16\nSTAREQUAL = 38\nSTRING = 3\nTILDE = 31\nTYPECOMMENT = 58\nTYPEIGNORE = 57\nVBAR = 18\nVBAREQUAL = 42\nall = ['tokname', 'ISTERMINAL', 'ISNONTERMINAL', 'ISEOF', 'ENDMAR...\ntokname = {0: 'ENDMARKER', 1: 'NAME', 2: 'NUMBER', 3: 'STRING', 4: 'N...\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Ka-Ping Yee <ping@lfw.org>\n",
            "subsections": []
        },
        "CREDITS": {
            "content": "GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, Skip Montanaro, Raymond Hettinger, Trent Nelson, Michael Foord\n",
            "subsections": []
        },
        "FILE": {
            "content": "/usr/lib/python3.10/tokenize.py\n\n",
            "subsections": []
        }
    },
    "summary": "tokenize - Tokenization help for Python programs.",
    "flags": [],
    "examples": [],
    "see_also": []
}