首页 \ 问答 \ 文件i / o问题(file i/o problem)

文件i / o问题(file i/o problem)

我遇到一个非常简单的问题。 我正在尝试删除文件中的换行符并将输出发送到新文件。 这是我的代码:

infile = open('seq.txt', mode='r', encoding='utf-8')
lines = infile.readlines()
for line in lines:
    par = line.strip('\n')

outfile = open('seqpar.txt', mode='w', encoding='utf-8')
for line in lines:
    outfile.write(par)

当我运行上面的代码时,outfile(seqpar.txt)的内容是完全空白的。 我试图在线搜索I / O教程,但我似乎无法找到类似问题的任何解决方案。 由于某种原因,我在理解文件I / O时遇到了麻烦。请提前感谢您的帮助。


I am having trouble with a really simple problem. I'm trying to remove line breaks in a file and send the output to a new file. This is my code:

infile = open('seq.txt', mode='r', encoding='utf-8')
lines = infile.readlines()
for line in lines:
    par = line.strip('\n')

outfile = open('seqpar.txt', mode='w', encoding='utf-8')
for line in lines:
    outfile.write(par)

When I run the above code, the contents of the outfile (seqpar.txt) is completely blank. I've tried to search for I/O tutorials online, but I can't seem to locate any solutions to a similar problem. I'm really having trouble with understanding file I/O for some reason.Thanks in advance for the help.


原文:https://stackoverflow.com/questions/6043537
更新时间:2023-10-12 07:10

最满意答案

看起来像格式化的问题。

您需要使用$filter=(Bokning_x0020_fr_x00e5_n ge datetime'2017-10-03T00:28:05Z') and (Bokning_x0020_till le datetime'2010-04-02T00:28:08Z')

所以,你的网址是:

var url = `${_spPageContextInfo.webAbsoluteUrl}/_api/web/lists/getbytitle('Program')/items?
$filter=(Bokning_x0020_fr_x00e5_n ge datetime'2017-10-03T00:28:05Z') and (Bokning_x0020_till le datetime'2010-04-02T00:28:08Z')
$select=Title,Bokning_x0020_fr_x00e5_n,Bokning_x0020_till,Kontaktperson,Max_x0020_antal_x0020_platser;

Looks like some issue with formatting.

You need to use $filter=(Bokning_x0020_fr_x00e5_n ge datetime'2017-10-03T00:28:05Z') and (Bokning_x0020_till le datetime'2010-04-02T00:28:08Z')

So, your url would be:

var url = `${_spPageContextInfo.webAbsoluteUrl}/_api/web/lists/getbytitle('Program')/items?
$filter=(Bokning_x0020_fr_x00e5_n ge datetime'2017-10-03T00:28:05Z') and (Bokning_x0020_till le datetime'2010-04-02T00:28:08Z')
$select=Title,Bokning_x0020_fr_x00e5_n,Bokning_x0020_till,Kontaktperson,Max_x0020_antal_x0020_platser;

相关问答

