Re: detect interactivity

2010-01-03 Thread Lie Ryan
On 12/30/2009 11:25 PM, Roald de Vries wrote: Actually, performance is not much if an issue for what I want to do; it's mainly interest in 'how should I do this in general'. I'll just leave in all the code, and if it becomes a real issue, I'll separate the code over an interactive and a non-inter

Re: detect interactivity

2009-12-30 Thread Steven D'Aprano
On Wed, 30 Dec 2009 14:42:12 +0100, Vito 'ZeD' De Tullio wrote: > Steven D'Aprano wrote: > > >>> if I run 'python <<< "import sys; print(sys.ps1)"', I get an error. >> >> Of course you do, because you're not running interactively > > Excuse me, why do you say that? Two reasons. First, becaus

Re: detect interactivity

2009-12-30 Thread Vito 'ZeD' De Tullio
Steven D'Aprano wrote: >> if I run 'python <<< "import sys; print(sys.ps1)"', I get an error. > > Of course you do, because you're not running interactively Excuse me, why do you say that? -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list

Re: detect interactivity

2009-12-30 Thread Roald de Vries
On Dec 30, 2009, at 4:10 AM, Steve Holden wrote: Roald de Vries wrote: On Dec 30, 2009, at 2:28 AM, Dave Angel wrote: Roald de Vries wrote: On Dec 29, 2009, at 8:34 PM, Dave Angel wrote: Antoine Pitrou wrote: Le Tue, 29 Dec 2009 16:09:58 +0100, Roald de Vries a écrit : Dear all, Is it

Re: detect interactivity

2009-12-30 Thread Antoine Pitrou
Le Wed, 30 Dec 2009 03:33:18 +0100, Roald de Vries a écrit : > > I'm using a database, and want to use python interactively to manipulate > it. On the other hand, I also want to be able to use it non- > interactively. In that case, it would be a waste of CPU to load the > function/class definition

Re: detect interactivity

2009-12-29 Thread Dave Angel
Steve Holden wrote: Roald de Vries wrote: On Dec 30, 2009, at 2:28 AM, Dave Angel wrote: Roald de Vries wrote: mehow define a different set of functions??? I'm using a database, and want to use python interactively to manipulate it. On the other hand, I also want to be

Re: detect interactivity

2009-12-29 Thread Steven D'Aprano
On Wed, 30 Dec 2009 03:33:18 +0100, Roald de Vries wrote: > I'm using a database, and want to use python interactively to manipulate > it. On the other hand, I also want to be able to use it non- > interactively. In that case, it would be a waste of CPU to load the > function/class definitions mea

Re: detect interactivity

2009-12-29 Thread Steven D'Aprano
On Wed, 30 Dec 2009 03:26:20 +0100, Roald de Vries wrote: > On Dec 30, 2009, at 1:52 AM, Steven D'Aprano wrote: >> On Tue, 29 Dec 2009 16:09:58 +0100, Roald de Vries wrote: >> >>> Dear all, >>> >>> Is it possible for a Python script to detect whether it is running >>> interactively? It can be usef

Re: detect interactivity

2009-12-29 Thread Steve Holden
Roald de Vries wrote: > > On Dec 30, 2009, at 2:28 AM, Dave Angel wrote: > >> Roald de Vries wrote: >>> On Dec 29, 2009, at 8:34 PM, Dave Angel wrote: Antoine Pitrou wrote: > Le Tue, 29 Dec 2009 16:09:58 +0100, Roald de Vries a écrit : > > >> Dear all, >> >> Is it pos

Re: detect interactivity

2009-12-29 Thread Roald de Vries
On Dec 30, 2009, at 2:28 AM, Dave Angel wrote: Roald de Vries wrote: On Dec 29, 2009, at 8:34 PM, Dave Angel wrote: Antoine Pitrou wrote: Le Tue, 29 Dec 2009 16:09:58 +0100, Roald de Vries a écrit : Dear all, Is it possible for a Python script to detect whether it is running interactivel

Re: detect interactivity

2009-12-29 Thread Roald de Vries
On Dec 30, 2009, at 1:52 AM, Steven D'Aprano wrote: On Tue, 29 Dec 2009 16:09:58 +0100, Roald de Vries wrote: Dear all, Is it possible for a Python script to detect whether it is running interactively? It can be useful for e.g. defining functions that are only useful in interactive mode. Ah,

Re: detect interactivity

2009-12-29 Thread Dave Angel
Roald de Vries wrote: On Dec 29, 2009, at 8:34 PM, Dave Angel wrote: Antoine Pitrou wrote: Le Tue, 29 Dec 2009 16:09:58 +0100, Roald de Vries a écrit : Dear all, Is it possible for a Python script to detect whether it is running interactively? It can be useful for e.g. defining functions th

Re: detect interactivity

2009-12-29 Thread Steven D'Aprano
On Tue, 29 Dec 2009 16:09:58 +0100, Roald de Vries wrote: > Dear all, > > Is it possible for a Python script to detect whether it is running > interactively? It can be useful for e.g. defining functions that are > only useful in interactive mode. Ah, I should have looked more carefully at the do

Re: detect interactivity

2009-12-29 Thread Steven D'Aprano
On Tue, 29 Dec 2009 16:09:58 +0100, Roald de Vries wrote: > Dear all, > > Is it possible for a Python script to detect whether it is running > interactively? It can be useful for e.g. defining functions that are > only useful in interactive mode. Check __name__. It's set to '__main__' when runni

Re: detect interactivity

2009-12-29 Thread Roald de Vries
On Dec 29, 2009, at 8:34 PM, Dave Angel wrote: Antoine Pitrou wrote: Le Tue, 29 Dec 2009 16:09:58 +0100, Roald de Vries a écrit : Dear all, Is it possible for a Python script to detect whether it is running interactively? It can be useful for e.g. defining functions that are only useful in i

Re: detect interactivity

2009-12-29 Thread Dave Angel
Antoine Pitrou wrote: Le Tue, 29 Dec 2009 16:09:58 +0100, Roald de Vries a écrit : Dear all, Is it possible for a Python script to detect whether it is running interactively? It can be useful for e.g. defining functions that are only useful in interactive mode. Try the isatty() metho

Re: detect interactivity

2009-12-29 Thread Antoine Pitrou
Le Tue, 29 Dec 2009 16:09:58 +0100, Roald de Vries a écrit : > Dear all, > > Is it possible for a Python script to detect whether it is running > interactively? It can be useful for e.g. defining functions that are > only useful in interactive mode. Try the isatty() method (*) on e.g. stdin: $

detect interactivity

2009-12-29 Thread Roald de Vries
Dear all, Is it possible for a Python script to detect whether it is running interactively? It can be useful for e.g. defining functions that are only useful in interactive mode. Kind regards, Roald -- http://mail.python.org/mailman/listinfo/python-list