Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #94291

Re: Can I copy/paste Python code?

References <0f0c6018-50e7-4e95-a798-313d767ce177@googlegroups.com> <mailman.796.1437447312.3674.python-list@python.org> <moldt9$tmm$1@dont-email.me>
Date 2015-07-22 00:48 +1000
Subject Re: Can I copy/paste Python code?
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.816.1437490089.3674.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Jul 21, 2015 at 10:29 PM, Christian Gollwitzer <auriocus@gmx.de> wrote:
> On 21.07.2015 04:55, Chris Angelico wrote:
>>
>> On Tue, Jul 21, 2015 at 12:49 PM, ryguy7272 <ryanshuell@gmail.com> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Can I copy/paste Python code? ryguy7272 <ryanshuell@gmail.com> - 2015-07-20 19:49 -0700
  Re: Can I copy/paste Python code? Chris Angelico <rosuav@gmail.com> - 2015-07-21 12:55 +1000
    Re: Can I copy/paste Python code? Christian Gollwitzer <auriocus@gmx.de> - 2015-07-21 14:29 +0200
      Re: Can I copy/paste Python code? Chris Angelico <rosuav@gmail.com> - 2015-07-22 00:48 +1000
      Re: Can I copy/paste Python code? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-21 17:12 +0100
        Re: Can I copy/paste Python code? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-07-21 20:05 -0400
      Re: Can I copy/paste Python code? Laura Creighton <lac@openend.se> - 2015-07-21 19:25 +0200
        Re: Can I copy/paste Python code? Grant Edwards <invalid@invalid.invalid> - 2015-07-21 18:55 +0000
        Re: Can I copy/paste Python code? Steven D'Aprano <steve@pearwood.info> - 2015-07-22 10:45 +1000
          Re: Can I copy/paste Python code? Laura Creighton <lac@openend.se> - 2015-07-22 09:01 +0200
            Re: Can I copy/paste Python code? Grant Edwards <invalid@invalid.invalid> - 2015-07-22 13:54 +0000
              Re: Can I copy/paste Python code? Laura Creighton <lac@openend.se> - 2015-07-22 16:37 +0200
                Re: Can I copy/paste Python code? Grant Edwards <invalid@invalid.invalid> - 2015-07-22 14:53 +0000
                Re: Can I copy/paste Python code? Laura Creighton <lac@openend.se> - 2015-07-22 18:53 +0200
                Re: Can I copy/paste Python code? Christian Gollwitzer <auriocus@gmx.de> - 2015-07-22 23:23 +0200
      Re: Can I copy/paste Python code? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-21 20:58 +0100
        Re: Can I copy/paste Python code? Grant Edwards <invalid@invalid.invalid> - 2015-07-21 20:32 +0000
          Re: Can I copy/paste Python code? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-21 21:54 +0100
          Re: Can I copy/paste Python code? Emile van Sebille <emile@fenx.com> - 2015-07-21 14:03 -0700
            Re: Can I copy/paste Python code? Grant Edwards <invalid@invalid.invalid> - 2015-07-21 21:47 +0000
              Re: Can I copy/paste Python code? Emile van Sebille <emile@fenx.com> - 2015-07-21 15:35 -0700
                Re: Can I copy/paste Python code? Grant Edwards <invalid@invalid.invalid> - 2015-07-22 00:10 +0000
                Re: Can I copy/paste Python code? Emile van Sebille <emile@fenx.com> - 2015-07-22 09:49 -0700
                Re: Can I copy/paste Python code? Grant Edwards <invalid@invalid.invalid> - 2015-07-22 19:35 +0000
                Re: Can I copy/paste Python code? Emile van Sebille <emile@fenx.com> - 2015-07-22 14:39 -0700
                Re: [OT] Can I copy/paste Python code? Michael Torrie <torriem@gmail.com> - 2015-07-22 15:56 -0600
                Re: [OT] Can I copy/paste Python code? Grant Edwards <invalid@invalid.invalid> - 2015-07-22 22:50 +0000
                Re: [OT] Can I copy/paste Python code? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-07-23 15:39 +1000
                Re: Can I copy/paste Python code? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-07-23 15:22 +1000
                Re: Can I copy/paste Python code? Grant Edwards <invalid@invalid.invalid> - 2015-07-22 20:49 +0000
              Re: Can I copy/paste Python code? Michael Torrie <torriem@gmail.com> - 2015-07-21 16:36 -0600
                Re: Can I copy/paste Python code? Grant Edwards <invalid@invalid.invalid> - 2015-07-22 00:12 +0000
                Re: Can I copy/paste Python code? Michael Torrie <torriem@gmail.com> - 2015-07-21 19:03 -0600
                Re: Can I copy/paste Python code? Chris Angelico <rosuav@gmail.com> - 2015-07-22 11:12 +1000
              Re: Can I copy/paste Python code? Chris Angelico <rosuav@gmail.com> - 2015-07-22 10:04 +1000
                Re: Can I copy/paste Python code? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2015-07-22 10:55 +0300
                Re: Can I copy/paste Python code? Chris Angelico <rosuav@gmail.com> - 2015-07-22 18:13 +1000
      Re: Can I copy/paste Python code? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-22 08:47 +0100
  Re: Can I copy/paste Python code? Laura Creighton <lac@openend.se> - 2015-07-21 10:24 +0200
  Re: Can I copy/paste Python code? "Peter Heitzer" <peter.heitzer@rz.uni-regensburg.de> - 2015-07-21 08:40 +0000
  Re: Can I copy/paste Python code? ryguy7272 <ryanshuell@gmail.com> - 2015-07-21 08:18 -0700
  Re: Can I copy/paste Python code? Gene Heskett <gheskett@wdtv.com> - 2015-07-21 13:41 -0400

csiph-web