Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed7.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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'operator': 0.03; 'subject:Python': 0.05; 'used.': 0.05; '21,': 0.07; 'subject:code': 0.07; 'works.': 0.07; 'cc:addr:python-list': 0.09; 'situation.': 0.09; 'python': 0.10; 'itself.': 0.11; 'file,': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; "pdf's": 0.16; 'received:mail-ig0-x22a.google.com': 0.16; 'tabs': 0.16; 'wrote:': 0.16; 'string': 0.17; 'drawing': 0.18; 'creates': 0.18; '>>>': 0.20; 'together.': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'file.': 0.22; 'trying': 0.22; 'code,': 0.23; 'code.': 0.23; 'seems': 0.23; 'words': 0.24; 'header:In-Reply-To:1': 0.24; 'all.': 0.24; "i've": 0.25; "doesn't": 0.26; 'chris': 0.26; 'message-id:@mail.gmail.com': 0.27; 'data,': 0.27; 'idea': 0.28; 'indentation': 0.29; 'spaces': 0.29; 'typically': 0.29; "i'm": 0.30; 'subject:/': 0.30; 'code': 0.30; 'guess': 0.31; 'software,': 0.32; 'maybe': 0.33; 'belong': 0.33; 'limitations': 0.33; 'thanks!': 0.34; 'tue,': 0.34; 'file': 0.34; 'running': 0.34; 'received:google.com': 0.35; 'exist': 0.35; 'sometimes': 0.35; 'but': 0.36; 'there': 0.36; 'lines': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'operating': 0.37; 'hundreds': 0.37; 'pdf': 0.37; 'creation': 0.38; 'christian': 0.38; 'anything': 0.38; 'copying': 0.38; 'test': 0.39; 'sure': 0.39; 'format': 0.39; 'does': 0.39; 'where': 0.40; 'space': 0.40; 'some': 0.40; 'details,': 0.60; 'your': 0.60; 'leading': 0.61; 'documents': 0.61; 'eyes': 0.70; 'jul': 0.72; 'surprise': 0.72; 'special': 0.73; 'sounds': 0.76; 'actually,': 0.84; 'chrisa': 0.84; 'flaw': 0.84; 'gollwitzer': 0.84; 'mum': 0.84; 'to:none': 0.91; 'acrobat': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=m00d20b6KiWPoBtWOUxvWmOs59J0q3W8dymIVozyhes=; b=EPu567ewS5DPEplLKsZvAaS/vLYupMOMAvUyBeJAc3VOgKHpG/17PRAS+H7vE/fHnF Mu1CLJmq6lNBE0XggU9wi10cd2YK3TMEj4MSCb+Pkr64DsLqIWwHqEaSrzYSLTEYrcRK /XWvramQm6OnGn9bWeP9kQkx0k7CsgSU/BbtglIj6GZMZ6Uijx9IUuDbdpK7J1NlFNPu I20xOf4omIvWZB0nRWA08xPobP9zEY+HU5e1jUT60CUtuDDvAMlmTLv0GtJhG5H8eWuC GsLgY0BO6hPU0Ry5Cv7KF+OE2i6va1DDH6wO49yr9vsqMu4n7l9bRtHRzM4dPoX5YJhX 2dvQ== MIME-Version: 1.0 X-Received: by 10.50.136.194 with SMTP id qc2mr25195701igb.6.1437490086893; Tue, 21 Jul 2015 07:48:06 -0700 (PDT) In-Reply-To: References: <0f0c6018-50e7-4e95-a798-313d767ce177@googlegroups.com> Date: Wed, 22 Jul 2015 00:48:06 +1000 Subject: Re: Can I copy/paste Python code? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1437490089 news.xs4all.nl 2842 [2001:888:2000:d::a6]:44311 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:94291 On Tue, Jul 21, 2015 at 10:29 PM, Christian Gollwitzer wrote: > On 21.07.2015 04:55, Chris Angelico wrote: >> >> On Tue, Jul 21, 2015 at 12:49 PM, ryguy7272 wrote: >>> >>> 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 time I >>> paste in any kind of code, it seems like everything is immediately >>> left-justified, and then nothing works. >>> >>> Any idea how to make this work easily? Without re-typing hundreds of >>> lines of code... >> >> >> Sounds like a flaw in the PDF - it creates indentation in some way >> other than leading spaces/tabs. > > > PDF never uses tabs and spaces for indentation. In a PDF file, typically all > words are placed using a drawing operator individually, the space is made up > by your eyes when see the file. While space characters exist in fonts, they > are practically never used. Often even inside a word there are breaks, > because of kerning corrections. When copying the data, the PDF reader has to > guess where the word breaks are and how the strings belong together. Acrobat > does a good job, but fails in this special situation. Sometimes it even > fails for a narrow running font and copies the string without any word > breaks. Ah. I've never dug into PDF's internal details, but the above explanation completely doesn't surprise me. Tip, to document publishers: Don't use PDF for anything containing Python code. Thanks! Actually, maybe don't use PDF at all. I keep having to help my Mum deal with stupid problems with PDF documents she gets, and I'm never sure whether the fault is with the PDF creation software, the human operating said software, or limitations in the file format itself. ChrisA