Path: csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!87.79.20.101.MISMATCH!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder3.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.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'suggestions,': 0.07; 'method:': 0.09; 'subject:characters': 0.09; 'def': 0.12; 'finds': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'subject: \n ': 0.16; 'subject:windows': 0.16; 'wrote:': 0.18; 'help.': 0.21; 'seems': 0.21; 'import': 0.22; 'header:User- Agent:1': 0.23; 'header:In-Reply-To:1': 0.27; 'character': 0.29; 'work:': 0.31; 'probably': 0.32; 'everyone': 0.33; 'subject:from': 0.34; 'subject:with': 0.35; 'one,': 0.35; 'received:84': 0.35; 'doing': 0.36; 'thanks': 0.36; 'to:addr:python-list': 0.38; 'issue': 0.38; 'to:addr:python.org': 0.39; 'email addr:gmail.com': 0.63; 'header:Reply-To:1': 0.67; 'skip:w 30': 0.69; 'reply-to:no real name:2**0': 0.71; 'reply-to:addr:python.org': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=Vd3OYjZ9 c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=0kkAYlmtguIA:10 a=_yxm6v-lmbwA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=4HBy_2rajJ0A:10 a=pGLkceISAAAA:8 a=ngNvFRLq3j0qnCFoIQAA:9 a=wPNLvfGTeEIA:10 a=MSl-tDqOz04A:10 X-AUTH: mrabarnett:2500 Date: Wed, 18 Sep 2013 20:40:53 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Stripping characters from windows clipboard with win32clipboard from excel References: <13c19665-6dc9-49fe-88c8-52c643892eba@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org 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: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1379533259 news.xs4all.nl 15971 [2001:888:2000:d::a6]:56993 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54397 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]