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

📄 92.html

📁 国外python经典教材,python爱好者的首选
💻 HTML
字号:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Robots" content="INDEX,NOFOLLOW">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<TITLE>Safari | Python Essential Reference, Second Edition -&gt; Files</TITLE>
<LINK REL="stylesheet" HREF="oreillyi/oreillyM.css">
</HEAD>
<BODY bgcolor="white" text="black" link="#990000" vlink="#990000" alink="#990000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="100%" cellpadding=5 cellspacing=0 border=0 class="navtopbg"><tr><td><font size="1"><p class="navtitle"><a href="2.html" class="navtitle">Linux/Unix</a> &gt; <a href="0735710910.html" class="navtitle">Python Essential Reference, Second Edition</a> &gt; <a href="89.html" class="navtitle">9. Input and Output</a> &gt; <span class="nonavtitle">Files</span></p></font></td><td align="right" valign="top" nowrap><font size="1"><a href="main.asp?list" class="safnavoff">See All Titles</a></font></td></tr></table>
<TABLE width=100% bgcolor=white border=0 cellspacing=0 cellpadding=5><TR><TD>
<TABLE border=0 width="100%" cellspacing=0 cellpadding=0><TR><td align=left width="15%" class="headingsubbarbg"><a href="91.html" title="Reading Options and Environment Variables"><font size="1">&lt;&nbsp;BACK</font></a></td><td align=center width="70%" class="headingsubbarbg"><font size="1"><a href="popanote.asp?pubui=oreilly&bookname=0735710910&snode=92" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="92.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="93.html" title="Standard Input, Output, and Error"><font size="1">CONTINUE&nbsp;&gt;</font></a></td></TR></TABLE>
<a href="5%2F28%2F2002+9%3A02%3A47+PM.html" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><font color=white size=1>155117184014003188065099048180054212144238241179195140058238111161105084124007242194071231</font><a href="read3.asp?bookname=0735710910&snode=92&now=5%2F28%2F2002+9%3A02%3A47+PM" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><br>
<FONT>
<h3>Files</h3>
<p>The built-in function <tT CLAss="monofont">open(</tt><I><TT Class="monofont">name</TT></I>
<Tt class="monofont"> [,</tt><i><tt class="monofont">mode</tt></i>
<tT clAss="monofont">])</tT> opens and creates files, as shown here:</p>

<pre>

f = open('foo')        # Opens 'foo' for reading 
f = open('foo','w')    # Open for writing </Pre>

<p>The file mode is <TT CLass="monofont">'r'</tT> for read, <TT Class="monofont">'w'</TT> for write, or <TT clasS="monofont">'a'</TT> for append. The mode character can be followed by <Tt class="monofont">'b'</tt> for binary data, such as <tt class="monofont">'rb'</tt> or <tt cLasS="monofont">'wb'</tt>. This is optional on UNIX, but required on Windows, and should be included if you抮e concerned about portability. In addition, a file can be opened for updates by supplying a plus (<tT clasS="monofont">+</tt>) character, such as <tT CLAss="monofont">'r+'</tt> or <TT CLass="monofont">'w+'</tT>. When a file is opened for update, you can perform both input and output, as long as all output operations flush their data before any subsequent input operations. If a file is opened using <TT Class="monofont">'w+'</TT> mode, its length is first truncated to zero.</P>

<P><tt class="monofont">open()</tt> returns a file object that supports the methods shown in <a href="92#2.html">Table 9.1</a>.</p>

<a namE="2"></a><p><TablE bordEr="1" ceLLSPacinG="0" CELlpadDING="1" widtH="100%">
<CAPtion><h5>Table

⌨️ 快捷键说明

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