如何删除字符串中的多余空格[复制](How to remove extra spaces in a string [duplicate])
这个问题在这里已经有了答案:
- 删除字符串中间多余的空格拆分连接Python 4的答案
- 简单的方法来删除字符串中的多个空格? 19个答案
我必须评估一个文本文件,其中包含格式不正确的文章,我必须重新格式化。 第一步是删除句子中的所有额外空格。 我决定读入文件,然后将所有行放入一个字符串中,然后将包含句子的行放入单独的列表中。 现在我在决定如何删除列表中的多余空格时遇到困难,并且想知道是否可以使用内置方法删除多余的空格?
以下是我列表中一个句子的例子:
["Albuquerque is my turkey and he's feathered and he's fine, And he"]
和我到目前为止的代码:
def remove_extra_whitespaces(): fileList= [] removeList= [] infile= open("essay1.txt", 'r') for line in infile: if (len(line))>0: fileList.append(line.strip()) else: fileList.append(line) print (len(fileList[4])) for k in range(len(fileList)): if (len(fileList[k]))>0: #" ".join(fileList[k]) removeList.append(fileList[k])
This question already has an answer here:
I have to evaluate a text file that contains a poorly formatted essay that I must reformat. The first step is to remove all extra spaces in the sentences. I decided to read in the file and then put all the lines into a string and then I put the lines that contains sentences into its own separate list. Now I have trouble with deciding how to remove the extra spaces in the list and was wondering if theres a built in method that I can use to remove extra spaces?
Here is an example of a sentence in my list:
["Albuquerque is my turkey and he's feathered and he's fine, And he"]
and the code I have so far :
def remove_extra_whitespaces(): fileList= [] removeList= [] infile= open("essay1.txt", 'r') for line in infile: if (len(line))>0: fileList.append(line.strip()) else: fileList.append(line) print (len(fileList[4])) for k in range(len(fileList)): if (len(fileList[k]))>0: #" ".join(fileList[k]) removeList.append(fileList[k])
原文:https://stackoverflow.com/questions/42357021
最满意答案
我认为这不是一项复杂的任务。我可能会问格雷戈里,他是否可以花几分钟时间来讨论这个问题......但格雷戈里是在浪潮之下。 这是没有任何进展的主要原因。 这就是答案......
It seems possible with the PostBuildScript plugin.
https://wiki.jenkins-ci.org/display/JENKINS/PostBuildScript+Plugin
Screenshot is attached and it is super-easy. Just download the plugin and choose "Execute a set of scripts" from "Add post-build-action" menu.
相关问答
更多-
使用Add post-build action按钮并选择Post build task ,它由提到的Post构建任务插件提供: 之后,您将拥有任务,每个任务都有一个输入字段脚本 ,您可以在其中执行命令: Use the Add post-build action button and select Post build task, which is provided by the mentioned Post build task plugin: Afterwards, you have Tasks, ea ...
-
经过快速测试后,似乎应该有一个删除按钮。 我不确定为什么它不在您的安装中,但我已经在我自己的Jenkins安装中看到过不同的配置。 我知道摆脱配置部分的唯一方法是将其从作业配置文件中删除。 为此,您需要对构建服务器上的Jenkins目录进行写访问。 首先找到你想从中删除IRC部分的作业的配置文件,它将位于Jenkins目录下的作业下,例如,如果你的工作被称为'我真棒的工作',那么你会发现它
\jobs\my awesome job\config.xml 其中 使用Post build任务插件很容易。 Very easily done with Post build task plugin.好的,问题解决了:我在环境系统变量GRADLE_USER_HOME, C:\Documents and Settings\myUser\.gradle中C:\Documents and Settings\myUser\.gradle ,这样gradle可以看到gradle.properties文件。 Ok, problem solved: I set up in the environment system variable GRADLE_USER_HOME, C:\Documents and Settin ...如何在Jenkins Groovy Post Build插件中重用groovy脚本?(How to re-use groovy script in Jenkins Groovy Post Build plugin?)[2023-09-16]
您可以在groovy postbuild中加载生活在Jenkins master上的任何groovy文件并执行它。 例如,您可以在c驱动器上有一个特殊目录,其中包含所有常用脚本。 稍后我将使用一些代码更新我的答案,该代码向您展示如何加载脚本。 更新 假设您的C:驱动器上有一个test.groovy文件,它应该像Groovy Postbuild中的以下内容一样简单: evaluate(new File("C:\\test.groovy")) 请查看Groovy Postbuild的评论部分以获取更多示例和其 ...我认为这不是一项复杂的任务。我可能会问格雷戈里,他是否可以花几分钟时间来讨论这个问题......但格雷戈里是在浪潮之下。 这是没有任何进展的主要原因。 这就是答案...... It seems possible with the PostBuildScript plugin. https://wiki.jenkins-ci.org/display/JENKINS/PostBuildScript+Plugin Screenshot is attached and it is super-easy. Just ...Gradle jacoco代码覆盖 - 然后在Jenkins中发布/显示(Gradle jacoco code coverage - Then publish/show in Jenkins)[2024-02-10]
问题:我假设您的单元测试不依赖于tomcat。 在这种情况下,你是对的,你不能提前启动tomcat。 要创建覆盖率报告,您需要执行 gradle jacocoTestReport 没有jacocoTestReport gradle将不会触发jacoco生成报告。 还有一件事,关于你的代码片段。 我假设您已将默认主要source/java更改为source/java 。 在这种情况下,您不必设置additionalSourceDirs 。 集成测试:是的,您需要先启动tomcat,或者至少必须确保tomca ...在Jenkins中从Gradle脚本调用Git时出错(Error Occured When Calling Git from Gradle Script in Jenkins)[2022-05-20]
由于我没有收到任何回复,我决定玩游戏并找到一个插件来使用它: Gradle Git插件 我在关于从grgit调用rev-list的问题中发现了一个问题,并决定在我的构建文件中实现相同的功能。 我将插件添加到我的gradle构建文件中: plugins { id 'org.ajoberstar.grgit' version '1.3.2' } 我将getBuildNumber转换为: def getBuildNumber = { -> return grgit.log(includes:['HEAD ...这个插件应该兼容2.7.4版和我所知道的Jenkins的大多数其他版本。 一旦安装并重新启动所有作业,就应该激活它。 为了访问Jenkins插件更改提供的选项- 自上次成功以来,您应该单击“ 自上次成功后更改 ”选项,或者在构建结束时附加字符串/changes-since-last-success/网址。 例如: http://111.11.11.111:8080/job/TEST/26/changes-since-last-success/ 然后你会得到如下选项: This plugin should ...我认为你实际上有两种不同的方法来解决这个问题: 1.从sh脚本获取版本/组 找到一种从gradle构建工具获取Gradle版本的方法(例如gradle getVersion() ,但我不熟悉Gradle)然后使用shell脚本来获取此版本。 如果要获取版本的Gradle命令是gradle getVersion() ,那么您将在管道中执行: def projectVersion = sh script: "gradle getVersion()", returnStdout: true def project ...相关文章
更多- [google面试CTCI] 1-5.替换字符串中特定字符
- 怎么得到String数组?
- redis 字符串(String) SET 操作
- 利用Decommission从Hadoop集群中Remove节点
- Java String类
- Extra Sensory perception
- Python 字符串操作
- Java 获取字符串中第N次出现的字符位置
- 【转】C# 中@符号在字符串中的作用
- 字符串应用之字符串编码转换
最新问答
更多- h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
- 创建一个功能(Create a function)
- 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
- PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
- Qt冻结循环的原因?(Qt freezing cause of the loop?)
- TableView重复youtube-api结果(TableView Repeating youtube-api result)
- 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
- SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
- 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
- 以编程方式创建UITableView(Creating a UITableView Programmatically)
- 如何打破按钮上的生命周期循环(How to break do-while loop on button)
- C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
- 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
- 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
- Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
- 设置kotlin扩展名(Setting a kotlin extension)
- 如何并排放置两个元件?(How to position two elements side by side?)
- 如何在vim中启用python3?(How to enable python3 in vim?)
- 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
- 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
- Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
- dedecms如何安装?
- 在哪儿学计算机最好?
- 学php哪个的书 最好,本人菜鸟
- 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
- 如何覆盖错误堆栈getter(How to override Error stack getter)
- 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
- USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
- 电脑高中毕业学习去哪里培训
- 正则表达式验证SMTP响应(Regex to validate SMTP Responses)