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(文件拷贝)的更多相关文章

  1. 笨办法学Python - 习题1: A Good First Program

    在windows上安装完Python环境后,开始按照<笨办法学Python>书上介绍的章节进行练习. 习题 1: 第一个程序 第一天主要是介绍了Python中输出函数print的使用方法, ...

  2. 笨办法学Python - 习题11-12: Asking Questions & Prompting People

    目录 1.习题 11: 提问 2.习题 12: 提示别人 3.总结 1.习题 11: 提问 学习目标:了解人机交互场景,熟悉raw_input 的用法. 1.在 Python2.x 中 raw_inp ...

  3. 笨办法学Python - 习题8-10: Printing & Printing, Printing

    目录 1.习题 8: 打印,打印 2.习题 9: 打印,打印,打印 3.习题 10: 那是什么? 3.1.转义序列: 4.习题总结: 1.习题 8: 打印,打印 学习目标:继续学习 %r 的格式化输出 ...

  4. 笨办法学Python - 习题6-7: Strings and Text & More Printing

    目录 1.习题 6: 字符串(string) 和文本 2.加分习题: 3.我的答案 4.习题总结 5.习题 7: 更多打印 6.习题总结 1.习题 6: 字符串(string) 和文本 学习目标:了解 ...

  5. 笨办法学Python - 习题5: More Variables and Printing

    1.习题 5: 更多的变量和打印 学习目标:了解用户输入方法,明白pthon2和Python3之间的用户输入的区别.了解格式化字符串(format string)的概念,学会如何创建包含变量内容的字符 ...

  6. 笨办法学Python - 习题4: Variables and Names

    1.习题 4: 变量(variable)和命名 学习目标:了解Python中变量的定义,学习定义简明易记的变量名 变量:变量是存储内存中的值,就是每定义一个变量就会在内存中开辟一个空间.基于变量的类型 ...

  7. 笨办法学Python - 习题3: Numbers and Math

    目录 习题 3: 数字和数学计算 算术运算符 加分习题: 我的答案: 总结: 扩展: Python比较运算符 Python赋值运算符 Python位运算符 Python逻辑运算符 Python成员运算 ...

  8. 笨办法学python 习题14 优化过 遇到问题的请看

    print "\t what's you name?"user_name = raw_input('>') from sys import argvscript, = arg ...

  9. 笨办法学 Python (Learn Python The Hard Way)

    最近在看:笨办法学 Python (Learn Python The Hard Way) Contents: 译者前言 前言:笨办法更简单 习题 0: 准备工作 习题 1: 第一个程序 习题 2: 注 ...

  10. 笨办法学 Python (第三版)(转载)

    笨办法学 Python (第三版) 原文地址:http://blog.sina.com.cn/s/blog_72b8298001019xg8.html   摘自https://learn-python ...

随机推荐

  1. 部署Docker distribution仓库

    环境准备: 下载docker yum文件 # wget -O /etc/yum.repos.d/aliyun.repo http://mirrors.aliyun.com/repo/Centos-7. ...

  2. [BZOJ 1124][POI 2008] 枪战 Maf

    1124: [POI2008]枪战Maf Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 659  Solved: 259[Submit][Status ...

  3. 解决charles中文乱码(附代码)

    1. 将下面的代码保存为一个*.xml的文件 <?xml version='1.0' encoding='UTF-8' ?> <?charles serialisation-vers ...

  4. codeforces 703E Mishka and Divisors

    codeforces 703E Mishka and Divisors 题面 给出大小为\(1000\)的数组和一个数\(k\),求长度最短的一个子序列使得子序列的元素之积是\(k\)的倍数,如果有多 ...

  5. linux服务器部署nodejs项目

    一.安装nodejs 1.去官网下载和自己系统匹配的文件: 英文网址:https://nodejs.org/en/download/ 中文网址:http://nodejs.cn/download/ 通 ...

  6. mysql5.6 函数大全

    # 数学函数(1)ABS(x)返回x的绝对值(2)PI()返回圆周率π,默认显示6位小数(3)SQRT(x)返回非负数的x的二次方根(4)MOD(x,y)返回x被y除后的余数(5)CEIL(x).CE ...

  7. 在64位Ubuntu上编译32位程序常见错误

    问       题1: 找不到头文件 asm/errno.h 解决办法 : [/usr/lib/gcc$ ]sudo ln -s x86_64-linux-gnu/asm asm 问题2:找不到gcc ...

  8. Python 学习笔记(十四)Python类(三)

    完善类的内容 示例: #! /usr/bin/env python # coding =utf-8 #通常类名首字母大写 class Person(object): """ ...

  9. DDL-数据类型

    一.数值型1.整型tinyint.smallint.mediumint.int/integer.bigint1         2        3          4            8 特 ...

  10. 树概念及使用connect by进行级联查询

    树 树,大家都见过,以这种形式的数据关系,就是树.下面看一张图,了解什么是根节点(树干).节点或分叉.叶(叶节点) connect by 级联查询 connect by可以用于级联查询,常用于对具有树 ...