亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? node17.html

?? Pythone Library reference. it is ok and simple.
?? HTML
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0062)http://www.honors.montana.edu/~jjc/easytut/easytut/node17.html -->
<!--Converted with LaTeX2HTML 99.2beta6 (1.42)original version by:  Nikos Drakos, CBLU, University of Leeds* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan* with significant contributions from:  Jens Lippmann, Marek Rouchal, Martin Wilck and others --><HTML><HEAD><TITLE>File IO</TITLE>
<META content="File IO" name=description>
<META content=easytut name=keywords>
<META content=document name=resource-type>
<META content=global name=distribution>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META content="MSHTML 5.00.2614.3500" name=GENERATOR>
<META content=text/css http-equiv=Content-Style-Type><LINK 
href="node17_files/easytut.css" rel=STYLESHEET><LINK href="node18.html" 
rel=next><LINK href="node16.html" rel=previous><LINK href="easytut.html" 
rel=up><LINK href="node18.html" rel=next></HEAD>
<BODY><!--Navigation Panel--><A 
href="http://www.honors.montana.edu/~jjc/easytut/easytut/node18.html" 
name=tex2html368><IMG align=bottom alt=next border=0 height=24 
src="node17_files/next.png" width=37></A> <A 
href="http://www.honors.montana.edu/~jjc/easytut/easytut/easytut.html" 
name=tex2html364><IMG align=bottom alt=up border=0 height=24 
src="node17_files/up.png" width=26></A> <A 
href="http://www.honors.montana.edu/~jjc/easytut/easytut/node16.html" 
name=tex2html358><IMG align=bottom alt=previous border=0 height=24 
src="node17_files/prev.png" width=63></A> <A 
href="http://www.honors.montana.edu/~jjc/easytut/easytut/node2.html" 
name=tex2html366><IMG align=bottom alt=contents border=0 height=24 
src="node17_files/contents.png" width=65></A> <BR><B>Next:</B> <A 
href="http://www.honors.montana.edu/~jjc/easytut/easytut/node18.html" 
name=tex2html369>Dealing with the imperfect</A> <B>Up:</B> <A 
href="http://www.honors.montana.edu/~jjc/easytut/easytut/easytut.html" 
name=tex2html365>Non-Programmers Tutorial For Python</A> <B>Previous:</B> <A 
href="http://www.honors.montana.edu/~jjc/easytut/easytut/node16.html" 
name=tex2html359>Revenge of the Strings</A> &nbsp; <B><A 
href="http://www.honors.montana.edu/~jjc/easytut/easytut/node2.html" 
name=tex2html367>Contents</A></B> <BR><BR><!--End of Navigation Panel--><!--Table of Child-Links--><A 
name=CHILD_LINKS><STRONG>Subsections</STRONG></A> 
<UL>
  <LI><A 
  href="http://www.honors.montana.edu/~jjc/easytut/easytut/node17.html#SECTION001710000000000000000" 
  name=tex2html370>Exercises</A> </LI></UL><!--End of Table of Child-Links-->
<HR>

<H1><A name=SECTION001700000000000000000>File IO</A> </H1>Here is a simple 
example of file IO: <PRE>#Write a file
out_file = open("test.txt","w")
out_file.write("This Text is going to out file\nLook at it and see\n")
out_file.close()

#Read a file
in_file = open("test.txt","r")
text = in_file.read()
in_file.close()

print text,
</PRE>The output and the contents of the file test.txt are: <PRE>This Text is going to out file
Look at it and see
</PRE>Notice that it wrote a file called test.txt in the directory that you ran 
the program from. The <CODE>\n</CODE> in the string tells Python to put a 
<B>n</B>ewline where it is. 
<P>A overview of file IO is: 
<OL>
  <LI>Get a file object with the <CODE>open</CODE> function. 
  <LI>Read or write to the file object (depending on how it was opened) 
  <LI>Close it </LI></OL>
