Re: Pasting code into the cmdline interpreter

2016-09-22 Thread Gregory Ewing
eryk sun wrote: if we see a read that returns less than the buffer size but doesn't end on a newline, then for a terminal, and only a terminal, I think we can infer Ctrl+D was typed and handle it as EOF. I don't think it would be wise to rely on that. There is no promise that any given read() c

Re: Pasting code into the cmdline interpreter

2016-09-22 Thread eryk sun
On Thu, Sep 22, 2016 at 3:21 PM, Random832 wrote: > On Thu, Sep 22, 2016, at 09:45, eryk sun wrote: > >> Yes, FileIO.readall continues making read() system calls until it sees >> an empty read. But if we know we're reading from a terminal, we should >> be able to assume that a read either consumes

Re: Pasting code into the cmdline interpreter

2016-09-22 Thread Random832
On Thu, Sep 22, 2016, at 09:45, eryk sun wrote: > On Thu, Sep 22, 2016 at 12:40 PM, Gregory Ewing > wrote: > > eryk sun wrote: > >> > >> Actually in a Unix terminal the cursor can also be at > >> the end of a line, but a bug in Python requires pressing Ctrl+D twice > >> in that case. > > > > I wou

Re: Pasting code into the cmdline interpreter

2016-09-22 Thread Veek M
eryk sun wrote: > On Thu, Sep 22, 2016 at 12:40 PM, Gregory Ewing > wrote: >> eryk sun wrote: >>> >>> Actually in a Unix terminal the cursor can also be at >>> the end of a line, but a bug in Python requires pressing Ctrl+D >>> twice in that case. >> >> I wouldn't call that a bug, rather it's a c

Re: Pasting code into the cmdline interpreter

2016-09-22 Thread eryk sun
On Thu, Sep 22, 2016 at 12:40 PM, Gregory Ewing wrote: > eryk sun wrote: >> >> Actually in a Unix terminal the cursor can also be at >> the end of a line, but a bug in Python requires pressing Ctrl+D twice >> in that case. > > I wouldn't call that a bug, rather it's a consequence of > what Ctrl-D

Re: Pasting code into the cmdline interpreter

2016-09-22 Thread Gregory Ewing
eryk sun wrote: Actually in a Unix terminal the cursor can also be at the end of a line, but a bug in Python requires pressing Ctrl+D twice in that case. I wouldn't call that a bug, rather it's a consequence of what Ctrl-D does. It doesn't really mean EOF, it means to send whatever the terminal

Re: Pasting code into the cmdline interpreter

2016-09-22 Thread Veek M
Ben Finney wrote: > Veek M writes: > >> Ben Finney wrote: >> >> > Since you are writing code into a module file, why not just run the >> > module from that file with the non-interactive Python interpreter? >> > >> It's part of a hexchat plugin/addon.. > > Which tells me that it still isn't app

Re: Pasting code into the cmdline interpreter

2016-09-22 Thread Veek M
eryk sun wrote: > On Thu, Sep 22, 2016 at 5:12 AM, Veek M wrote: >> 2. Blank lines in my code within the editor are perfectly acceptable >> for readability but they act as a block termination on cmd line. > > You can write a simple paste() function. For example: > > import sys > paste =

Re: Pasting code into the cmdline interpreter

2016-09-22 Thread Lawrence D’Oliveiro
On Thursday, September 22, 2016 at 5:12:13 PM UTC+12, Veek M wrote: > How do i deal with this - what's the best way to achieve what I'm trying > to do. If you want a scratchpad for trying out Python code, I can recommend Jupyter/IPython . -- https://mail.python.org/mailman/

Re: Pasting code into the cmdline interpreter

2016-09-22 Thread Steven D'Aprano
On Thursday 22 September 2016 17:42, eryk sun wrote: > On Thu, Sep 22, 2016 at 5:12 AM, Veek M wrote: >> 2. Blank lines in my code within the editor are perfectly acceptable for >> readability but they act as a block termination on cmd line. > > You can write a simple paste() function. For examp

Re: Pasting code into the cmdline interpreter

2016-09-22 Thread eryk sun
On Thu, Sep 22, 2016 at 5:12 AM, Veek M wrote: > 2. Blank lines in my code within the editor are perfectly acceptable for > readability but they act as a block termination on cmd line. You can write a simple paste() function. For example: import sys paste = lambda: exec(sys.stdin.read(),

Re: Pasting code into the cmdline interpreter

2016-09-21 Thread Ben Finney
Veek M writes: > Ben Finney wrote: > > > Since you are writing code into a module file, why not just run the > > module from that file with the non-interactive Python interpreter? > > > It's part of a hexchat plugin/addon.. Which tells me that it still isn't appropriate to copy-paste the code d

Re: Pasting code into the cmdline interpreter

2016-09-21 Thread Veek M
Ben Finney wrote: > Veek M writes: > >> 1. I had to turn on highlighting to catch mixed indent (which >> is a good thing anyways so this was resolved - not sure how tabs got >> in anyhow) > > The EditorConfig system is a growing consensus for configuring a code > base to instruct text editors

Re: Pasting code into the cmdline interpreter

2016-09-21 Thread Christian Gollwitzer
Am 22.09.16 um 07:12 schrieb Veek M: I wanted to test this piece of code which is Kate (editor) on the cmd line python >>> prompt: 2. Blank lines in my code within the editor are perfectly acceptable for readability but they act as a block termination on cmd line. So if i paste: tex_matches = re.

Re: Pasting code into the cmdline interpreter

2016-09-21 Thread Ben Finney
Veek M writes: > 1. I had to turn on highlighting to catch mixed indent (which is a > good thing anyways so this was resolved - not sure how tabs got in > anyhow) The EditorConfig system is a growing consensus for configuring a code base to instruct text editors not to mangle it. See the Edit