python读取txt文件中特定位置字符的方法

yipeiwu_com6年前Python基础

如下所示:

# -*- coding:utf-8 -*-

import sys
reload(sys)
sys.setdefaultencoding('utf8')
fp = open("resources.txt", "r")
sample = fp.readlines()

file=open("test.txt", "w")

for line in sample:
 sample_ = line.split('固定字符')
 print(sample_[n])
 file.write(sample_[n])
 file.write('\n')

以上这篇python读取txt文件中特定位置字符的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python斐波那契数列的计算方法

题目: 计算斐波那契数列。具体什么是斐波那契数列,那就是0,1,1,2,3,5,8,13,21,34,55,89,144,233。 要求: 时间复杂度尽可能少 分析: 给出了...

解决pip install的时候报错timed out的问题

安装包的时候报错,执行:pip install pyinstaller 问题: File "c:\python\python35\lib\site-packages\pip\_ven...

python openCV获取人脸部分并存储功能

本文实例为大家分享了python openCV获取人脸部分并存储的具体代码,供大家参考,具体内容如下 #-*- coding:utf-8 -*- import cv2 import...

Django ORM多对多查询方法(自定义第三张表&ManyToManyField)

对于多对多表 - 1.自定义第三张表,更加灵活 - 2.ManyToManyField 自动生成第3张表 只能 有3列数据 不能自己添加。 自定义第三张表 # models.py...

Python接收Gmail新邮件并发送到gtalk的方法

本文实例讲述了Python接收Gmail新邮件并发送到gtalk的方法。分享给大家供大家参考。具体实现方法如下: #!/usr/bin/env python # -*- coding...