<P>The first step is to get a file object. The way to do this is to use the 
<CODE>open</CODE> function. The format is <CODE>file_object = 
open(filename,mode)</CODE> where <CODE>file_object</CODE> is the variable to put 
the file object, <CODE>filename</CODE> is a string with the filename, and 
<CODE>mode</CODE> is either <CODE>"r"</CODE> to <B>r</B>ead a file or 
<CODE>"w"</CODE> to <B>w</B>rite a file. Next the file objects functions can be 
called. The two most common functions are <CODE>read</CODE> and 
<CODE>write</CODE>. The <CODE>write</CODE> function adds a string to the end of 
the file. The <CODE>read</CODE> function reads the next thing in the file and 
returns it as a string. If no argument is given it will return the whole file 
(as done in the example). 
<P>Now here is a new version of the phone numbers program that we made earlier: <PRE>import string

true = 1
false = 0

def print_numbers(numbers):
    print "Telephone Numbers:"
    for x in numbers.keys():
        print "Name: ",x," \tNumber: ",numbers[x]
    print

def add_number(numbers,name,number):
    numbers[name] = number

def lookup_number(numbers,name):
    if numbers.has_key(name):
        return "The number is "+numbers[name]
    else:
        return name+" was not found"

def remove_number(numbers,name):
    if numbers.has_key(name):
        del numbers[name]
    else:
        print name," was not found"


def load_numbers(numbers,filename):
    in_file = open(filename,"r")
    while true:
        in_line = in_file.readline()
        if in_line == "":
            break
        in_line = in_line[:-1]
        [name,number] = string.split(in_line,",")
        numbers[name] = number
    in_file.close()

def save_numbers(numbers,filename):
    out_file = open(filename,"w")
    for x in numbers.keys():
        out_file.write(x+","+numbers[x]+"\n")
    out_file.close()
    

def print_menu():
    print '1. Print Phone Numbers'
    print '2. Add a Phone Number'
    print '3. Remove a Phone Number'
    print '4. Lookup a Phone Number'
    print '5. Load numbers'
    print '6. Save numbers'
    print '7. Quit'
    print
</PRE><PRE>phone_list = {}
menu_choice = 0
print_menu()
while menu_choice != 7:
    menu_choice = input("Type in a number (1-7):")
    if menu_choice == 1:
        print_numbers(phone_list)
    elif menu_choice == 2:
        print "Add Name and Number"
        name = raw_input("Name:")
        phone = raw_input("Number:")
        add_number(phone_list,name,phone)
    elif menu_choice == 3:
        print "Remove Name and Number"
        name = raw_input("Name:")
        remove_number(phone_list,name)
    elif menu_choice == 4:
        print "Lookup Number"
	name = raw_input("Name:")
        print lookup_number(phone_list,name)
    elif menu_choice == 5:
        filename = raw_input("Filename to load:")
        load_numbers(phone_list,filename)
    elif menu_choice == 6:
        filename = raw_input("Filename to save:")
        save_numbers(phone_list,filename)
    elif menu_choice == 7:
        pass
    else:
        print_menu()
print "Goodbye"
</PRE>Notice that it now includes saving and loading files. Here is some output 
of my running it twice: <PRE>&gt; python tele2.py
1. Print Phone Numbers
2. Add a Phone Number
3. Remove a Phone Number
4. Lookup a Phone Number
5. Load numbers
6. Save numbers
7. Quit

Type in a number (1-7):2
Add Name and Number
Name:Jill
Number:1234
Type in a number (1-7):2
Add Name and Number
Name:Fred 
Number:4321
Type in a number (1-7):1
Telephone Numbers:
Name:  Jill     Number:  1234
Name:  Fred     Number:  4321

