python中的token bytes_Python token.type方法代碼示例

# 需要導入模塊: import token [as 別名]

# 或者: from token import type [as 別名]

def tokenize(readline):

"""

The tokenize() generator requires one argument, readline, which

must be a callable object which provides the same interface as the

readline() method of built-in file objects. Each call to the function

should return one line of input as bytes. Alternatively, readline

can be a callable function terminating with StopIteration:

readline = open(myfile, 'rb').__next__ # Example of alternate readline

The generator produces 5-tuples with these members: the token type; the

token string; a 2-tuple (srow, scol) of ints specifying the row and

column where the token begins in the source; a 2-tuple (erow, ecol) of

ints specifying the row and column where the token ends in the source;

and the line on which the token was found. The line passed is the

logical line; continuation lines are included.

The first token sequence will always be an ENCODING token

which tells you which encoding was used to decode the bytes stream.

"""

# This import is here to avoid problems when the itertools module is not

# built yet and tokenize is imported.

from itertools import chain, repeat

encoding, consumed = detect_encoding(readline)

rl_gen = iter(readline, b"")

empty = repeat(b"")

return _tokenize(chain(consumed, rl_gen, empty).__next__, encoding)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值