“Python/docs/3.9/library/tabnanny”的版本间差异

来自菜鸟教程
Python/docs/3.9/library/tabnanny
跳转至:导航、​搜索
(autoload)
 
(Page commit)
 
第1行: 第1行:
 +
{{DISPLAYTITLE:tabnanny — 模糊缩进检测 — Python 文档}}
 
<div id="module-tabnanny" class="section">
 
<div id="module-tabnanny" class="section">
  
 
<span id="tabnanny-detection-of-ambiguous-indentation"></span>
 
<span id="tabnanny-detection-of-ambiguous-indentation"></span>
= [[#module-tabnanny|<code>tabnanny</code>]] --- Detection of ambiguous indentation =
+
= tabnanny — 模糊缩进检测 =
  
'''Source code:''' [https://github.com/python/cpython/tree/3.9/Lib/tabnanny.py Lib/tabnanny.py]
+
'''源代码:''' [[#id1|<span id="id2" class="problematic">:source:`Lib/tabnanny.py`</span>]]
  
For the time being this module is intended to be called as a script. However it
+
 
is possible to import it into an IDE and use the function [[#tabnanny.check|<code>check()</code>]]
+
-----
described below.
+
 
 +
目前,该模块旨在作为脚本调用。 但是,可以将其导入 IDE 并使用下面描述的函数 [[#tabnanny.check|check()]]
  
 
<div class="admonition note">
 
<div class="admonition note">
  
注解
+
笔记
  
The API provided by this module is likely to change in future releases; such
+
此模块提供的 API 可能会在未来版本中更改; 此类更改可能无法向后兼容。
changes may not be backward compatible.
 
  
  
 
</div>
 
</div>
; <code>tabnanny.</code><code>check</code><span class="sig-paren">(</span>''<span class="n">file_or_dir</span>''<span class="sig-paren">)</span>
+
; <span class="sig-prename descclassname"><span class="pre">tabnanny.</span></span><span class="sig-name descname"><span class="pre">check</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">file_or_dir</span></span>''<span class="sig-paren">)</span>
: If ''file_or_dir'' is a directory and not a symbolic link, then recursively descend the directory tree named by ''file_or_dir'', checking all <code>.py</code> files along the way. If ''file_or_dir'' is an ordinary Python source file, it is checked for whitespace related problems. The diagnostic messages are written to standard output using the [[../functions#print|<code>print()</code>]] function.
+
: 如果 ''file_or_dir'' 是一个目录而不是一个符号链接,那么递归地下降由 ''file_or_dir'' 命名的目录树,一路检查所有 <code>.py</code> 文件。 如果 ''file_or_dir'' 是普通的 Python 源文件,则检查与空格相关的问题。 使用 [[../functions#print|print()]] 函数将诊断消息写入标准输出。
  
; <code>tabnanny.</code><code>verbose</code>
+
; <span class="sig-prename descclassname"><span class="pre">tabnanny.</span></span><span class="sig-name descname"><span class="pre">verbose</span></span>
: Flag indicating whether to print verbose messages. This is incremented by the <code>-v</code> option if called as a script.
+
: 指示是否打印详细消息的标志。 如果作为脚本调用,它会通过 <code>-v</code> 选项增加。
  
; <code>tabnanny.</code><code>filename_only</code>
+
; <span class="sig-prename descclassname"><span class="pre">tabnanny.</span></span><span class="sig-name descname"><span class="pre">filename_only</span></span>
: Flag indicating whether to print only the filenames of files containing whitespace related problems. This is set to true by the <code>-q</code> option if called as a script.
+
: 指示是否仅打印包含空格相关问题的文件的文件名的标志。 如果作为脚本调用,则通过 <code>-q</code> 选项将其设置为 true。
  
; ''exception'' <code>tabnanny.</code><code>NannyNag</code>
+
; ''<span class="pre">exception</span>'' <span class="sig-prename descclassname"><span class="pre">tabnanny.</span></span><span class="sig-name descname"><span class="pre">NannyNag</span></span>
: Raised by [[#tabnanny.process_tokens|<code>process_tokens()</code>]] if detecting an ambiguous indent. Captured and handled in [[#tabnanny.check|<code>check()</code>]].
+
: 如果检测到不明确的缩进,则由 [[#tabnanny.process_tokens|process_tokens()]] 引发。 在 [[#tabnanny.check|check()]] 中捕获和处理。
  
; <code>tabnanny.</code><code>process_tokens</code><span class="sig-paren">(</span>''<span class="n">tokens</span>''<span class="sig-paren">)</span>
+
; <span class="sig-prename descclassname"><span class="pre">tabnanny.</span></span><span class="sig-name descname"><span class="pre">process_tokens</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">tokens</span></span>''<span class="sig-paren">)</span>
: This function is used by [[#tabnanny.check|<code>check()</code>]] to process tokens generated by the [[../tokenize#module-tokenize|<code>tokenize</code>]] module.
+
: [[#tabnanny.check|check()]] 使用此函数来处理由 [[../tokenize#module-tokenize|tokenize]] 模块生成的令牌。
  
 
<div class="admonition seealso">
 
<div class="admonition seealso">
  
参见
+
也可以看看
 +
 
 +
; 模块 [[../tokenize#module-tokenize|代币化]]
 +
: Python 源代码的词法扫描器。
  
; Module [[../tokenize#module-tokenize|<code>tokenize</code>]]
 
: Lexical scanner for Python source code.
 
  
 +
</div>
  
 
</div>
 
</div>
 +
<div class="clearer">
 +
 +
  
 
</div>
 
</div>
  
[[Category:Python 3.9 中文文档]]
+
[[Category:Python 3.9 文档]]

2021年10月31日 (日) 04:53的最新版本

tabnanny — 模糊缩进检测

源代码: :source:`Lib/tabnanny.py`



目前,该模块旨在作为脚本调用。 但是,可以将其导入 IDE 并使用下面描述的函数 check()

笔记

此模块提供的 API 可能会在未来版本中更改; 此类更改可能无法向后兼容。


tabnanny.check(file_or_dir)
如果 file_or_dir 是一个目录而不是一个符号链接,那么递归地下降由 file_or_dir 命名的目录树,一路检查所有 .py 文件。 如果 file_or_dir 是普通的 Python 源文件,则检查与空格相关的问题。 使用 print() 函数将诊断消息写入标准输出。
tabnanny.verbose
指示是否打印详细消息的标志。 如果作为脚本调用,它会通过 -v 选项增加。
tabnanny.filename_only
指示是否仅打印包含空格相关问题的文件的文件名的标志。 如果作为脚本调用,则通过 -q 选项将其设置为 true。
exception tabnanny.NannyNag
如果检测到不明确的缩进,则由 process_tokens() 引发。 在 check() 中捕获和处理。
tabnanny.process_tokens(tokens)
check() 使用此函数来处理由 tokenize 模块生成的令牌。

也可以看看

模块 代币化
Python 源代码的词法扫描器。