Python 通过print将数据保存到文件中
1. Print them to screen
man = []
other = []
try:
data = open('sketch.txt')
for each_line in data:
try:
(role, line_spoken) = each_line.split(':',1)
line_spoken=line_spoken.strip()
if role== 'Man':
man.append(line_spoken)
elif role == 'Other Man':
other.append(line_spoken)
except ValueError:
pass
data.close()
except IOError:
print ('The datafiel is missing!') print('printing=====man===list=======',man)
print('printing=====other===list=====',other)
2. Save the data to man_data.txt and other_data.txt
man = []
other = []
try:
data = open('sketch.txt')
for each_line in data:
try:
(role, line_spoken) = each_line.split(':',1)
line_spoken=line_spoken.strip()
if role== 'Man':
man.append(line_spoken)
elif role == 'Other Man':
other.append(line_spoken)
except ValueError:
pass
data.close()
except IOError:
print ('The datafiel is missing!') try:
man_out = open("man_data.txt","w")
other_out = open('other_data.txt','a') print('here is data from list',man,file=man_out)
print('save man file to man_data.txt')
print('here is data from list',other,file=other_out)
print('save other file to other_data.txt') man_out.close()
other_out.close()
except IOError:
print ('data file is not exist')
Python 通过print将数据保存到文件中的更多相关文章
- Python 通过print_lol将数据保存到文件中
1. 定义一个print_lol函数来控制列表的缩进和写入位置 import sys """this is a new fuction, which work for a ...
- python将字典中的数据保存到文件中
d = {'a':'aaa','b':'bbb'}s = str(d)f = open('dict.txt','w')f.writelines(s)f.close()
- Python3操作MySQL,查询数据并保存到文件中
我们在测试过程中,可能需要到数据库中拉去一些数据,为从测试准备.比如最近在做接口性能测试的时候,就需要很多数据来支撑,所以就需要的数据库去查询数据,下面就是python3 查询 mysql 并且保存到 ...
- 『无为则无心』Python日志 — 66、将日志信息保存到文件中
目录 1.把日志信息保存到文件中 2.拓展 (1)观察代码 (2)提出问题 (3)问题说明 1.把日志信息保存到文件中 代码如下所示: """ logging模块是Pyt ...
- php cUrl模拟登录,cookie保存到文件中
源码如下: <?php header("Content-Type:text/html;charset=utf-8"); //模拟群友通讯录手机号登录 $curl = curl ...
- json和xml封装数据、数据缓存到文件中
一.APP的通信格式之xml xml:扩展标记语言,可以用来标记数据,定义数据类型,是一种允许用户对自己标记语言进行定义的源语言.XML格式统一,扩平台语言,非常适合数据传输和通信,业界公认的标准. ...
- 利用FFmpeg 将 rtsp 获取H264裸流并保存到文件中
既然已经可以通过 RTSP 获取h264 裸流了.那么通过 FFmpeg 将其保存到文件中怎么做呢? 一.首先RTSP获取 h264 裸流 我们上面两篇文章主要讲的是通过 rtsp://Your ip ...
- Object 保存到文件中
6月4日 Object 保存到文件中 Q. 你添加一个新类到你的项目当中且你希望可以保存这个类的一个实例对象到磁盘文件 并在需要时从磁盘文件读回到内存中 A. 方案 确保你的类遵循 NSCodi ...
- Java将对象保存到文件中/从文件中读取对象
1.保存对象到文件中 Java语言只能将实现了Serializable接口的类的对象保存到文件中,利用如下方法即可: public static void writeObjectToFile(Obje ...
随机推荐
- (理论篇)温故而知新_PHP入门基础教程
简单的回顾一下基础知识 1.嵌入方法: 类似ASP的<%,PHP可以是<?php或者是<?,结束符号是?>,当然您也可以自己指定. 2.引用文件: 引用文件的方法有两种:req ...
- hdu 2665 Kth number
划分树 /* HDU 2665 Kth number 划分树 */ #include<stdio.h> #include<iostream> #include<strin ...
- linux,下载与安装
1.下载地址 1.网易开源镜像站 http://mirrors.163.com 2.centos 官方站 http://www.centos.org 2.虚拟机 VirtualBox ------- ...
- 让Windows Server 2008 + IIS 7+ ASP.NET 支持10万并发请求(转载)
转自:http://www.cnblogs.com/dudu/archive/2009/11/10/1600062.html 今天下午17点左右,博客园博客站点出现这样的错误信息: Error Sum ...
- [JSOI2008] 完美的对称
题目描述 在峰会期间,必须使用许多保镖保卫参加会议的各国代表.代表们除了由他自己的随身保镖保护外,组委会还指派了一些其他的特工和阻击手保护他们.为了使他们的工作卓有成效,使被保卫的人的安全尽可能得到保 ...
- Google Java Style Guide
https://google.github.io/styleguide/javaguide.html Table of Contents 1 Introduction 1.1 Terminolog ...
- Threadpool dump
Microsoft (R) Windows Debugger Version 10.0.10586.567 AMD64Copyright (c) Microsoft Corporation. All ...
- ES
https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-service-win.html https://www.e ...
- java 中的断言assert的使用
一.assertion的意义和用法 J2SE 1.4在语言上提供了一个新特性,就是assertion功能,它是该版本在Java语言方面最大的革新. 从理论上来说,通过 assertion方式可以证明程 ...
- Nuget 摘录
1 , Creating and Publishing a Package https://docs.nuget.org/create/creating-and-publishing-a-pa ...