码迷,mamicode.com
首页 > 其他好文 > 详细

ex16.py

时间:2016-11-19 02:52:25      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:universal   argv   exists   reading   变量   rip   bsp   color   app   


 1 # -*- coding:utf-8 -*-
 2 
 3 from sys import argv
 4 
 5 script, filename = argv  #解包变量参数
 6 
 7 print ("we‘re going to erase %r." % filename)
 8 print ("if you don‘t want that, hit CTRL-C(^c).")   #CTRL-C的用法
 9 print ("if you  do want that, hit RETURN.")   # RETURN的用法
10 
11 input ("?")
12 
13 print ("opening the file...")
14 target = open(filename, w)  #‘w‘的意识是‘write’,不可写成大写,否则出现语法错误。本句为定义变量target
15 
16 # 学会该如何打开一个其它文件目录的文件?????
17 #‘r‘       open for reading (default)
18 #‘w‘       open for writing, truncating the file first ‘x‘   create a new file and open it for writing
19 #‘a‘       open for writing, appending to the end of the file if it exists
20 #‘b‘       binary mode 二进制
21 #‘t‘       text mode (default) 文本模式
22 #‘+‘       open a disk file for updating (reading and writing)
23 #‘U‘       universal newline mode (deprecated)   
24 
25 print ("truncating the file .Goodbye!")
26 #target.truncate()     #truncate()的意思是清空文件
27 
28 print ("Now I‘m going to ask you for three lines.")
29 
30 line1 = input ("line 1: ")
31 line2 = input ("line 2: ")
32 line3 = input ("line 3: ")
33 
34 print ("I‘m going to write these to the file.")
35 
36 target.write(line1) #write()的意思是写入文件
37 target.write("\n")
38 target.write(line2)
39 target.write("\n")
40 target.write(line3)
41 target.write("\n")
42 
43 print ("And finally,we close it.")
44 target.close() # 关闭文件和保存的意思

 

 

 

ex16.py

标签:universal   argv   exists   reading   变量   rip   bsp   color   app   

原文地址:http://www.cnblogs.com/jiangzhipeng/p/6079686.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!