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将数据保存到文件中的更多相关文章

  1. Python 通过print_lol将数据保存到文件中

    1. 定义一个print_lol函数来控制列表的缩进和写入位置 import sys """this is a new fuction, which work for a ...

  2. python将字典中的数据保存到文件中

    d = {'a':'aaa','b':'bbb'}s = str(d)f = open('dict.txt','w')f.writelines(s)f.close()

  3. Python3操作MySQL,查询数据并保存到文件中

    我们在测试过程中,可能需要到数据库中拉去一些数据,为从测试准备.比如最近在做接口性能测试的时候,就需要很多数据来支撑,所以就需要的数据库去查询数据,下面就是python3 查询 mysql 并且保存到 ...

  4. 『无为则无心』Python日志 — 66、将日志信息保存到文件中

    目录 1.把日志信息保存到文件中 2.拓展 (1)观察代码 (2)提出问题 (3)问题说明 1.把日志信息保存到文件中 代码如下所示: """ logging模块是Pyt ...

  5. php cUrl模拟登录,cookie保存到文件中

    源码如下: <?php header("Content-Type:text/html;charset=utf-8"); //模拟群友通讯录手机号登录 $curl = curl ...

  6. json和xml封装数据、数据缓存到文件中

    一.APP的通信格式之xml xml:扩展标记语言,可以用来标记数据,定义数据类型,是一种允许用户对自己标记语言进行定义的源语言.XML格式统一,扩平台语言,非常适合数据传输和通信,业界公认的标准. ...

  7. 利用FFmpeg 将 rtsp 获取H264裸流并保存到文件中

    既然已经可以通过 RTSP 获取h264 裸流了.那么通过 FFmpeg 将其保存到文件中怎么做呢? 一.首先RTSP获取 h264 裸流 我们上面两篇文章主要讲的是通过 rtsp://Your ip ...

  8. Object 保存到文件中

    6月4日 Object 保存到文件中  Q. 你添加一个新类到你的项目当中且你希望可以保存这个类的一个实例对象到磁盘文件 并在需要时从磁盘文件读回到内存中  A. 方案  确保你的类遵循 NSCodi ...

  9. Java将对象保存到文件中/从文件中读取对象

    1.保存对象到文件中 Java语言只能将实现了Serializable接口的类的对象保存到文件中,利用如下方法即可: public static void writeObjectToFile(Obje ...

随机推荐

  1. 二 J2EE 概述

    一 WEB 应用 1. WEB 应用工作方式:B/S 模式 (浏览器/服务器模式) 2. WEB 应用结构组成: a. WEB 服务器:是安装在 WEB 服务器计算机上的一个软件包,负责接收用户请求并 ...

  2. .NET 里 静态方法的并发处理

    静态方法在程序运行时 就已经实例化好了 不管多少用户并发 都一样处理,不需要排队等待,实例代码: namespace DotNet.Example { using DotNet.BaseManager ...

  3. mysql最大连接数

    通常,mysql的最大连接数默认是100, 最大可以达到16384.1.查看最大连接数:show variables like '%max_connections%';2.修改最大连接数方法一:修改配 ...

  4. C++ Primer : 第十一章 : 关联容器之概述、有序关联容器关键字要求和pair类型

    标准库定义了两种主要的关联容器:map和set map中的元素时一些关键字-值(key-value)对,关键字起到索引的作用,值则表示与索引相关的数据.set中每个元素只包含一个关键字,可以完成高效的 ...

  5. 网站不能访问(httperrLog【Timer_MinBytesPerSecond】【Timer_ConnectionIdle】)(转载)

    在\LogFiles\HTTPERR的日志(C:\Windows\System32\LogFiles\HTTPERR)中发现了大量Timer_MinBytesPerSecond,Timer_Conne ...

  6. URAL-1989 Subpalindromes(单点更新+hash)

    题目大意:给一行字符串,两种操作:change(pos,char),将pos处字符改为char:isPalindrome(i,j),询问[i,j]之间是否为回文字符串. 题目分析:做正反两次字符串哈希 ...

  7. [POI 2008]Mafia

    这题目写了我好长时间,但还是几乎(不要在意细节)一遍 A 了喵~ 据说有代码奇短的,Orz 思路巧妙的大爷 想我这种 Brute Force 写写的傻 X 真是代码量飞起来了耶,喵~ 如果把每个人看成 ...

  8. 论文笔记之:Spatially Supervised Recurrent Convolutional Neural Networks for Visual Object Tracking

    Spatially Supervised Recurrent Convolutional Neural Networks for Visual Object Tracking  arXiv Paper ...

  9. linux下删除所有.svn目录

    linux下删除所有.svn目录方法为    find . -type d -name ".svn"|xargs rm -rf    或者    find . -type d -i ...

  10. stl的仿函数adapter

    Stl的一点思考 编程语言是为编译器写一份策略,如果将这份策略模板化那就是泛型编程了 bind1st bind2nd not1 not2 adapter并不改变仿函数接口,只是将参数引入其他的运算流程