更多
  • 在这种情况下,您需要强制将端点“ https://mydomain.sharepoint.com ”设置为null。 否则,对“mydomain.sharepoint.com”的每个请求都将添加一个由SharePoint服务器验证的图形授权标头。 由于应用程序是在Azure AD而非SharePoint上注册的,因此它将被视为无效的受众。 以下是供您参考的解决方法,如果它适用于您,请告诉我。 (function () { angular.module('app', [ 'ngRoute', ...
  • 以下示例显示如何检索特定类型的列表( ListTemplateType.DocumentLibrary为101 )。 Url: /_api/web/lists?$filter=BaseTemplate eq 101 Method: GET Headers: Authorization: "Bearer " + accessToken Accept: "application/atom+xml" The following example shows how to retrieve list ...
  • 根据SharePoint REST请求中的使用OData查询操作,不支持grouping等操作。 解决方案是在从SharePoint REST服务返回JSON结果后应用分组。 如何使用jQuery从数组中获取不同的值 function groupBy(items,propertyName) { var result = []; $.each(items, function(index, item) { if ($.inArray(item[propertyName], resu ...
  • 看起来像格式化的问题。 您需要使用$filter=(Bokning_x0020_fr_x00e5_n ge datetime'2017-10-03T00:28:05Z') and (Bokning_x0020_till le datetime'2010-04-02T00:28:08Z') 所以,你的网址是: var url = `${_spPageContextInfo.webAbsoluteUrl}/_api/web/lists/getbytitle('Program')/items? $filter=( ...
  • 搜索周围 图搜索API的功能有限,首先它只会搜索目标网站集(驱动器),其次我不确定目前是否支持按内容类型进行搜索(可能带有$ filter)。 ..) 但如果这符合你的约束条件,它可能是一个(更容易)的选项。 围绕auth&auth 在这两种情况下(图表或SharePoint搜索),当人们到达您的应用程序(asp.net MVC)时会发生什么:身份验证中间件负责将用户重定向到AAD,为您的应用程序获取访问令牌,将其重定向到您的应用程序应用程序使用该访问令牌在应用程序上创建会话。 我的观点是:在这一点上,你所 ...
  • 我终于找到了错误。 我使用的URL是正确的。 唯一的问题是,默认情况下它将行限制设置为20.在增加行限制时,我能够获得完整的结果。 I finally found the mistake. The URL which I was using was correct. The only thing was that by default it was taking the row limit to 20. On increasing the row limit I was able to get comple ...
  • 我得到了答案。 只需将类“noindex”放在您不希望出现在搜索结果中的元素上。 在我的例子中,我将类“noindex”放在包含页眉,页脚和菜单持有者的div上。 I got the answer. Just put the class "noindex" on the element that you don't want to appear in the search result. In my case, I put the class "noindex" on my divs containing ...
  • Category字段( PostCategory内部名称)是一个多选字段 ,在SharePoint REST中, 不支持将$orderby查询选项应用于此类型的字段。 但您可以使用JavaScript对返回的项目进行排序。 以下示例演示如何按Category字段订购Posts 。 这里有一个重要的注意事项: 由于Category字段是多选字段值,因此假设每个帖子只能指定一个类别 。 为此,引入了FirstCategoryTitle属性, FirstCategoryTitle属性表示帖子项中第一个类别的标题。 ...
  • 以下是此问题的两种可能解决方案: 创建第二个列表,并在主列表上批准新项目或更新项目时让工作流程在此列表上创建或更新项目。 答:工作清单 - >新建或更改项目 - >工作流程 - >创建或更新清单B:生产清单上的项目 使用项目的唯一ID来检查列表B上是否已存在项目。 你可以在这里阅读第二个可能的解决方案: https : //sharepoint.stackexchange.com/questions/116921/distinguish-between-approved-and-not-approved-i ...
  • 是列表和图书馆在一天结束时是一回事。 您可以通过剥离上述案例中的最后一个段(Items(1))从odata.editLink获取列表标题。 如果您调用该路径,它将为您提供列表与已修改项目/文件的详细信息。 如果您想要用户的详细信息,请调用/ _api / Web / lists / getbytitle('用户信息列表')/项目(EditorId)。 如果你想要项目/文件的路径调用odata.editlink并且返回的serverrelativeurl参数将具有它的路径,title将具有项目/文件的标题。 ...

相关文章

更多

最新问答

更多
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • Java中的不可变类(Immutable class in Java)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • EXCEL VBA 基础教程下载
  • RoR - 邮件中的动态主体(部分)(RoR - Dynamic body (part) in mailer)
  • 无法在Google Script中返回2D数组?(Can not return 2D Array in Google Script?)
  • JAVA环境变量的设置和对path , classpth ,java_home设置作用和目的?
  • mysql 关于分组查询、时间条件查询
  • 如何使用PowerShell匹配运算符(How to use the PowerShell match operator)
  • Effective C ++,第三版:重载const函数(Effective C++, Third edition: Overloading const function)
  • 如何用DELPHI动态建立MYSQL的数据库和表? 请示出源代码。谢谢!
  • 带有简单redis应用程序的Node.js抛出“未处理的错误”(Node.js with simple redis application throwing 'unhandled error')
  • 使用前端框架带来哪些好处,相对于使用jquery
  • Ruby将字符串($ 100.99)转换为float或BigDecimal(Ruby convert string ($100.99) to float or BigDecimal)
  • 高考完可以去做些什么?注意什么?
  • 如何声明放在main之后的类模板?(How do I declare a class template that is placed after the main?)
  • 如何使用XSLT基于兄弟姐妹对元素进行分组(How to group elements based on their siblings using XSLT)
  • 在wordpress中的所有页面的标志(Logo in all pages in wordpress)
  • R:使用rollapply对列组进行求和的问题(R: Problems using rollapply to sum groups of columns)
  • Allauth不会保存其他字段(Allauth will not save additional fields)
  • python中使用sys模块中sys.exit()好像不能退出?
  • 将Int拆分为3个字节并返回C语言(Splitting an Int to 3 bytes and back in C)
  • 在SD / MMC中启用DDR会导致问题吗?(Enabling DDR in SD/MMC causes problems? CMD 11 gives a response but the voltage switch wont complete)
  • sed没有按预期工作,从字符串中间删除特殊字符(sed not working as expected, removing special character from middle of string)
  • 如何将字符串转换为Elixir中的函数(how to convert a string to a function in Elixir)