Path: csiph.com!usenet.pasdenom.info!gegeweb.org!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'mrab': 0.05; 'suggestions,': 0.07; 'string': 0.09; 'defines': 0.09; 'library?': 0.09; 'method:': 0.09; 'null,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:characters': 0.09; 'windows,': 0.09; 'python': 0.11; 'def': 0.12; 'bug': 0.12; 'windows': 0.15; 'finds': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:windows': 0.16; 'wrote:': 0.18; 'help.': 0.21; 'seems': 0.21; 'example': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'defined': 0.27; 'header:X-Complaints-To:1': 0.27; 'character': 0.29; 'work:': 0.31; 'probably': 0.32; 'interface': 0.32; 'text': 0.33; 'everyone': 0.33; 'maybe': 0.34; 'subject:from': 0.34; 'subject:with': 0.35; 'one,': 0.35; 'doing': 0.36; 'charset:us- ascii': 0.36; 'thanks': 0.36; 'should': 0.36; 'somebody': 0.38; 'to:addr:python-list': 0.38; 'issue': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'first': 0.61; 'email addr:gmail.com': 0.63; 'skip:w 30': 0.69; 'ending': 0.78; 'excel,': 0.84; 'job;': 0.84; 'specs.': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re: Stripping characters from windows clipboard with win32clipboard from excel Date: Wed, 18 Sep 2013 20:13:20 +0000 (UTC) References: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> <523A01C5.4080705@mrabarnett.plus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 174.32.174.35 User-Agent: XPN/1.2.6 (Street Spirit ; Linux) 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1379535222 news.xs4all.nl 15935 [2001:888:2000:d::a6]:41204 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54401 On 18/9/2013 15:40, MRAB wrote: > On 18/09/2013 20:28, stephen.boulet@gmail.com wrote: >> Thanks to everyone for their help. Using everyone's suggestions, this seems to work: >> >> import win32clipboard, win32con >> >> def getclipboard(): >> win32clipboard.OpenClipboard() >> s = win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT) >> win32clipboard.CloseClipboard() >> if '\0' in s: >> s = s[:s.index('\0')] >> return s >> > That'll look for a null character and, if it finds one, then look for > it again. Of course, that probably isn't an issue in practice. > > However, an alternative way of doing it is to use the .partition method: > > return s.partition('\0')[0] So is the bug in Excel, in Windows, or in the Python library? Somebody is falling down on the job; if Windows defines the string as ending at the first null, then the Python interface should use that when defining the text defined with CF_UNICODETEXT. Or maybe it's an example of ill-defined Windows specs. -- DaveA