gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

498 lines
32KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="importlib.resources.abc – Abstract base classes for resources" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/importlib.resources.abc.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Source code: Lib/importlib/resources/abc.py" />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="Source code: Lib/importlib/resources/abc.py" />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>importlib.resources.abc – Abstract base classes for resources &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="importlib.metadata – Accessing package metadata" href="importlib.metadata.html" />
  33. <link rel="prev" title="importlib.resources – Package resource reading, opening and access" href="importlib.resources.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/importlib.resources.abc.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h4>Previous topic</h4>
  84. <p class="topless"><a href="importlib.resources.html"
  85. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.resources</span></code> – Package resource reading, opening and access</a></p>
  86. </div>
  87. <div>
  88. <h4>Next topic</h4>
  89. <p class="topless"><a href="importlib.metadata.html"
  90. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.metadata</span></code> – Accessing package metadata</a></p>
  91. </div>
  92. <div role="note" aria-label="source link">
  93. <h3>This Page</h3>
  94. <ul class="this-page-menu">
  95. <li><a href="../bugs.html">Report a Bug</a></li>
  96. <li>
  97. <a href="https://github.com/python/cpython/blob/main/Doc/library/importlib.resources.abc.rst"
  98. rel="nofollow">Show Source
  99. </a>
  100. </li>
  101. </ul>
  102. </div>
  103. </nav>
  104. </div>
  105. </div>
  106. <div class="related" role="navigation" aria-label="related navigation">
  107. <h3>Navigation</h3>
  108. <ul>
  109. <li class="right" style="margin-right: 10px">
  110. <a href="../genindex.html" title="General Index"
  111. accesskey="I">index</a></li>
  112. <li class="right" >
  113. <a href="../py-modindex.html" title="Python Module Index"
  114. >modules</a> |</li>
  115. <li class="right" >
  116. <a href="importlib.metadata.html" title="importlib.metadata – Accessing package metadata"
  117. accesskey="N">next</a> |</li>
  118. <li class="right" >
  119. <a href="importlib.resources.html" title="importlib.resources – Package resource reading, opening and access"
  120. accesskey="P">previous</a> |</li>
  121. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  122. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  123. <li class="switchers">
  124. <div class="language_switcher_placeholder"></div>
  125. <div class="version_switcher_placeholder"></div>
  126. </li>
  127. <li>
  128. </li>
  129. <li id="cpython-language-and-version">
  130. <a href="../index.html">3.12.3 Documentation</a> &#187;
  131. </li>
  132. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  133. <li class="nav-item nav-item-2"><a href="modules.html" accesskey="U">Importing Modules</a> &#187;</li>
  134. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.resources.abc</span></code> – Abstract base classes for resources</a></li>
  135. <li class="right">
  136. <div class="inline-search" role="search">
  137. <form class="inline-search" action="../search.html" method="get">
  138. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  139. <input type="submit" value="Go" />
  140. </form>
  141. </div>
  142. |
  143. </li>
  144. <li class="right">
  145. <label class="theme-selector-label">
  146. Theme
  147. <select class="theme-selector" oninput="activateTheme(this.value)">
  148. <option value="auto" selected>Auto</option>
  149. <option value="light">Light</option>
  150. <option value="dark">Dark</option>
  151. </select>
  152. </label> |</li>
  153. </ul>
  154. </div>
  155. <div class="document">
  156. <div class="documentwrapper">
  157. <div class="bodywrapper">
  158. <div class="body" role="main">
  159. <section id="module-importlib.resources.abc">
  160. <span id="importlib-resources-abc-abstract-base-classes-for-resources"></span><h1><a class="reference internal" href="#module-importlib.resources.abc" title="importlib.resources.abc: Abstract base classes for resources"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.resources.abc</span></code></a> – Abstract base classes for resources<a class="headerlink" href="#module-importlib.resources.abc" title="Link to this heading">¶</a></h1>
  161. <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/importlib/resources/abc.py">Lib/importlib/resources/abc.py</a></p>
  162. <hr class="docutils" />
  163. <div class="versionadded">
  164. <p><span class="versionmodified added">New in version 3.11.</span></p>
  165. </div>
  166. <dl class="py class">
  167. <dt class="sig sig-object py" id="importlib.resources.abc.ResourceReader">
  168. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">importlib.resources.abc.</span></span><span class="sig-name descname"><span class="pre">ResourceReader</span></span><a class="headerlink" href="#importlib.resources.abc.ResourceReader" title="Link to this definition">¶</a></dt>
  169. <dd><p><em>Superseded by TraversableResources</em></p>
  170. <p>An <a class="reference internal" href="../glossary.html#term-abstract-base-class"><span class="xref std std-term">abstract base class</span></a> to provide the ability to read
  171. <em>resources</em>.</p>
  172. <p>From the perspective of this ABC, a <em>resource</em> is a binary
  173. artifact that is shipped within a package. Typically this is
  174. something like a data file that lives next to the <code class="docutils literal notranslate"><span class="pre">__init__.py</span></code>
  175. file of the package. The purpose of this class is to help abstract
  176. out the accessing of such data files so that it does not matter if
  177. the package and its data file(s) are stored in a e.g. zip file
  178. versus on the file system.</p>
  179. <p>For any of methods of this class, a <em>resource</em> argument is
  180. expected to be a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a> which represents
  181. conceptually just a file name. This means that no subdirectory
  182. paths should be included in the <em>resource</em> argument. This is
  183. because the location of the package the reader is for, acts as the
  184. “directory”. Hence the metaphor for directories and file
  185. names is packages and resources, respectively. This is also why
  186. instances of this class are expected to directly correlate to
  187. a specific package (instead of potentially representing multiple
  188. packages or a module).</p>
  189. <p>Loaders that wish to support resource reading are expected to
  190. provide a method called <code class="docutils literal notranslate"><span class="pre">get_resource_reader(fullname)</span></code> which
  191. returns an object implementing this ABC’s interface. If the module
  192. specified by fullname is not a package, this method should return
  193. <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a>. An object compatible with this ABC should only be
  194. returned when the specified module is a package.</p>
  195. <div class="deprecated-removed">
  196. <p><span class="versionmodified">Deprecated since version 3.12, will be removed in version 3.14: </span>Use <a class="reference internal" href="#importlib.resources.abc.TraversableResources" title="importlib.resources.abc.TraversableResources"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.resources.abc.TraversableResources</span></code></a> instead.</p>
  197. </div>
  198. <dl class="py method">
  199. <dt class="sig sig-object py" id="importlib.resources.abc.ResourceReader.open_resource">
  200. <em class="property"><span class="pre">abstractmethod</span> </em><span class="sig-name descname"><span class="pre">open_resource</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">resource</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.ResourceReader.open_resource" title="Link to this definition">¶</a></dt>
  201. <dd><p>Returns an opened, <a class="reference internal" href="../glossary.html#term-file-like-object"><span class="xref std std-term">file-like object</span></a> for binary reading
  202. of the <em>resource</em>.</p>
  203. <p>If the resource cannot be found, <a class="reference internal" href="exceptions.html#FileNotFoundError" title="FileNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileNotFoundError</span></code></a> is
  204. raised.</p>
  205. </dd></dl>
  206. <dl class="py method">
  207. <dt class="sig sig-object py" id="importlib.resources.abc.ResourceReader.resource_path">
  208. <em class="property"><span class="pre">abstractmethod</span> </em><span class="sig-name descname"><span class="pre">resource_path</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">resource</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.ResourceReader.resource_path" title="Link to this definition">¶</a></dt>
  209. <dd><p>Returns the file system path to the <em>resource</em>.</p>
  210. <p>If the resource does not concretely exist on the file system,
  211. raise <a class="reference internal" href="exceptions.html#FileNotFoundError" title="FileNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileNotFoundError</span></code></a>.</p>
  212. </dd></dl>
  213. <dl class="py method">
  214. <dt class="sig sig-object py" id="importlib.resources.abc.ResourceReader.is_resource">
  215. <em class="property"><span class="pre">abstractmethod</span> </em><span class="sig-name descname"><span class="pre">is_resource</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.ResourceReader.is_resource" title="Link to this definition">¶</a></dt>
  216. <dd><p>Returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if the named <em>name</em> is considered a resource.
  217. <a class="reference internal" href="exceptions.html#FileNotFoundError" title="FileNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileNotFoundError</span></code></a> is raised if <em>name</em> does not exist.</p>
  218. </dd></dl>
  219. <dl class="py method">
  220. <dt class="sig sig-object py" id="importlib.resources.abc.ResourceReader.contents">
  221. <em class="property"><span class="pre">abstractmethod</span> </em><span class="sig-name descname"><span class="pre">contents</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.ResourceReader.contents" title="Link to this definition">¶</a></dt>
  222. <dd><p>Returns an <a class="reference internal" href="../glossary.html#term-iterable"><span class="xref std std-term">iterable</span></a> of strings over the contents of
  223. the package. Do note that it is not required that all names
  224. returned by the iterator be actual resources, e.g. it is
  225. acceptable to return names for which <a class="reference internal" href="#importlib.resources.abc.ResourceReader.is_resource" title="importlib.resources.abc.ResourceReader.is_resource"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_resource()</span></code></a> would
  226. be false.</p>
  227. <p>Allowing non-resource names to be returned is to allow for
  228. situations where how a package and its resources are stored
  229. are known a priori and the non-resource names would be useful.
  230. For instance, returning subdirectory names is allowed so that
  231. when it is known that the package and resources are stored on
  232. the file system then those subdirectory names can be used
  233. directly.</p>
  234. <p>The abstract method returns an iterable of no items.</p>
  235. </dd></dl>
  236. </dd></dl>
  237. <dl class="py class">
  238. <dt class="sig sig-object py" id="importlib.resources.abc.Traversable">
  239. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">importlib.resources.abc.</span></span><span class="sig-name descname"><span class="pre">Traversable</span></span><a class="headerlink" href="#importlib.resources.abc.Traversable" title="Link to this definition">¶</a></dt>
  240. <dd><p>An object with a subset of <a class="reference internal" href="pathlib.html#pathlib.Path" title="pathlib.Path"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a> methods suitable for
  241. traversing directories and opening files.</p>
  242. <p>For a representation of the object on the file-system, use
  243. <a class="reference internal" href="importlib.resources.html#importlib.resources.as_file" title="importlib.resources.as_file"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.resources.as_file()</span></code></a>.</p>
  244. <dl class="py attribute">
  245. <dt class="sig sig-object py" id="importlib.resources.abc.Traversable.name">
  246. <span class="sig-name descname"><span class="pre">name</span></span><a class="headerlink" href="#importlib.resources.abc.Traversable.name" title="Link to this definition">¶</a></dt>
  247. <dd><p>Abstract. The base name of this object without any parent references.</p>
  248. </dd></dl>
  249. <dl class="py method">
  250. <dt class="sig sig-object py" id="importlib.resources.abc.Traversable.iterdir">
  251. <em class="property"><span class="pre">abstractmethod</span> </em><span class="sig-name descname"><span class="pre">iterdir</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.Traversable.iterdir" title="Link to this definition">¶</a></dt>
  252. <dd><p>Yield Traversable objects in self.</p>
  253. </dd></dl>
  254. <dl class="py method">
  255. <dt class="sig sig-object py" id="importlib.resources.abc.Traversable.is_dir">
  256. <em class="property"><span class="pre">abstractmethod</span> </em><span class="sig-name descname"><span class="pre">is_dir</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.Traversable.is_dir" title="Link to this definition">¶</a></dt>
  257. <dd><p>Return True if self is a directory.</p>
  258. </dd></dl>
  259. <dl class="py method">
  260. <dt class="sig sig-object py" id="importlib.resources.abc.Traversable.is_file">
  261. <em class="property"><span class="pre">abstractmethod</span> </em><span class="sig-name descname"><span class="pre">is_file</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.Traversable.is_file" title="Link to this definition">¶</a></dt>
  262. <dd><p>Return True if self is a file.</p>
  263. </dd></dl>
  264. <dl class="py method">
  265. <dt class="sig sig-object py" id="importlib.resources.abc.Traversable.joinpath">
  266. <em class="property"><span class="pre">abstractmethod</span> </em><span class="sig-name descname"><span class="pre">joinpath</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">pathsegments</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.Traversable.joinpath" title="Link to this definition">¶</a></dt>
  267. <dd><p>Traverse directories according to <em>pathsegments</em> and return
  268. the result as <code class="xref py py-class docutils literal notranslate"><span class="pre">Traversable</span></code>.</p>
  269. <p>Each <em>pathsegments</em> argument may contain multiple names separated by
  270. forward slashes (<code class="docutils literal notranslate"><span class="pre">/</span></code>, <code class="docutils literal notranslate"><span class="pre">posixpath.sep</span></code> ).
  271. For example, the following are equivalent:</p>
  272. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">files</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="s1">&#39;subdir&#39;</span><span class="p">,</span> <span class="s1">&#39;subsuddir&#39;</span><span class="p">,</span> <span class="s1">&#39;file.txt&#39;</span><span class="p">)</span>
  273. <span class="n">files</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="s1">&#39;subdir/subsuddir/file.txt&#39;</span><span class="p">)</span>
  274. </pre></div>
  275. </div>
  276. <p>Note that some <code class="xref py py-class docutils literal notranslate"><span class="pre">Traversable</span></code> implementations
  277. might not be updated to the latest version of the protocol.
  278. For compatibility with such implementations, provide a single argument
  279. without path separators to each call to <code class="docutils literal notranslate"><span class="pre">joinpath</span></code>. For example:</p>
  280. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">files</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="s1">&#39;subdir&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="s1">&#39;subsubdir&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">joinpath</span><span class="p">(</span><span class="s1">&#39;file.txt&#39;</span><span class="p">)</span>
  281. </pre></div>
  282. </div>
  283. <div class="versionchanged">
  284. <p><span class="versionmodified changed">Changed in version 3.11: </span><code class="docutils literal notranslate"><span class="pre">joinpath</span></code> accepts multiple <em>pathsegments</em>, and these segments
  285. may contain forward slashes as path separators.
  286. Previously, only a single <em>child</em> argument was accepted.</p>
  287. </div>
  288. </dd></dl>
  289. <dl class="py method">
  290. <dt class="sig sig-object py" id="importlib.resources.abc.Traversable.__truediv__">
  291. <em class="property"><span class="pre">abstractmethod</span> </em><span class="sig-name descname"><span class="pre">__truediv__</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">child</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.Traversable.__truediv__" title="Link to this definition">¶</a></dt>
  292. <dd><p>Return Traversable child in self.
  293. Equivalent to <code class="docutils literal notranslate"><span class="pre">joinpath(child)</span></code>.</p>
  294. </dd></dl>
  295. <dl class="py method">
  296. <dt class="sig sig-object py" id="importlib.resources.abc.Traversable.open">
  297. <em class="property"><span class="pre">abstractmethod</span> </em><span class="sig-name descname"><span class="pre">open</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'r'</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.Traversable.open" title="Link to this definition">¶</a></dt>
  298. <dd><p><em>mode</em> may be ‘r’ or ‘rb’ to open as text or binary. Return a handle
  299. suitable for reading (same as <a class="reference internal" href="pathlib.html#pathlib.Path.open" title="pathlib.Path.open"><code class="xref py py-attr docutils literal notranslate"><span class="pre">pathlib.Path.open</span></code></a>).</p>
  300. <p>When opening as text, accepts encoding parameters such as those
  301. accepted by <a class="reference internal" href="io.html#io.TextIOWrapper" title="io.TextIOWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.TextIOWrapper</span></code></a>.</p>
  302. </dd></dl>
  303. <dl class="py method">
  304. <dt class="sig sig-object py" id="importlib.resources.abc.Traversable.read_bytes">
  305. <span class="sig-name descname"><span class="pre">read_bytes</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.Traversable.read_bytes" title="Link to this definition">¶</a></dt>
  306. <dd><p>Read contents of self as bytes.</p>
  307. </dd></dl>
  308. <dl class="py method">
  309. <dt class="sig sig-object py" id="importlib.resources.abc.Traversable.read_text">
  310. <span class="sig-name descname"><span class="pre">read_text</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">encoding</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.Traversable.read_text" title="Link to this definition">¶</a></dt>
  311. <dd><p>Read contents of self as text.</p>
  312. </dd></dl>
  313. </dd></dl>
  314. <dl class="py class">
  315. <dt class="sig sig-object py" id="importlib.resources.abc.TraversableResources">
  316. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">importlib.resources.abc.</span></span><span class="sig-name descname"><span class="pre">TraversableResources</span></span><a class="headerlink" href="#importlib.resources.abc.TraversableResources" title="Link to this definition">¶</a></dt>
  317. <dd><p>An abstract base class for resource readers capable of serving
  318. the <a class="reference internal" href="importlib.resources.html#importlib.resources.files" title="importlib.resources.files"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.resources.files()</span></code></a> interface. Subclasses
  319. <a class="reference internal" href="#importlib.resources.abc.ResourceReader" title="importlib.resources.abc.ResourceReader"><code class="xref py py-class docutils literal notranslate"><span class="pre">ResourceReader</span></code></a> and provides
  320. concrete implementations of the <code class="xref py py-class docutils literal notranslate"><span class="pre">ResourceReader</span></code>’s
  321. abstract methods. Therefore, any loader supplying
  322. <code class="xref py py-class docutils literal notranslate"><span class="pre">TraversableResources</span></code> also supplies <code class="xref py py-class docutils literal notranslate"><span class="pre">ResourceReader</span></code>.</p>
  323. <p>Loaders that wish to support resource reading are expected to
  324. implement this interface.</p>
  325. <dl class="py method">
  326. <dt class="sig sig-object py" id="importlib.resources.abc.TraversableResources.files">
  327. <em class="property"><span class="pre">abstractmethod</span> </em><span class="sig-name descname"><span class="pre">files</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#importlib.resources.abc.TraversableResources.files" title="Link to this definition">¶</a></dt>
  328. <dd><p>Returns a <a class="reference internal" href="#importlib.resources.abc.Traversable" title="importlib.resources.abc.Traversable"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.resources.abc.Traversable</span></code></a> object for the loaded
  329. package.</p>
  330. </dd></dl>
  331. </dd></dl>
  332. </section>
  333. <div class="clearer"></div>
  334. </div>
  335. </div>
  336. </div>
  337. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  338. <div class="sphinxsidebarwrapper">
  339. <div>
  340. <h4>Previous topic</h4>
  341. <p class="topless"><a href="importlib.resources.html"
  342. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.resources</span></code> – Package resource reading, opening and access</a></p>
  343. </div>
  344. <div>
  345. <h4>Next topic</h4>
  346. <p class="topless"><a href="importlib.metadata.html"
  347. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.metadata</span></code> – Accessing package metadata</a></p>
  348. </div>
  349. <div role="note" aria-label="source link">
  350. <h3>This Page</h3>
  351. <ul class="this-page-menu">
  352. <li><a href="../bugs.html">Report a Bug</a></li>
  353. <li>
  354. <a href="https://github.com/python/cpython/blob/main/Doc/library/importlib.resources.abc.rst"
  355. rel="nofollow">Show Source
  356. </a>
  357. </li>
  358. </ul>
  359. </div>
  360. </div>
  361. <div id="sidebarbutton" title="Collapse sidebar">
  362. <span>«</span>
  363. </div>
  364. </div>
  365. <div class="clearer"></div>
  366. </div>
  367. <div class="related" role="navigation" aria-label="related navigation">
  368. <h3>Navigation</h3>
  369. <ul>
  370. <li class="right" style="margin-right: 10px">
  371. <a href="../genindex.html" title="General Index"
  372. >index</a></li>
  373. <li class="right" >
  374. <a href="../py-modindex.html" title="Python Module Index"
  375. >modules</a> |</li>
  376. <li class="right" >
  377. <a href="importlib.metadata.html" title="importlib.metadata – Accessing package metadata"
  378. >next</a> |</li>
  379. <li class="right" >
  380. <a href="importlib.resources.html" title="importlib.resources – Package resource reading, opening and access"
  381. >previous</a> |</li>
  382. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  383. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  384. <li class="switchers">
  385. <div class="language_switcher_placeholder"></div>
  386. <div class="version_switcher_placeholder"></div>
  387. </li>
  388. <li>
  389. </li>
  390. <li id="cpython-language-and-version">
  391. <a href="../index.html">3.12.3 Documentation</a> &#187;
  392. </li>
  393. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  394. <li class="nav-item nav-item-2"><a href="modules.html" >Importing Modules</a> &#187;</li>
  395. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.resources.abc</span></code> – Abstract base classes for resources</a></li>
  396. <li class="right">
  397. <div class="inline-search" role="search">
  398. <form class="inline-search" action="../search.html" method="get">
  399. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  400. <input type="submit" value="Go" />
  401. </form>
  402. </div>
  403. |
  404. </li>
  405. <li class="right">
  406. <label class="theme-selector-label">
  407. Theme
  408. <select class="theme-selector" oninput="activateTheme(this.value)">
  409. <option value="auto" selected>Auto</option>
  410. <option value="light">Light</option>
  411. <option value="dark">Dark</option>
  412. </select>
  413. </label> |</li>
  414. </ul>
  415. </div>
  416. <div class="footer">
  417. &copy;
  418. <a href="../copyright.html">
  419. Copyright
  420. </a>
  421. 2001-2024, Python Software Foundation.
  422. <br />
  423. This page is licensed under the Python Software Foundation License Version 2.
  424. <br />
  425. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  426. <br />
  427. See <a href="/license.html">History and License</a> for more information.<br />
  428. <br />
  429. The Python Software Foundation is a non-profit corporation.
  430. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  431. <br />
  432. <br />
  433. Last updated on Apr 09, 2024 (13:47 UTC).
  434. <a href="/bugs.html">Found a bug</a>?
  435. <br />
  436. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  437. </div>
  438. </body>
  439. </html>
上海开阖软件有限公司 沪ICP备12045867号-1