5.18-笨办法学python-习题17(文件拷贝)
from sys import argv
from os.path import exists
#又import了一个命令exists,这个命令将文件名字符串作为参数,如果文件存在返回TRUE,否则返回FALSE script,from_file,to_file=argv
#传参,不过没有管exists哎 print("copying from %s to %s "%(from_file,to_file))
#打印copying from "from_file"to "to_file" get=open(from_file)
#打开“from_file”并传递给对象get
indata=get.read()
#读文件然后传给indata print("the input file is %d bytes long"%len(indata))
#打印the input file is “一个数字”bytes long
print("does the output file exist?%r"%exists(to_file))
#打印does the output file exist?+true/false(有就是true)
print("ready,hit RETURN to continue ,CTRL-C to abort.")
#打印ready,hit RETURN to continue ,CTRL-C to abort.
input('<')
#一个提示符
output=open(to_file,'w')
#以只写的模式打开“to_file”
output.write(indata)
#把indata里的内容(from_file)写进output(to_file) print("alright,all done")
#打印alright,all done
output.close()
#关闭output
get.close()
#关闭get
copied=open("copied.txt")
print(copied.read())
#查看文件咯
5.18-笨办法学python-习题17(文件拷贝)的更多相关文章
- 笨办法学Python - 习题1: A Good First Program
在windows上安装完Python环境后,开始按照<笨办法学Python>书上介绍的章节进行练习. 习题 1: 第一个程序 第一天主要是介绍了Python中输出函数print的使用方法, ...
- 笨办法学Python - 习题11-12: Asking Questions & Prompting People
目录 1.习题 11: 提问 2.习题 12: 提示别人 3.总结 1.习题 11: 提问 学习目标:了解人机交互场景,熟悉raw_input 的用法. 1.在 Python2.x 中 raw_inp ...
- 笨办法学Python - 习题8-10: Printing & Printing, Printing
目录 1.习题 8: 打印,打印 2.习题 9: 打印,打印,打印 3.习题 10: 那是什么? 3.1.转义序列: 4.习题总结: 1.习题 8: 打印,打印 学习目标:继续学习 %r 的格式化输出 ...
- 笨办法学Python - 习题6-7: Strings and Text & More Printing
目录 1.习题 6: 字符串(string) 和文本 2.加分习题: 3.我的答案 4.习题总结 5.习题 7: 更多打印 6.习题总结 1.习题 6: 字符串(string) 和文本 学习目标:了解 ...
- 笨办法学Python - 习题5: More Variables and Printing
1.习题 5: 更多的变量和打印 学习目标:了解用户输入方法,明白pthon2和Python3之间的用户输入的区别.了解格式化字符串(format string)的概念,学会如何创建包含变量内容的字符 ...
- 笨办法学Python - 习题4: Variables and Names
1.习题 4: 变量(variable)和命名 学习目标:了解Python中变量的定义,学习定义简明易记的变量名 变量:变量是存储内存中的值,就是每定义一个变量就会在内存中开辟一个空间.基于变量的类型 ...
- 笨办法学Python - 习题3: Numbers and Math
目录 习题 3: 数字和数学计算 算术运算符 加分习题: 我的答案: 总结: 扩展: Python比较运算符 Python赋值运算符 Python位运算符 Python逻辑运算符 Python成员运算 ...
- 笨办法学python 习题14 优化过 遇到问题的请看
print "\t what's you name?"user_name = raw_input('>') from sys import argvscript, = arg ...
- 笨办法学 Python (Learn Python The Hard Way)
最近在看:笨办法学 Python (Learn Python The Hard Way) Contents: 译者前言 前言:笨办法更简单 习题 0: 准备工作 习题 1: 第一个程序 习题 2: 注 ...
- 笨办法学 Python (第三版)(转载)
笨办法学 Python (第三版) 原文地址:http://blog.sina.com.cn/s/blog_72b8298001019xg8.html 摘自https://learn-python ...
随机推荐
- 在VisualStudio中远程调试IIS站点
如何在本地调试服务器上的站点? 如果要在本地调试服务器上的站点我们需要用到一个远程调试工具msvsmon.exe. 我们可以再VS安装目录中找到它 如:C:\Program Fil ...
- August 19th 2017 Week 33rd Saturday
Live for today and stop stressing out about tomorrow. 为今天而活,不必为明天过分担心. Stop bewailing the past misfo ...
- Economy a Two-Edged Sword for Democrats
2017-05-03 12:05:07 https://www.usnews.com/news/blogs/ken-walshs-washington/2014/10/03/economy-a-two ...
- apt 安装 tomcat
apt 安装 tomcat 直接使用 agt-get 安装 apt-get install tomcat7 # or apt-get install tomcat8 需要一段时间后就安装完成了. 安装 ...
- Redis数据的底层存储原理
redis底层是用什么结构来存储数据的呢? 我们从源码上去理解就会容易的多: redis底层是使用C语言来编写的,我们可以看到它的数据结构声明.一个 dict 有两个dictht,一个dictht ...
- working-with-php-and-beanstalkd
原文出处:http://www.lornajane.net/posts/2014/working-with-php-and-beanstalkd Working with PHP and Beanst ...
- js字符串和数组
sustr substring slice的联系与区别 str.substr(2,5) //从索引2开始截取5个字符,原有字符串str不变 str.substring(2,5) //从索引2开始截 ...
- JNI由浅入深_10_JNI 综合开发
1.使用ndk-build时如果找不到某个类,可以使用下面两种方法解决: 1.1 进入src目录 D:\project3\JNIAndroid\src>set classpath=D:\proj ...
- ASP.NET Core 如何设置发布环境
在ASP.NET Core中自带了一些内置对象,可以读取到当前程序处于什么样的环境当中,比如在ASP.NET Core的Startup类的Configure方法中,我们就会看到这么一段代码: publ ...
- OC字符串处理
接到一个需求, 现有多个品牌的商品,使用字符串保存已选中的品牌,使用','隔开,可以反选. 分析问题可知: 1. 字符串由多个品牌名字组成,由 ',' 隔开. 2.如果选中的品牌不在字符串内,则拼接到 ...