Path: csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.net!feeder1.cambriumusenet.nl!feed.tweaknews.nl!85.12.40.138.MISMATCH!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'received:internal': 0.09; 'subject:characters': 0.09; 'python': 0.11; 'suggest': 0.14; 'incorrect': 0.16; 'message-id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:66.111.4.27': 0.16; 'received:messagingengine.com': 0.16; 'received:out3-smtp.messagingengine.com': 0.16; 'subject: \n ': 0.16; 'subject:windows': 0.16; 'utf8': 0.16; 'wrote:': 0.18; '(but': 0.19; 'not,': 0.20; "aren't": 0.24; 'bytes': 0.24; 'skip:e 30': 0.24; 'header:In-Reply-To:1': 0.27; 'to:2**1': 0.27; 'to:no real name:2**1': 0.29; "doesn't": 0.30; 'gives': 0.31; '13,': 0.31; 'sep': 0.31; 'fri,': 0.33; 'subject:from': 0.34; 'message.': 0.35; 'received:66': 0.35; 'subject:with': 0.35; 'but': 0.35; 'interact': 0.36; 'should': 0.36; 'received:10': 0.37; 'e.g.': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'remove': 0.60; 'from:no real name:2**0': 0.61; "you're": 0.61; 'first': 0.61; 'header:Message-Id:1': 0.63; 'email addr:gmail.com': 0.63; 'to:addr:gmail.com': 0.65; 'behavior': 0.77; 'pasting': 0.84; '2013,': 0.91 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.us; h= message-id:from:to:mime-version:content-transfer-encoding :content-type:in-reply-to:references:subject:date; s=mesmtp; bh= 8tpILBfOBVw5R492LoFG+u8yGAA=; b=syCFgtM4q32paI8yIlJb4F7k6wrvKuc2 JBiY9omTBJBuumA99FSJo9ar7w+yoOYsB3xG0AnyUJb3MQdP4xnqC7k1Oyo/P/Je AYlTCTBNwhXnXigMegwSaIIozYKok1Bly/vj9C2lMVzrlmSG/0zJQjUpegO7+MBG erpl6zlWTYs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:from:to:mime-version :content-transfer-encoding:content-type:in-reply-to:references :subject:date; s=smtpout; bh=8tpILBfOBVw5R492LoFG+u8yGAA=; b=N4k BH1I11Mr2+di9RBE3CaA/N8YqCfxTcWhkv09Ro+lyHGPxBM3JCSey30aEFHXp5ff grpu72rY90XJIdwHkMzc1/m7/Ctgoy8f1FFN386fGkx7mYJUluhji2BI2K0pbgtp 8ik9KyWOpXPQHWTTB7XQJcq1Fpde34knLCYZRTPI= X-Sasl-Enc: hYLXkDGRhh1aOHwKq5RiVq+I4oN95kyN4r9qREyUWa+v 1379088569 From: random832@fastmail.us To: stephen.boulet@gmail.com, python-list@python.org MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain X-Mailer: MessagingEngine.com Webmail Interface - ajax-d310b333 In-Reply-To: <12ce40fd-bb6e-4249-a38d-7521c27a2825@googlegroups.com> References: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> <74479771-2726-4a34-8fd6-531d64c5b7a5@googlegroups.com> <3PKdndBR7KeRF6_PnZ2dnUVZ_u6dnZ2d@westnet.com.au> <12ce40fd-bb6e-4249-a38d-7521c27a2825@googlegroups.com> Subject: Re: Stripping characters from windows clipboard with win32clipboard from excel Date: Fri, 13 Sep 2013 12:09:29 -0400 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1379088572 news.xs4all.nl 15894 [2001:888:2000:d::a6]:57787 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54122 On Fri, Sep 13, 2013, at 10:38, stephen.boulet@gmail.com wrote: > > Hm, that gives me a "Type str doesn't support the buffer API" message. > > Aha, I need to use str(s, encoding='utf8').rstrip('\0'). It's not a solution to your problem, but why aren't you using CF_UNICODETEXT, particularly if you're using python 3? And if you're not, utf8 is the incorrect encoding, you should be using encoding='mbcs' to interact with the CF_TEXT clipboard. Anyway, to match behavior found in other applications when pasting from the clipboard, I would suggest using: if s.contains('\0'): s = s[:s.index('\0')] Which will also remove non-null bytes after the first null (but if the clipboard contains these, it won't be pasted into e.g. notepad).