Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'subject:code': 0.07; 'width': 0.07; 'works.': 0.07; 'cc:addr :python-list': 0.09; 'received:openend.se': 0.09; 'received:theraft.openend.se': 0.09; 'python': 0.10; 'cc:addr:lac': 0.16; 'cc:addr:openend.se': 0.16; 'from:addr:lac': 0.16; 'from:addr:openend.se': 0.16; 'from:name:laura creighton': 0.16; 'message-id:@fido.openend.se': 0.16; 'received:89.233': 0.16; 'received:89.233.217': 0.16; 'received:89.233.217.133': 0.16; 'received:fido': 0.16; 'received:fido.openend.se': 0.16; 'tool.': 0.16; 'laura': 0.18; 'result,': 0.18; 'hack': 0.18; 'variable': 0.18; '2015': 0.20; 'cc:addr:python.org': 0.20; 'cc:2**1': 0.22; 'large,': 0.22; 'file.': 0.22; 'trying': 0.22; 'code,': 0.23; 'help.': 0.23; 'seems': 0.23; 'header:In-Reply- To:1': 0.24; 'all.': 0.24; 'mon,': 0.24; 'separate': 0.27; 'idea': 0.28; '-0700,': 0.29; 'received:se': 0.29; 'url:wikipedia': 0.29; 'cc:no real name:2**1': 0.29; 'convert': 0.29; "i'm": 0.30; 'subject:/': 0.30; 'url:wiki': 0.30; 'url:mailman': 0.30; 'work.': 0.30; 'code': 0.30; 'saves': 0.30; 'fixed': 0.31; 'run': 0.33; 'options': 0.33; 'url:python': 0.33; 'displayed': 0.33; 'url:listinfo': 0.34; 'file': 0.34; 'text': 0.35; 'sometimes': 0.35; 'but': 0.36; 'url:org': 0.36; 'lines': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'hundreds': 0.37; 'pdf': 0.37; 'charset:us-ascii': 0.37; 'doing': 0.38; 'version': 0.38; 'files': 0.38; 'test': 0.39; 'sure': 0.39; 'url:en': 0.39; 'url:mail': 0.40; 'some': 0.40; 'save': 0.60; 'your': 0.60; 'header:Message-Id:1': 0.61; 'back': 0.62; 'more': 0.63; 'jul': 0.72; 'received:89': 0.80; 'pdf.': 0.84 To: ryguy7272 cc: python-list@python.org, lac@openend.se From: Laura Creighton Subject: Re: Can I copy/paste Python code? In-Reply-To: Message from ryguy7272 of "Mon, 20 Jul 2015 19:49:56 -0700." <0f0c6018-50e7-4e95-a798-313d767ce177@googlegroups.com> References: <0f0c6018-50e7-4e95-a798-313d767ce177@googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <15993.1437467059.1@fido> Content-Transfer-Encoding: quoted-printable Date: Tue, 21 Jul 2015 10:24:19 +0200 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.3.9 (theraft.openend.se [89.233.217.130]); Tue, 21 Jul 2015 10:24:21 +0200 (CEST) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1437467069 news.xs4all.nl 2946 [2001:888:2000:d::a6]:40572 X-Complaints-To: abuse@xs4all.nl Path: csiph.com!usenet.pasdenom.info!news.stben.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Xref: csiph.com comp.lang.python:94275 In a message of Mon, 20 Jul 2015 19:49:56 -0700, ryguy7272 writes: >I'm trying to copy some Python code from a PDF book that I'm reading. I = want to test out the code, and I can copy it, but when I paste it into the= Shell, everything is all screwed up because of the indentation. Every tim= e I paste in any kind of code, it seems like everything is immediately lef= t-justified, and then nothing works. > >Any idea how to make this work easily? Without re-typing hundreds of lin= es of code... > >Thanks to all. >-- = >https://mail.python.org/mailman/listinfo/python-list What I do is run my pdf file through pdftotext https://en.wikipedia.org/wiki/Pdftotext and get a text version of the file. If the file is large, sometimes I just save the code I want to convert as separate pdf files and then convert them. Then I paste from the result, not the pdf. You want to give the -layout and -nopgbrk options to pdftotext. It's not perfect, but saves a lot of work. Make sure your pdf is writing your python code in a fixed width font before you try this, or it will be hopeless. If your python code is being displayed in the book in a variable width font, you will first have to hack your pdf to stop doing this, and then run it through the tool. Write back if you need more help. Laura