如何在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)[2021-12-22]
现在可以在AppHarbor上运行Machine.Specifications(MSpec)测试。 It is now possible to run Machine.Specifications (MSpec) tests on AppHarbor. -
部署到AppHarbor后,WebInvoke表单元素为空(WebInvoke Form elements are null after deploying to AppHarbor)[2023-10-16]
好吧,我不确定问题是什么,但我找到了解决办法...... 我现在使用以下代码,它似乎工作: StreamReader reader = new StreamReader(stream); String res = reader.ReadToEnd(); NameValueCollection coll = HttpUtility.ParseQueryString(res); criteria.Retailers= coll["Retailers"].Split('|'); 我在这篇文章中找到了答案: WC ... -
如果您想在其中一个提到的托管商处拥有私人帐户,您唯一的选择就是Bitbucket 。 他们的免费计划包括无限制的私人Git和Mercurial存储库(唯一的限制是不超过五个用户,包括您)可以访问私有存储库。 GitHub也提供私有存储库, 但不是免费的 。 CodePlex完全免费, 但只允许开源项目 (没有私人项目)。 编辑: 使用“集成Appharbor工具到NuGet”,你的意思是AppHarbor拉动NuGet包,这样你就不必将它们提交到你的存储库了吗? 如果是,请查看使用NuGet包还原以避免将包 ...
-
所以,我的代码中有一个错误,但下面的信息是我用来了解AppHarbor正在对配置变量做什么,并允许我修复它。 本文包含有关配置变量如何工作的模糊细节,但这里是TLDR。 配置变量仅适用于AppSettings; 你不能将它们与连接字符串一起使用 AppSettings键值必须与配置变量的名称匹配。 Web配置转换发生在配置变量更新之前。 FINAL步骤是使用配置变量更新AppSettings。 来自AppHarbor支持的说明: 在实际部署应用程序之前,不会注入应用程序的生产配置,因此如果从构建日志页面下载 ...
-
我解决了这个问题 - 发生这种情况的原因是因为内容未被复制到输出目录。 我不确切知道AppHarbor如何在那里构建部署脚本,但我将Copy To Output Directory选项值更改为Copy Always ,这解决了问题。 ( Build Action已设置为Content ) I solved the problem - The reason this was happening because the content wasn't being copied to the output dire ...
-
在Appharbor上无头(Dotless on Appharbor)[2022-09-26]
我必须将Build Action值设置为Content ,然后将Copy To Output DIrectory值设置为Copy always 。 这样做后,它似乎正常工作! WOOHOOOO! 这太令人兴奋了。 这是过去几天的重大问题。 I had to set the Build Action value to Content and then set the Copy To Output DIrectory value to Copy always. After doing that, it seem ... -
事实证明, _ViewStart.cshtml文件不再是项目的一部分。 由于物理文件仍然存在,本地调试正在捡起它并且运行正常。 但是,如果它不是构建的一部分,当AppHarbor构建项目时,它不包括导致所有视图(没有显式布局)使用Layout = null进行渲染 感谢大家! 捂脸 So it turns out that the _ViewStart.cshtml file was no longer a part of the project. Since the physical file was s ...
-
您是否尝试过按照此问题中的建议将“ Generate serialization assembly ”设置为“关闭”? Have you tried setting Generate serialization assembly to "Off" as suggested in this question?
-
为什么要使用AppHarbor插件?(Why use AppHarbor addons?)[2021-11-09]
通过AppHarbor配置附加组件为您提供了自动应用程序配置,整合计费以及能够管理AppHarbor中所有内容的优势(无需记住X登录,也无需记住在各种服务提供商处更新X信用卡)。 我们试图让标题尽可能不显眼,并且它似乎在我们的大多数附加合作伙伴网站上运行良好。 如果它导致任何地方破损,请给我们留言。 我们还不断与我们的附加合作伙伴合作,使他们的附加计划产品保持最新状态,我刚刚给AirBrake家伙发了一封电子邮件。 感谢您提醒我们这个问题! Provisioning add-ons through AppH ... -
将HintPath更改为..\packages对我来说不起作用,但将其更改为$(Solutiondir)\packages对我来说就像魅力一样。 There were some paths in the csproj that were broken:
..\web\packages\mongocsharpdriver.1.8.3\lib\net35\MongoDB.Bs ...