文件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;

相关问答

更多

对Sharepoint REST API进行CAML查询会导致“无效的受众URI”?(CAML-query to Sharepoint REST API results in “invalid audience URI”?)

在这种情况下,您需要强制将端点“ https://mydomain.sharepoint.com ”设置为null。 否则,对“mydomain.sharepoint.com”的每个请求都将添加一个由SharePoint服务器验证的图形授权标头。 由于应用程序是在Azure AD而非SharePoint上注册的,因此它将被视为无效的受众。 以下是供您参考的解决方法,如果它适用于您,请告诉我。 (function () { angular.module('app', [ 'ngRoute...

Rest API中的Sharepoint GetListsOfType(Sharepoint GetListsOfType in Rest API)

以下示例显示如何检索特定类型的列表( 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...

使用REST API获取SharePoint列表的不同数据(Get distinct data of SharePoint list using REST API)

根据SharePoint REST请求中的使用OData查询操作,不支持grouping等操作。 解决方案是在从SharePoint REST服务返回JSON结果后应用分组。 如何使用jQuery从数组中获取不同的值 function groupBy(items,propertyName) { var result = []; $.each(items, function(index, item) { if ($.inArray(item[propertyName],...

SharePoint REST _api DateTimeRange查询(SharePoint REST _api DateTimeRange query)

看起来像格式化的问题。 您需要使用$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? $fil...

Sharepoint REST API和MVC AAD连接(Sharepoint REST api and MVC AAD connect)

搜索周围 图搜索API的功能有限,首先它只会搜索目标网站集(驱动器),其次我不确定目前是否支持按内容类型进行搜索(可能带有$ filter)。 ..) 但如果这符合你的约束条件,它可能是一个(更容易)的选项。 围绕auth&auth 在这两种情况下(图表或SharePoint搜索),当人们到达您的应用程序(asp.net MVC)时会发生什么:身份验证中间件负责将用户重定向到AAD,为您的应用程序获取访问令牌,将其重定向到您的应用程序应用程序使用该访问令牌在应用程序上创建会话。 我的观点是:在这一...

SharePoint 2013搜索REST API(SharePoint 2013 search REST API)

我终于找到了错误。 我使用的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 c...

使用rest api进行sharepoint搜索(sharepoint search using rest api)

我得到了答案。 只需将类“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 contai...

Sharepoint 2010博客 - 按类别订购休息查询(Sharepoint 2010 Blog - Order rest query by Category)

Category字段( PostCategory内部名称)是一个多选字段 ,在SharePoint REST中, 不支持将$orderby查询选项应用于此类型的字段。 但您可以使用JavaScript对返回的项目进行排序。 以下示例演示如何按Category字段订购Posts 。 这里有一个重要的注意事项: 由于Category字段是多选字段值,因此假设每个帖子只能指定一个类别 。 为此,引入了FirstCategoryTitle属性, FirstCategoryTitle属性表示帖子项中第一个类...

Sharepoint 2013 - 通过REST api仅获取上次批准的版本(Sharepoint 2013 - Fetch only last approved version through REST api)

以下是此问题的两种可能解决方案: 创建第二个列表,并在主列表上批准新项目或更新项目时让工作流程在此列表上创建或更新项目。 答:工作清单 - >新建或更改项目 - >工作流程 - >创建或更新清单B:生产清单上的项目 使用项目的唯一ID来检查列表B上是否已存在项目。 你可以在这里阅读第二个可能的解决方案: https : //sharepoint.stackexchange.com/questions/116921/distinguish-between-approved-and-not-appro...

getChanges Sharepoint rest API(getChanges Sharepoint rest API)

是列表和图书馆在一天结束时是一回事。 您可以通过剥离上述案例中的最后一个段(Items(1))从odata.editLink获取列表标题。 如果您调用该路径,它将为您提供列表与已修改项目/文件的详细信息。 如果您想要用户的详细信息,请调用/ _api / Web / lists / getbytitle('用户信息列表')/项目(EditorId)。 如果你想要项目/文件的路径调用odata.editlink并且返回的serverrelativeurl参数将具有它的路径,title将具有项目/文件...

相关文章

更多

Hadoop的I/O

1. 数据完整性:任何语言对IO的操作都要保持其数据的完整性。Hadoop当然希望数据在存储和处理中不 ...

Hadoop I/O系统介绍

看过很多Hadoop介绍或者是学习的帖子和文章,发现介绍Hadoop I/O系统的很少。很多文章都会介 ...

Hadoop1.0.4 HDFS I/O性能测试

分布式RDF查询引擎的项目需要在节点之间传输中间结果,考虑HDFS可以作为一个备选的传输媒介,于是对H ...

Java中如何用I/O流读取一个Word文档的内容?

BufferedReader br = new BufferedReader(new FileRead ...

O2O

啥是O2O?一句两句话解释不清楚,行业也没有统一的定义,O2O的英文全拼是Online To Offl ...

Bentley.STAAD.RCDC.V8i.04.01.01.03 1CD

1、Bentley Multiframe Advanced V8i SS3 17.00.02.10 W ...

《O'Reilly:深入HTML5应用开发》扫描版[PDF]

中文名: O'Reilly:深入HTML5应用开发 作者: (美)Anthony T. Hold ...

I18n的一个问题

升级了,2.2.2, 用了I18n. 问题来了。 以前model validation 出错的默认消 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本