Type in a number (1-7):6
Filename to save:numbers.txt
Type in a number (1-7):7
Goodbye
</PRE><PRE>&gt; python tele2.py
1. Print Phone Numbers
2. Add a Phone Number
3. Remove a Phone Number
4. Lookup a Phone Number
5. Load numbers
6. Save numbers
7. Quit

Type in a number (1-7):5
Filename to load:numbers.txt
Type in a number (1-7):1
Telephone Numbers:
Name:  Jill     Number:  1234
Name:  Fred     Number:  4321

Type in a number (1-7):7
Goodbye
</PRE>
<P>The new portions of this program are: <PRE>def load_numbers(numbers,filename):
    in_file = open(filename,"r")
    while 1:
        in_line = in_file.readline()
        if len(in_line) == 0:
            break
        in_line = in_line[:-1]
        [name,number] = string.split(in_line,",")
        numbers[name] = number
    in_file.close()
</PRE><PRE>def save_numbers(numbers,filename):
    out_file = open(filename,"w")
    for x in numbers.keys():
        out_file.write(x+","+numbers[x]+"\n")
    out_file.close()
</PRE>
<P>First we will look at the save portion of the program. First it creates a 
file object with the command <CODE>open(filename,"w")</CODE>. Next it goes 
through and creates a line for each of the phone numbers with the command 
<CODE>out_file.write(x+","+numbers[x]+"\n")</CODE>. This writes out a line that 
contains the name, a comma, the number and follows it by a newline. 
<P>The loading portion is a little more complicated. It starts by getting a file 
object. Then it uses a <CODE>while 1:</CODE> loop to keep looping until a 
<CODE>break</CODE> statement is encountered. Next it gets a line with the line 
<CODE>in_line = in_file.readline()</CODE>. The <CODE>getline</CODE> function 
will return a empty string (len(string) == 0) when the end of the file is 
reached. The <CODE>if</CODE> statement checks for this and <CODE>break</CODE>s 
out of the <CODE>while</CODE> loop when that happens. Of course if the 
<CODE>readline</CODE> function did not return the newline at the end of the line 
there would be no way to tell if an empty string was an empty line or the end of 
the file so the newline is left in what <CODE>getline</CODE> returns. Hence we 
have to get rid of the newline. The line <CODE>in_line = in_line[:-1]</CODE> 
does this for us by dropping the last character. Next the line 
<CODE>[name,number] = string.split(in_line,",")</CODE> splits the line at the 
comma into a name and a number. This is then added to the <CODE>numbers</CODE> 
dictionary. 
<P>
<H1><A name=SECTION001710000000000000000>Exercises</A> </H1>
<P>Now modify the grades program from section <A 
href="http://www.honors.montana.edu/~jjc/easytut/easytut/node13.html#firstgrades">11</A> 
so that is uses file IO to keep a record of the students. 
<P>
<HR>
<!--Navigation Panel--><A 
href="http://www.honors.montana.edu/~jjc/easytut/easytut/node18.html" 
name=tex2html368><IMG align=bottom alt=next border=0 height=24 
src="node17_files/next.png" width=37></A> <A 
href="http://www.honors.montana.edu/~jjc/easytut/easytut/easytut.html" 
name=tex2html364><IMG align=bottom alt=up border=0 height=24 
src="node17_files/up.png" width=26></A> <A 
href="http://www.honors.montana.edu/~jjc/easytut/easytut/node16.html" 
name=tex2html358><IMG align=bottom alt=previous border=0 height=24 
src="node17_files/prev.png" width=63></A> <A 
href="http://www.honors.montana.edu/~jjc/easytut/easytut/node2.html" 
name=tex2html366><IMG align=bottom alt=contents border=0 height=24 
src="node17_files/contents.png" width=65></A> <BR><B>Next:</B> <A 
href="http://www.honors.montana.edu/~jjc/easytut/easytut/node18.html" 
name=tex2html369>Dealing with the imperfect</A> <B>Up:</B> <A 
href="http://www.honors.montana.edu/~jjc/easytut/easytut/easytut.html" 
name=tex2html365>Non-Programmers Tutorial For Python</A> <B>Previous:</B> <A 
href="http://www.honors.montana.edu/~jjc/easytut/easytut/node16.html" 
name=tex2html359>Revenge of the Strings</A> &nbsp; <B><A 
href="http://www.honors.montana.edu/~jjc/easytut/easytut/node2.html" 
name=tex2html367>Contents</A></B> <!--End of Navigation Panel-->
<ADDRESS>Josh Cogliati <A 
href="mailto:jjc@honors.montana.edu">jjc@honors.montana.edu</A> 
</ADDRESS></BODY></HTML>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产一区二区三区在线观看免费| 国产精品伦理在线| 日本亚洲三级在线| 日韩欧美自拍偷拍| 久久99精品久久久久久| 久久精品人人爽人人爽| 国产 日韩 欧美大片| 中文字幕亚洲不卡| 91啪亚洲精品| 日韩电影一区二区三区| 日韩欧美成人激情| 国产不卡免费视频| 综合中文字幕亚洲| 欧美日韩日日摸| 国产一区二区伦理片| 亚洲丝袜制服诱惑| 欧美一区二区三区视频免费播放| 精品亚洲aⅴ乱码一区二区三区| 欧美韩国日本一区| 欧美日韩免费一区二区三区视频| 久久不见久久见中文字幕免费| 国产无人区一区二区三区| 一本一道久久a久久精品 | 91色九色蝌蚪| 亚洲小说欧美激情另类| 欧美成人三级电影在线| a级精品国产片在线观看| 亚洲激情校园春色| 久久亚洲一区二区三区明星换脸 | 欧美日韩国产乱码电影| 国产精品一区专区| 一级特黄大欧美久久久| 久久久久久久网| 欧美三片在线视频观看| 国产精品自拍三区| 日韩成人免费电影| 亚洲天堂精品视频| 26uuu色噜噜精品一区二区| 91丨九色丨黑人外教| 久久精品999| 亚洲精品视频在线观看免费| 欧美va在线播放| 欧美视频中文字幕| 成人18精品视频| 激情av综合网| 午夜精品爽啪视频| 亚洲人123区| 久久夜色精品一区| 久久综合丝袜日本网| 精品视频在线免费看| 福利视频网站一区二区三区| 蜜桃传媒麻豆第一区在线观看| 亚洲免费资源在线播放| 国产亚洲欧美日韩俺去了| 91精品久久久久久久91蜜桃| 91福利社在线观看| 99久久精品国产导航| 国产精品综合二区| 美美哒免费高清在线观看视频一区二区| 亚洲女性喷水在线观看一区| 亚洲国产精品黑人久久久| 欧美精品一区二| 欧美videofree性高清杂交| 91精品蜜臀在线一区尤物| 欧美三区在线观看| 在线观看区一区二| 一本一道久久a久久精品综合蜜臀 一本一道综合狠狠老 | 老司机一区二区| 亚洲成人av电影| 亚洲综合色自拍一区| 亚洲精品五月天| 亚洲免费高清视频在线| 成人免费在线观看入口| 日本一区二区不卡视频| 中文字幕欧美三区| 中文字幕精品一区二区精品绿巨人 | 午夜成人在线视频| 亚洲观看高清完整版在线观看 | 欧美高清在线一区二区| 久久久噜噜噜久久中文字幕色伊伊| 欧美日韩不卡一区| 欧美人狂配大交3d怪物一区| 91精品国产综合久久久蜜臀图片| 欧美人动与zoxxxx乱| 欧美一区午夜精品| 日韩色在线观看| 精品不卡在线视频| 国产亚洲制服色| 国产精品日韩成人| 亚洲欧美视频一区| 婷婷亚洲久悠悠色悠在线播放| 日韩中文字幕麻豆| 精品一二三四区| 白白色亚洲国产精品| 91一区二区在线观看| 欧美日韩免费不卡视频一区二区三区| 这里只有精品电影| 欧美刺激午夜性久久久久久久| 26uuu国产电影一区二区| 久久久精品免费观看| 国产精品美女久久久久aⅴ国产馆 国产精品美女久久久久av爽李琼 国产精品美女久久久久高潮 | 国产91丝袜在线播放0| 99久久精品一区| 欧美日韩美女一区二区| 欧美成人精品福利| 日本成人在线电影网| 国产一区二区三区免费| 一本久道久久综合中文字幕| 欧美一区二区三区视频在线| 国产欧美精品一区| 亚洲激情第一区| 精品中文av资源站在线观看| 不卡av在线免费观看| 欧美精选午夜久久久乱码6080| 久久久亚洲午夜电影| 亚洲一区二区三区免费视频| 美国欧美日韩国产在线播放 | 99精品欧美一区| 欧美日韩夫妻久久| 国产精品视频第一区| 午夜精品久久久久久| 国产91精品久久久久久久网曝门| 欧美性大战久久久久久久| 欧美精品一区二区三区一线天视频| 一区二区中文字幕在线| 久久99精品视频| 欧洲一区二区三区免费视频| 26uuu精品一区二区在线观看| 一个色综合网站| 国产精品69久久久久水密桃 | 26uuu色噜噜精品一区二区| 一区二区三区毛片| 国产精品亚洲一区二区三区妖精| 欧美日韩成人在线| 成人欧美一区二区三区小说| 精品一区二区三区香蕉蜜桃| 欧美无砖专区一中文字| 中文无字幕一区二区三区| 久久国产精品一区二区| 欧美图片一区二区三区| 中文字幕一区二区三区色视频 | 亚洲国产精品高清| 免费成人在线观看视频| 欧美伊人久久大香线蕉综合69| 欧美国产精品久久| 久草在线在线精品观看| 欧美日本在线播放| 夜夜嗨av一区二区三区四季av| 国产成人在线观看| 精品国产一区二区三区久久影院 | 久久 天天综合| 91精品久久久久久久久99蜜臂| 亚洲国产欧美在线人成| 成人国产一区二区三区精品| 国产欧美一区二区三区鸳鸯浴 | 亚洲一区二区三区四区中文字幕| 国产精品一区不卡| 久久伊人蜜桃av一区二区| 美国十次了思思久久精品导航| 欧美丰满少妇xxxbbb| 调教+趴+乳夹+国产+精品| 在线观看视频一区二区| 一区二区三区在线视频观看 | 91麻豆精品国产91久久久久久久久 | 亚洲成人自拍一区| 91福利在线观看| 亚洲综合在线五月| 欧美综合视频在线观看| 亚洲一区二区精品久久av| 欧美性受xxxx| 亚洲电影第三页| 欧美精品久久久久久久久老牛影院| 午夜精品123| 欧美一级理论片| 久久国产视频网| 2欧美一区二区三区在线观看视频 337p粉嫩大胆噜噜噜噜噜91av | 2022国产精品视频| 精品一区二区在线看| 久久一区二区三区四区| 粉嫩久久99精品久久久久久夜| 国产精品无圣光一区二区| 91蜜桃免费观看视频| 夜夜揉揉日日人人青青一国产精品| 在线亚洲+欧美+日本专区| 亚洲国产你懂的| 日韩一二三四区| 国产做a爰片久久毛片| 亚洲国产精品国自产拍av| 一本大道久久a久久综合| 午夜激情综合网| 精品少妇一区二区三区视频免付费| 国产乱人伦精品一区二区在线观看| 国产亚洲成年网址在线观看| 99re视频精品| 日日夜夜精品视频免费| 精品国产乱码久久久久久1区2区 | 久久这里只有精品视频网| 91在线视频免费91| 亚洲高清免费一级二级三级| www精品美女久久久tv|