⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 configparser-objects.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>5.7.1 ConfigParser Objects </title>
<META NAME="description" CONTENT="5.7.1 ConfigParser Objects ">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="previous" href="module-ConfigParser.html" tppabs="http://www.python.org/doc/current/lib/module-ConfigParser.html">
<LINK REL="up" href="module-ConfigParser.html" tppabs="http://www.python.org/doc/current/lib/module-ConfigParser.html">
<LINK REL="next" href="module-fileinput.html" tppabs="http://www.python.org/doc/current/lib/module-fileinput.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-ConfigParser.html" tppabs="http://www.python.org/doc/current/lib/module-ConfigParser.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="module-ConfigParser.html" tppabs="http://www.python.org/doc/current/lib/module-ConfigParser.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="module-fileinput.html" tppabs="http://www.python.org/doc/current/lib/module-fileinput.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-ConfigParser.html" tppabs="http://www.python.org/doc/current/lib/module-ConfigParser.html">5.7 ConfigParser  </A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-ConfigParser.html" tppabs="http://www.python.org/doc/current/lib/module-ConfigParser.html">5.7 ConfigParser  </A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-fileinput.html" tppabs="http://www.python.org/doc/current/lib/module-fileinput.html">5.8 fileinput  </A>
<br><hr></DIV>
<!--End of Navigation Panel-->

<H2>
<BR>
5.7.1 ConfigParser Objects 
</H2>

<P>
<tt class="class">ConfigParser</tt> instances have the following methods:

<P>
<dl><dt><b><a name='l2h-791'><tt class='method'>defaults</tt></a></b> ()
<dd>
Return a dictionary containing the instance-wide defaults.
</dl>

<P>
<dl><dt><b><a name='l2h-792'><tt class='method'>sections</tt></a></b> ()
<dd>
Return a list of the sections available; <code>DEFAULT</code> is not
included in the list.
</dl>

<P>
<dl><dt><b><a name='l2h-793'><tt class='method'>add_section</tt></a></b> (<var>section</var>)
<dd>
Add a section named <var>section</var> to the instance.  If a section by
the given name already exists, <tt class="exception">DuplicateSectionError</tt> is
raised.
</dl>

<P>
<dl><dt><b><a name='l2h-794'><tt class='method'>has_section</tt></a></b> (<var>section</var>)
<dd>
Indicates whether the named section is present in the
configuration. The <code>DEFAULT</code> section is not acknowledged.
</dl>

<P>
<dl><dt><b><a name='l2h-795'><tt class='method'>options</tt></a></b> (<var>section</var>)
<dd>
Returns a list of options available in the specified <var>section</var>.
</dl>

<P>
<dl><dt><b><a name='l2h-796'><tt class='method'>has_option</tt></a></b> (<var>section, option</var>)
<dd>
If the given section exists, and contains the given option. return 1;
otherwise return 0. (New in 1.6)
</dl>

<P>
<dl><dt><b><a name='l2h-797'><tt class='method'>read</tt></a></b> (<var>filenames</var>)
<dd>
Read and parse a list of filenames.  If <var>filenames</var> is a string or
Unicode string, it is treated as a single filename.
</dl>

<P>
<dl><dt><b><a name='l2h-798'><tt class='method'>readfp</tt></a></b> (<var>fp</var><big>[</big><var>, filename</var><big>]</big>)
<dd>
Read and parse configuration data from the file or file-like object in
<var>fp</var> (only the <tt class="method">readline()</tt> method is used).  If
<var>filename</var> is omitted and <var>fp</var> has a <tt class="member">name</tt> attribute,
that is used for <var>filename</var>; the default is "<tt class="samp">&lt;???&gt;</tt>".
</dl>

<P>
<dl><dt><b><a name='l2h-799'><tt class='method'>get</tt></a></b> (<var>section, option</var><big>[</big><var>, raw</var><big>[</big><var>, vars</var><big>]</big><big>]</big>)
<dd>
Get an <var>option</var> value for the provided <var>section</var>.  All the
"<tt class="character">%</tt>" interpolations are expanded in the return values, based on
the defaults passed into the constructor, as well as the options
<var>vars</var> provided, unless the <var>raw</var> argument is true.
</dl>

<P>
<dl><dt><b><a name='l2h-800'><tt class='method'>getint</tt></a></b> (<var>section, option</var>)
<dd>
A convenience method which coerces the <var>option</var> in the specified
<var>section</var> to an integer.
</dl>

<P>
<dl><dt><b><a name='l2h-801'><tt class='method'>getfloat</tt></a></b> (<var>section, option</var>)
<dd>
A convenience method which coerces the <var>option</var> in the specified
<var>section</var> to a floating point number.
</dl>

<P>
<dl><dt><b><a name='l2h-802'><tt class='method'>getboolean</tt></a></b> (<var>section, option</var>)
<dd>
A convenience method which coerces the <var>option</var> in the specified
<var>section</var> to a boolean value.  Note that the only accepted values
for the option are "<tt class="samp">0</tt>" and "<tt class="samp">1</tt>", any others will raise
<tt class="exception">ValueError</tt>.
</dl>

<P>
<dl><dt><b><a name='l2h-803'><tt class='method'>set</tt></a></b> (<var>section, option, value</var>)
<dd>
If the given section exists, set the given option to the specified value;
otherwise raise <tt class="exception">NoSectionError</tt>. (New in 1.6)
</dl>

<P>
<dl><dt><b><a name='l2h-804'><tt class='method'>write</tt></a></b> (<var>fileobject</var>)
<dd>
Write a representation of the configuration to the specified file
object.  This representation can be parsed by a future <tt class="method">read()</tt>
call. (New in 1.6)
</dl>

<P>
<dl><dt><b><a name='l2h-805'><tt class='method'>remove_option</tt></a></b> (<var>section, option</var>)
<dd>
Remove the specified <var>option</var> from the specified <var>section</var>.
If the section does not exist, raise <tt class="exception">NoSectionError</tt>. 
If the option existed to be removed, return 1; otherwise return 0.
(New in 1.6)
</dl>

<P>
<dl><dt><b><a name='l2h-806'><tt class='method'>remove_section</tt></a></b> (<var>section</var>)
<dd>
Remove the specified <var>section</var> from the configuration.
If the section in fact existed, return 1.  Otherwise return 0.
</dl>

<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-ConfigParser.html" tppabs="http://www.python.org/doc/current/lib/module-ConfigParser.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="module-ConfigParser.html" tppabs="http://www.python.org/doc/current/lib/module-ConfigParser.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="module-fileinput.html" tppabs="http://www.python.org/doc/current/lib/module-fileinput.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-ConfigParser.html" tppabs="http://www.python.org/doc/current/lib/module-ConfigParser.html">5.7 ConfigParser  </A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-ConfigParser.html" tppabs="http://www.python.org/doc/current/lib/module-ConfigParser.html">5.7 ConfigParser  </A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-fileinput.html" tppabs="http://www.python.org/doc/current/lib/module-fileinput.html">5.8 fileinput  </A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -