ex17.py

 1 # -*- coding:utf-8 -*-
 2 from sys import argv
 3 from os.path import exists
 4
 5 script, from_file, to_file = argv
 6
 7 print ("copying from %s to %s" % (from_file, to_file))
 8
 9 # we could do these two on one line too,how?
10 in_file = open(from_file)
11 indata = in_file.read()
12
13 print("the input fule is %d bytes long" % len(indata))  #学会使用len()函数
14
15 print ("Does the output file exist? %r" % exists(to_file))
16 print ("Ready,hit RETURN to countinue, CTRL-C to abort.")
17 input()
18
19 out_file = open(to_file, ‘w‘)
20 out_file.write(indata)
21
22 print("alright, all done.")
23 out_file.close()
24 in_file.close()
时间: 2024-07-29 03:39:24

ex17.py的相关文章

python练习题-20170916

周末开始第一次尝试对着书写代码练习题 <笨办法学python>--作者Zed A.Shaw,翻译Wang Dingwei ex1.pyprint('hello world')---------------------------------------ex2.py #A comment, this is so you can read your program later.#Anything after the # is ignored by python. print('i could ha

Python文件操作之简化代码

一朝误入此门中,从此红尘了如空.... 程序这条路,当真是路漫漫... 这两天找到一本书,名为<笨方法学Python第三版>,全实例,感觉挺好的.需要的点书名下载, 密码:gmpn 今天想说的是习题17,先看书中源码: 1 from sys import argv 2 from os.path import exists 3 script, from_file, to_file = argv 4 print "Copying from %s to %s" % (from_f

python基础笔记01:基础知识

1.4 数字和表达式 # -*- coding:utf-8 -*- #1.4 #除法 print 1 / 2 print 1.0 / 2 print 10 / 3 print 10.0 / 3.0 print int(1.0/2) print float(1/2) #如果使用"//",那么就算是浮点数,双斜线也会执行整除 print 1 // 2 print 1.0 // 2.0 #取余 print 10 % 3 print 2.75 % 0.5 print int(2.75 % 0.

使用TDD理解views.py与urls.py的关系

首先必须对MVC的概念有初步的认识,django也遵循这样一套规范,views.py相当于视图函数,是整个架构中的处理引擎,而urls.py的作用就是将用户请求送入这样的引擎. 项目结构: urls.py: from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ # Examples: #url(r'^$', 'mysite.views.home', name='home

layers.py cs231n

如果有错误,欢迎指出,不胜感激. import numpy as np def affine_forward(x, w, b): 第一个最简单的 affine_forward简单的前向传递,返回 out,cache """ Computes the forward pass for an affine (fully-connected) layer. The input x has shape (N, d_1, ..., d_k) and contains a minibat

Python pydoc.py

1. 查看帮助,我们可以在python命令行交互环境下用 help函数,比如: 查看 math 模块: >>> help('math')Help on built-in module math: NAME math DESCRIPTION This module is always available. It provides access to the mathematical functions defined by the C standard. FUNCTIONS acos(..

创建py模板

创建模板之后,每次新建py文件,已初始定义的代码段将会自动出现在py文件中.

python下编译py成pyc和pyo

其实很简单,用python -m py_compile file.py python -m py_compile /root/src/{file1,file2}.py编译成pyc文件.也可以写份脚本来做这事:Code: import py_compile py_compile.compile('path') //path是包括.py文件名的路径 用python -O -m py_compile file.py 编译成pyo文件.1.其中的 -m 相当于脚本中的import,这里的-m py_co

django 运行python manage.py sqlall books 时报错 app has migration

出现这个问题的原因是版本之前的不兼容,我用的django版本是1.8.6 而 这条python manage.py sqlall books 是基于django1.0版本的. 在django1.8.6版本中生成一个表的语句是    $ python manage.py makemigrations books $ python manage.py sqlmigrate books 0001 django book2 是一本不错的教程,但是就是版本太老了,可以通过看book2对django有一个比