print 输出到文件
content = """We have seen thee, queen of cheese,
Lying quietly at your ease,
Gently fanned by evening breeze,
Thy fair form no flies dare seize.
All gaily dressed soon you'll go
To the great Provincial show,
To be admired by many a beau
In the city of Toronto.
Cows numerous as a swarm of bees,
Or as the leaves upon the trees,
It did require to make thee please,
And stand unrivalled, queen of cheese.
May you not receive a scar as
We have heard that Mr. Harris
Intends to send you off as far as
The great world's show at Paris.
Of the youth beware of these,
For some of them might rudely squeeze
And bite your cheek, then songs or glees
We could not sing, oh! queen of cheese.
We'rt thou suspended from balloon,
You'd cast a shade even at noon,
Folks would think it was the moon
About to fall and crush them soon.
"""
1.python3版本
f = open('poem.txt','w')
print(content,file=f)
f.close()
2.python2版本
f = open('poem.txt','w')
print >> f,content #使用输出重定向 ,注意只是将内容写入了文件的缓冲区中,还没有写入文件
f.close() #关闭文件描述符,将文件缓冲区中的内容从内存写入磁盘文件
print 输出到文件的更多相关文章
- python内置函数print输出到文件,实现日志记录的功能
# bulid time 2018-6-22 import os import time def log(*args, **kwargs): # *kargs 为了通用 可不传 rule = &quo ...
- python print输出到文件
要将程序的输出送到一个文件中,需要在 print 语句后面使用 >> 指定一个文件,如下所示: principal = # 初始金额 rate = 0.05 # 利率 numyears = ...
- Python Linux 命令行执行脚本输出重定向print到日志文件
reference: https://unix.stackexchange.com/questions/182537/write-python-stdout-to-file-immediately ...
- (Python )格式化输出、文件操作、json
本节学习Python的格式化输出,文件操作以及json的简单用法 1.格式化输出 将非字符串类型转换成字符串,可以使用函数:str() 或者repr() ,(这两个函数的区别目前我还没搞懂,求解答) ...
- linux bash脚本把A和B文件中有相同ID的B文件的内容输出到文件C
bash脚本把A和B文件中有相同ID的B文件的内容输出到文件C. Aid文件:ID001.1ID032.1ID090.10 Bfilt文件:XX XX XXX ID001.1 XXX999999999 ...
- 用otl写的oracle取数工具,执行传入在查询语句,把结果输出到文件
项目中经常需要用到此类型的工具 #pragma warning (disable:4786) #include <iostream> #include <map> #inclu ...
- [Head First Python]4.读取文件datafile.txt, 去除两边空格, 存储到列表,从列表格式化(nester.py)后输出到文件man.out,other.out
datafile.txt #文件 Man: this is the right room for an argument. Other Man: I've told you once. Man: N ...
- ASP.NET Core 2.1 : 十二.内置日志、使用Nlog将日志输出到文件
应用离不开日志,虽然现在使用VS有强大的调试功能,开发过程中不复杂的情况懒得输出日志了(想起print和echo的有木有),但在一些复杂的过程中以及应用日常运行中的日志还是非常有用. ASP.NET ...
- Java的实验程序之输出单个文件中的前 N 个最常出现的英语单词
日期:2018.10.11 星期四 博客期:016 题目:输出单个文件中的前 N 个最常出现的英语单词,并输出到文本文件中 在程序运行之前,我试着先写了字符的字母的总结,加载代码如下: //如下是第一 ...
随机推荐
- 配置apache-maven-3.6.0时所遇到的坑(一)
在命令行窗口中输入:mvn -v 或 直接 mvn 时报错:“错误: 找不到或无法加载主类 org.codehaus.plexus.classworlds.launcher.Lau ...
- Readability Assessment for Text Simplification -paper
https://pdfs.semanticscholar.org/e43a/3c3c032cf3c70875c4193f8f8818531857b2.pdf 1.introduction在Brazil ...
- c++输入输出流加速器
发现同样是cin,cout,其他大佬(orz)的耗时短很多.看了他们的代码,我发现他们加了一个很神奇的匿名函数(Lambda捕获)提高了cin,cout效率,因此去百度了解了一下.以下是大佬所使用 ...
- BinarySearch(Java)
private int binarySearch(int[] input, int target) { if (input == null) { return -1; } int index1 = 0 ...
- easyui的select使用
这是一个小demo,其他相关功能查看easyuiAPI,需要注意的是valueField: 'id', textField: 'name'中id指json的key,name指json的值,id和nam ...
- Go Example--锁
package main import ( "fmt" "math/rand" "runtime" "sync" &qu ...
- Go Example--for循环
package main import "fmt" func main() { i := 1 //Go循环只有for, 第一种循环方式 for i<=3 { fmt.Prin ...
- 【BZOJ2427】【HAOI2010】软件安装
无力吐槽…… 原题: 现在我们的手头有N个软件,对于一个软件i,它要占用Wi的磁盘空间,它的价值为Vi.我们希望从中选择一些软件安装到一台磁盘容量为M计算机上,使得这些软件的价值尽可能大(即Vi的和最 ...
- maven(二)
1.1 Maven的好处 节省空间 对jar包做了统一管理 依赖管理 一键构建 可跨平台 应用在大型项目可提高开发效率 1.2 Maven安装部署配置 1.3 Maven的仓库 ...
- "ERR unknown command 'cluster'"
golang 连接redis 集群提示 "ERR unknown command 'cluster'" redisdb = redis.NewClusterClient(& ...