Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
6c60d099
Kaydet (Commit)
6c60d099
authored
Eyl 09, 2010
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Improve the repr for the TokenInfo named tuple.
üst
44d7b6ad
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
2 deletions
+29
-2
tokenize.rst
Doc/library/tokenize.rst
+1
-1
tokenize.py
Lib/tokenize.py
+28
-1
No files found.
Doc/library/tokenize.rst
Dosyayı görüntüle @
6c60d099
...
...
@@ -111,7 +111,7 @@ function it uses to do this is available:
return fp.read()
Example of a script re
-
writer that transforms float literals into Decimal
Example of a script rewriter that transforms float literals into Decimal
objects::
from tokenize import tokenize, untokenize, NUMBER, STRING, NAME, OP
...
...
Lib/tokenize.py
Dosyayı görüntüle @
6c60d099
...
...
@@ -63,7 +63,9 @@ class TokenInfo(tuple):
return
result
def
__repr__
(
self
):
return
'TokenInfo(type=
%
r, string=
%
r, start=
%
r, end=
%
r, line=
%
r)'
%
self
typ
=
self
[
0
]
return
'TokenInfo(type=
%
s, string=
%
r, start=
%
r, end=
%
r, line=
%
r)'
%
\
(((
'
%
d (
%
s)'
%
(
typ
,
tok_name
[
typ
])),)
+
self
[
1
:])
def
_asdict
(
self
):
'Return a new dict which maps field names to their values'
...
...
@@ -550,3 +552,28 @@ def _tokenize(readline, encoding):
# library that expect to be able to use tokenize with strings
def
generate_tokens
(
readline
):
return
_tokenize
(
readline
,
None
)
if
__name__
==
"__main__"
:
# Quick sanity check
s
=
b
'''def parseline(self, line):
"""Parse the line into a command name and a string containing
the arguments. Returns a tuple containing (command, args, line).
'command' and 'args' may be None if the line couldn't be parsed.
"""
line = line.strip()
if not line:
return None, None, line
elif line[0] == '?':
line = 'help ' + line[1:]
elif line[0] == '!':
if hasattr(self, 'do_shell'):
line = 'shell ' + line[1:]
else:
return None, None, line
i, n = 0, len(line)
while i < n and line[i] in self.identchars: i = i+1
cmd, arg = line[:i], line[i:].strip()
return cmd, arg, line
'''
for
tok
in
tokenize
(
iter
(
s
.
splitlines
())
.
__next__
):
print
(
tok
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment