python pyparsing string:A,b,b,b,A,b,b,b * [关闭](python pyparsing string: A,b,b,b,A,b,b,b* [closed])
我有一个疯狂的问题。
我试图使用pyparsing来解析这样的事情:(点是不重要的压缩文本)
...... A B ....... B ....... ...... A B ....... B .......
我需要的是这样的:(将A和B元素连接到一个列表中)
[ [ [A],[B,B] ], [ [A],[B,B] ] , ...]
这是我的代码不起作用,只返回第一个[A]
table = pyparsing.OneOrMore(pyparsing.Group(A + (pyparsing.OneOrMore(pyparsing.Group(B) | pyparsing.SkipTo(B).suppress()))) | pyparsing.SkipTo(A).suppress())
我已经将这个pyparsing解决成这样的列表:
[ [A],[B],[B], [A],[B],[B] , ...]
但这是不可接受的,因为A和B元素没有直接连接在一个列表中。
值得一提的是
table1 = pyparsing.ZeroOrMore(pyparsing.Group(A) | pyparsing.SkipTo(A).suppress()) table2 = pyparsing.ZeroOrMore(pyparsing.Group(B) | pyparsing.SkipTo(B).suppress())
工作并返回所有A元素和B元素的列表。
I have a crazy problem.
I am trying to use pyparsing to parse something like this: (dots are unimportant suppressed text)
...... A B ....... B ....... ...... A B ....... B .......
What I need is something like this: (to connect A and B element into one list)
[ [ [A],[B,B] ], [ [A],[B,B] ] , ...]
This is my code which does not work and only returns the first [A]
table = pyparsing.OneOrMore(pyparsing.Group(A + (pyparsing.OneOrMore(pyparsing.Group(B) | pyparsing.SkipTo(B).suppress()))) | pyparsing.SkipTo(A).suppress())
I have already solved this pyparsing into a list like this:
[ [A],[B],[B], [A],[B],[B] , ...]
But this was not acceptable, since the A and B elements were not directly connected in one list.
Worth mentioning is that
table1 = pyparsing.ZeroOrMore(pyparsing.Group(A) | pyparsing.SkipTo(A).suppress()) table2 = pyparsing.ZeroOrMore(pyparsing.Group(B) | pyparsing.SkipTo(B).suppress())
works and return a list of all A elements and B elements.
原文:https://stackoverflow.com/questions/12402239
最满意答案
我想回答我自己的问题:我认为我找到了一个合理的解决方案。
我不会在函数内部处理任何异常,我是从外部做的。
private string GetSMTPAddressByFolderItem(Outlook.MAPIFolder mapiFolder) { string PR_MAILBOX_OWNER_ENTRYID = @"http://schemas.microsoft.com/mapi/proptag/0x661B0102"; string PR_SMTP_ADDRESS = @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E"; Outlook.Store store = null; Outlook.NameSpace ns = null; Outlook.AddressEntry sender = null; Outlook._ExchangeUser exchUser = null; try { if (mapiFolder == null) { return null; } // Get the parent store. store = mapiFolder.Store; string storeOwnerEntryId = store.PropertyAccessor.BinaryToString(store.PropertyAccessor.GetProperty(PR_MAILBOX_OWNER_ENTRYID)) as string; ns = Application.GetNamespace(Constants.OL_NAMESPACE); // i.e. "MAPI" sender = ns.GetAddressEntryFromID(storeOwnerEntryId); if (sender != null) { if (sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry || sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry) { exchUser = sender.GetExchangeUser(); if (exchUser != null) { return exchUser.PrimarySmtpAddress; } else { return null; } } else { return sender.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS) as string; } } return null; } finally { if (ns != null) { Marshal.ReleaseComObject(ns); ns = null; } if (store != null) { Marshal.ReleaseComObject(store); store = null; } if (sender != null) { Marshal.ReleaseComObject(sender); sender = null; } if (exchUser != null) { Marshal.ReleaseComObject(exchUser); exchUser = null; } } }
I like to answer my own questions: I think that I've found a plausible solution.
I do not treat any exceptions inside the function, I do that from outside.
private string GetSMTPAddressByFolderItem(Outlook.MAPIFolder mapiFolder) { string PR_MAILBOX_OWNER_ENTRYID = @"http://schemas.microsoft.com/mapi/proptag/0x661B0102"; string PR_SMTP_ADDRESS = @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E"; Outlook.Store store = null; Outlook.NameSpace ns = null; Outlook.AddressEntry sender = null; Outlook._ExchangeUser exchUser = null; try { if (mapiFolder == null) { return null; } // Get the parent store. store = mapiFolder.Store; string storeOwnerEntryId = store.PropertyAccessor.BinaryToString(store.PropertyAccessor.GetProperty(PR_MAILBOX_OWNER_ENTRYID)) as string; ns = Application.GetNamespace(Constants.OL_NAMESPACE); // i.e. "MAPI" sender = ns.GetAddressEntryFromID(storeOwnerEntryId); if (sender != null) { if (sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry || sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry) { exchUser = sender.GetExchangeUser(); if (exchUser != null) { return exchUser.PrimarySmtpAddress; } else { return null; } } else { return sender.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS) as string; } } return null; } finally { if (ns != null) { Marshal.ReleaseComObject(ns); ns = null; } if (store != null) { Marshal.ReleaseComObject(store); store = null; } if (sender != null) { Marshal.ReleaseComObject(sender); sender = null; } if (exchUser != null) { Marshal.ReleaseComObject(exchUser); exchUser = null; } } }
相关问答
更多-
您应该将Item转换为EmailMessage ,然后您可以查看From属性。 例如: var mailItems = findResults.Where(x => x is EmailMessage).Cast
().ToList(); foreach (EmailMessage item in mailItems) { Console.WriteLine(item.From.Address); } You should cast the Item to a Ema ... -
使用GC.Collect(),我能够强制程序清理以前的对象/调用Outlook。 我知道调用GC.Collect()不是最好的主意,但我认为它符合此处给出的标准: http : //blogs.msdn.com/b/ricom/archive/2004/11/29/271829.aspx 我认为问题在于,我正在生成许多请求以打开许多不同的电子邮件,垃圾收集通常随机发生,它不会发生得足够快,所以当我达到我的限制垃圾收集需要发生时。 问题是在我这样做之前没有发生这种情况我需要经常调用GC.Collect()来确 ...
-
假设 发件人子文件夹将位于收件箱下两层,但不在单个父文件夹下(即,“Doe,John”可能出现在Folder1下的Folder1和“Doe,Jane”下) 所有应由宏处理的电子邮件在执行之前都会被选中 该代码不应为缺少的发件人创建子文件夹 - 因为有多个可能的“父”文件夹 - 但应输出包含缺少的发件人文件夹列表的邮件 触发发件人姓名结尾的条件: 在空格之后或之前的连字符(即“Doe,John-US”=“Doe,John”和“Huntington-Whiteley,Rosie-CAN”= Huntington ...
-
以下代码是问题: _wrappedFolder.Items.ItemAdd +=Items_ItemAdd; _wrappedFolder.Items.ItemRemove += Items_ItemRemove; 触发事件的对象必须是活动的 - 在您的情况下,您在从_wrappedFolder.Items属性返回的隐式变量上设置事件处理程序 - 一旦GC释放该隐式变量,就不会触发任何事件。 在类级别声明Items对象以确保它保持引用和活动状态。 The following ...
-
Outlook 2010 VBA - 单击邮件时将发件人添加到联系人(Outlook 2010 VBA - Add sender to contacts when i click on a mail)[2023-06-17]
解决方案(包括测试例程)可能如下所示:(假设我们只考虑外部SMTP邮件。调整联系人文件夹的路径并添加更多错误检查!) Option Explicit Private Declare Function GetTickCount Lib "kernel32.dll" () As Long Sub AutoContactMessageRule(newMail As Outlook.mailItem) ' "script" routine to be called for each incoming ... -
在Outlook VSTO +阅读邮件提示中获取收件人的电子邮件地址(Get email address of a recipient in Outlook VSTO + Read MailTips)[2022-08-04]
Outlook对象模型不提供任何用于阅读邮件提示的内容。 请尝试使用以下代码: private string GetSenderSMTPAddress(Outlook.MailItem mail) { string PR_SMTP_ADDRESS = @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E"; if (mail == null) { throw new ArgumentNullExce ... -
基于您需要使用的MailItem文档 [SenderEmailAddress]用于发件人的电子邮件地址 要么 [SenderName]表示发件人的显示名称 您还应注意,属性名称区分大小写。 Based on the MailItem documentation you need to use [SenderEmailAddress] for the e-mail address of the sender or [SenderName] for the display name of the sender ...
-
我想回答我自己的问题:我认为我找到了一个合理的解决方案。 我不会在函数内部处理任何异常,我是从外部做的。 private string GetSMTPAddressByFolderItem(Outlook.MAPIFolder mapiFolder) { string PR_MAILBOX_OWNER_ENTRYID = @"http://schemas.microsoft.com/mapi/proptag/0x661B0102"; string PR_SMTP_A ...
-
查看BeforeItemMove以防止用户将项目移动到您的文件夹中。 此事件需要附加到您有兴趣观看的每个文件夹 - 我没有注意到的全局BeforeItemMove 。 您必须递归迭代每个邮箱文件夹或锁定到Explorer.FolderSwitch并附加您的项侦听器。 FolderSwitch有一些限制,因为您仍然可以通过Inspector Ribbon,OWA或EWS移动项目而无需切换文件夹。 要阻止用户重命名文件夹,可以使用StorageItem保留通过文件夹上下文父文件夹的FolderChange实现的 ...
-
如何使用outlook 2010/13发送的消息中设置发件人姓名?(How to set sender name in message sent using outlook 2010/13 ?
) [2023-03-24]配置文件中使用了哪种MAPI提供程序? 它是sn Exchange服务器吗? 还是POP3 / SMTP帐户? 如果您使用IOlkAccountManager查看配置文件( OutlookSpy会向您显示),请oyu查看预期的数据吗? After rounds of discussions with Dmitry. I was able to solve my problem as following - I already had LeagcyDN or exchange name of the user ...