从列表项的末尾删除\ n

时间:2019-09-17 12:14:40

标签: python

我有此代码

await turnContext.SendActivityAsync(MessageFactory.Text($"Hello!" + Environment.NewLine + $"Trust you are well" + Environment.NewLine + $"Hope that you are having a good day" + Environment.NewLine + $"We are contacting you concerning lea access requests" + Environment.NewLine + $"Could you please review the following tasks if any and add the required information!"), cancellationToken);
//await turnContext.SendActivityAsync(MessageFactory.Text($"Please type ok to continue!"), cancellationToken);
await turnContext.SendActivityAsync(MessageFactory.Text("Could you please click on the below button to continue?"));

var card = new HeroCard
{
    //Text = "Could you please click on the below button to continue?",
    Buttons = new List<CardAction>
        {
            new CardAction(ActionTypes.ImBack, title: "lea access request", value: "lea access request"),
        },
};
var reply = MessageFactory.Attachment(card.ToAttachment());
await turnContext.SendActivityAsync(reply, cancellationToken);

问题在于,某些def return_not_existing_signals(list_of_signals,read_or_write) : not_used_produced_signals = [] #print(list_of_signals) if read_or_write =="read": file_to_create= "c:\\path\\read.txt" else: file_to_create = "c:\\path\\write.txt" for i in list_of_signals : i.replace('\n','') if not search_for_signals(i) : not_used_produced_signals.append(i) write_to_txt(not_used_produced_signals,file_to_create) def search_for_signals(name_of_signal): for filename in Path('c:\path').glob('**/*.h') : with open(filename) as f: if name_of_signal in f.read(): return True return False 的结尾是\ n(例如:test1234rwq4 \ n)

list_of_signals不起作用

2 个答案:

答案 0 :(得分:2)

来自docs

  

string.replace(s,old,new [,maxreplace])

     

返回字符串s的副本    ,所有出现的旧子字符串替换为新的 。如果可选   给定参数maxreplace,第一个出现的maxreplace是   替换。

因此,您需要这样做,

-keep

答案 1 :(得分:1)

strg = "Helllo\nwhatsup?"
New_strg = strg.replace('\n','')
print(New_strg)

输出:

  

Hellowhatsup?