如何在Python中访问文件(.txt)中的下一行(How to access next line in a file(.txt) in Python)
我有一个文件然后打开它然后检查一些东西。 如果该行以“E PARAM”开头并且其中也有“OOPS1”,那么我想检查下一行是否以“E PARAM”开头。 如果不是,我会创建一个新文件并将其复制到那里,直到我没有打到另一个“E PARAM”行。 由于Python没有next()选项......什么可以帮助我
import string import os A = "k_trap_cur" B = open(A, 'r+') lines = B.readline() for lines in B: if lines.startswith("E PRAM"): if "OOPS: 1" in lines: while lines.next().startswith("E PARAM") == False: // HERE I want to access next line print " YES"
I have a file and I open it and then I check for few things. If the line starts with "E PARAM" and also has "OOPS1" in it somewhere then I want to check that the next line starts with " E PARAM". If not I will make a new file and copy it there till the time I dont hit another "E PARAM" line. Since Python doesnt have a next() option... what can help me here
import string import os A = "k_trap_cur" B = open(A, 'r+') lines = B.readline() for lines in B: if lines.startswith("E PRAM"): if "OOPS: 1" in lines: while lines.next().startswith("E PARAM") == False: // HERE I want to access next line print " YES"
原文:https://stackoverflow.com/questions/17075901
满意答案
好吧,我不确定问题是什么,但我找到了解决办法......
我现在使用以下代码,它似乎工作:
StreamReader reader = new StreamReader(stream); String res = reader.ReadToEnd(); NameValueCollection coll = HttpUtility.ParseQueryString(res); criteria.Retailers= coll["Retailers"].Split('|');
我在这篇文章中找到了答案: WCF + REST:请求数据在哪里?
Well I'm not sure what the problem is, but I found a work-around...
I now use the following code and it seems to work:
StreamReader reader = new StreamReader(stream); String res = reader.ReadToEnd(); NameValueCollection coll = HttpUtility.ParseQueryString(res); criteria.Retailers= coll["Retailers"].Split('|');
I found the answer on this post: WCF + REST: Where is the request data?
相关问答
更多MSpec在Appharbor上(MSpec on Appharbor)
部署到AppHarbor后,WebInvoke表单元素为空(WebInvoke Form elements are null after deploying to AppHarbor)
使用subversion部署到AppHarbor(deploying to AppHarbor using subversion)
AppHarbor配置变量未更新(AppHarbor Configuration Variables Not Updating)
appharbor没有部署静态内容(appharbor not deploying static content)
在Appharbor上无头(Dotless on Appharbor)
AppHarbor上的布局被忽略(Layout being ignored on AppHarbor)
在AppHarbor上部署抛出混合模式程序集错误(Deploying on AppHarbor throwing Mixed Mode Assembly error)
为什么要使用AppHarbor插件?(Why use AppHarbor addons?)
AppHarbor使用nuget包构建错误(AppHarbor build error with nuget packages)
相关文章
更多Securing Solr on Tomcat access using a user account
探索 Python,第 1 部分: Python 的内置数值类型
ACCESS TOKEN
python2和python3的区别
Python资源索引 【转载】
Python的文件类型
Becoming a data scientist
采用Python来访问Hadoop HSFS存储实现文件的操作
Python 在Linux中使用SQLite3
Python内建函数(A)
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!