- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用循环函数给出 5 个字符串:“Article 1”、“Article 2”等等……在此之后,我想获取文本文件中文章下方的信息。例如:
Article 1. It is not good to eat pizza after midnight
Article 2. I wouldn't survive a day withouth stackexchange
Article 3. All of these are just random phrases
Article 4. To prove if my experiment works.
Article 5. The red dog jumps over the lazy fox
这样做的目的是将每篇文章分开,以便稍后将其导出为相同文本格式的数据 block 。这是我所拥有的:
n=0
while n < 5:
n = n + 1
a = ('Article %(number)s' % {'number': n})
print(a)
with open("LISR2.txt") as openfile:
for line in openfile:
if a in line:
print(line)
但是我得到的是
C:\Users\Rafael\AppData\Local\Programs\Python\Python35-32\python.exe
Article 1
Article 2
Article 3
Article 4
Article 5
Article 5. The red dog jumps over the lazy fox
对于我正在尝试做的事情,这是正确的方法吗?还是我只需要更改一些代码语法?
最佳答案
请记住,代码完全按照您键入的顺序执行。此外,Python 中的缩进决定了嵌套。这意味着 while
和 with
语句处于同一级别,将依次执行。如果您希望 with
语句针对每个“文章”执行,那么您必须将它缩进另一个级别,以便它位于 while
循环内而不是在它之后。
关于python - 在 Python 中使用开放函数和循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40944520/
有人查看我的代码说下面的 SQL 查询 (SELECT * FROM...) 显然容易受到攻击。我对此进行了研究,似乎我通过使用参数化查询正确地做到了这一点,但显然我遗漏了一些东西。 app.get(
我使用 Curie 作为基本模型,使用自定义数据集创建了一个微调模型。我正在使用 Azure OpenAI 服务。 该模型正在尝试使用最大可能的 token 生成响应。例如,如果 max_token
我正在尝试将6x15数组(映射)中的随机坐标设置为数字3,但前提是该坐标的值仍为0。我要放置的值为3) 25 int shipnum; 26 int x; 27 28 shipnum = 1;
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
您好,我正在寻找“开放”、“链接”和“多重哈希”算法的伪代码。是的,我花了很多时间在谷歌上搜索,但没能找到好东西。 如果你有分享的链接,我将不胜感激 问候 最佳答案 这hash table tutor
是否可以实现 Visitor Pattern尊重 Open/Closed Principle ,但仍然可以添加新的可访问类? 开放/封闭原则指出“软件实体(类、模块、函数等)应该对扩展开放,但对修改关
很难说出这里问的是什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或言辞激烈,无法以目前的形式合理回答。如需帮助澄清此问题以便可以重新打开,visit the help center . 12 年前
我创建了 Azure 开放 AI 服务我想针对特定问题训练模型。但是,自定义模板按钮被禁用。在文档中,它说明了如何生成包含要训练的问题和答案的 .Jsonl,但没有任何内容可以导入这些文件。有人拿到了
我找到了一些关于开放/封闭递归的解释,但我不明白为什么定义中包含“递归”一词,或者它与动态/静态调度相比如何。我找到的解释中有: Open recursion. Another handy featu
我正在尝试为在加权图上运行的库找出类设计。可以在这个图上执行各种算法,例如,找到两个节点之间的最短距离,两个节点之间的最长距离,两个节点之间距离小于 10 的路径数(比方说)等。 我关心的不是我所知道
谁能告诉我开放 SSL 和安全 SSL 之间的区别。 我已经在 Play 商店发布了新的 Android 应用程序,它使用远程 API。 在 API 服务器上,我已经成功安装了安全 SSL。但我仍然被
当我将 url 加载到 WebView 并尝试打开链接时,其中一些会显示如下错误页面: net::ERR_UNKNOWN_URL_SCHEME intent://maps.yandex.ru?utm_
2 月 24 日消息 据外媒 TheVerge 报道,2 月 23 日晚间,LG 宣布将该公司的 webOS 智能电视平台授权给其他电视厂商使用,目前 LG 已和 RCA、Ayonz 和康佳等电视厂
我一直在思考这个面向对象的设计问题,但无法提出令人满意的解决方案,所以我想在这里向人群开放以征求意见。 我有一个代表回合制棋盘游戏的 Game 类,出于这个问题的目的,我们可以假设它类似于 Monop
我们有一个 Web 服务,它充当我们的客户和另一个服务之间的网关。客户端向第三方服务发送消息并从其接收随机消息。客户端的服务器通过安全套接字打开到我们的 Web 服务器的 channel ,以便接收传
应用商店里有一个叫 Touchpad 的应用,最后一次更新是在 11 月 29 日,其中包含一个新功能,支持“使用设备键盘上的 Siri 键向电脑发送文本”,我想知道是否有开放的 API Siri现在
我尝试在认知搜索上下文中为 Azure 开放 AI 服务添加矢量搜索时遇到问题。选择勾选标记后,即使有可用的现有文本嵌入模型,我也无法列出任何模型。造成这种差异的可能原因是什么以及如何解决? 最佳答案
我尝试在认知搜索上下文中为 Azure 开放 AI 服务添加矢量搜索时遇到问题。选择勾选标记后,即使有可用的现有文本嵌入模型,我也无法列出任何模型。造成这种差异的可能原因是什么以及如何解决? 最佳答案
我们的堆栈:Tomcat 7、Spring 3.1.1、OpenJPA 2.2.0 我遇到了一个问题,根源是比较: server1.equals(server2); server1 和 server2
我正在使用以下命令设置一个 java EE 项目(打开)JPA。我使用 glassfish 4.0 作为我的应用程序服务器,但似乎无法让持久性发挥作用。 我面临的问题似乎是一个相当普遍的问题,因为同一
我是一名优秀的程序员,十分优秀!