Re: [Tutor] Why begin a function name with an underscore

2012-08-29 Thread Steven D'Aprano
On 30/08/12 05:39, Japhy Bartlett wrote: If you tried to check in code like this: def _validate_int(obj): """Raise an exception if obj is not an integer.""" m = int(obj + 0) # May raise TypeError. if obj != m: raise ValueError('expected an integer but got %r' % obj

Re: [Tutor] Why begin a function name with an underscore

2012-08-29 Thread Steven D'Aprano
On 28/08/12 21:24, Wayne Werner wrote: On Mon, 27 Aug 2012, Richard D. Moores wrote: What the best way to test if something's an integer? try: whatever_you_want(supposed_integer) except ValueError: print("Oops, that wasn't an integer! Please try again") That's usually the best way..

Re: [Tutor] Why begin a function name with an underscore

2012-08-29 Thread Steven D'Aprano
On 28/08/12 20:00, Peter Otten wrote: [...] The differences to _validate_int() are subtle: class S(str): ... def __eq__(self, other): return True ... def __ne__(self, other): return False ... def __add__(self, other): return self ... vi(S("42")) Traceback (most recent call last):

Re: [Tutor] Why begin a function name with an underscore

2012-08-29 Thread Steven D'Aprano
On 28/08/12 19:02, Peter Otten wrote: Personally, I'm a big fan of ducktyping, so I would probably remove the check completely and live with the consequences: >>> pyprimes._validate_int = lambda x: None >>> pyprimes.isprime_naive(8.5) True garbage-in, garbage-out -- so what. Duck-typing

Re: [Tutor] running more than one python program at the same time

2012-08-29 Thread Marc Tompkins
On Tue, Aug 28, 2012 at 7:35 PM, Steven D'Aprano wrote: In Windows, that is the DOS prompt -- either cmd.com or command.exe, I > never remember which one is which. I'm pretty sure that was intentional, but just in case... In MS-DOS/PC-DOS, and in 16-bit versions of Windows (up to Windows 98/Me,

Re: [Tutor] Why begin a function name with an underscore

2012-08-29 Thread Steven D'Aprano
On Mon, Aug 27, 2012 at 6:33 PM, Japhy Bartlett wrote: something like: def _validate_int(obj): """Raise an exception if obj is not an integer.""" m = int(obj + 0) # May raise TypeError. if obj != m: raise ValueError('expected an integer but got %r' % obj) is a really

Re: [Tutor] Why begin a function name with an underscore

2012-08-29 Thread Steven D'Aprano
On 28/08/12 10:26, Richard D. Moores wrote: I've been going through Steven D'Aprano's pyprimes () and have many questions. One is why begin a function name with an underscore. He has several functions that do this. Two are: [...] I'm stealing these f

Re: [Tutor] running more than one python program at the same time

2012-08-29 Thread William R. Wing (Bill Wing)
On Aug 28, 2012, at 11:28 PM, aklei...@sonic.net wrote: >> On 08/28/2012 03:30 PM, Benjamin Fishbein wrote: >>> Hello, >>> I wrote a program that I want to have running 24/7. But the problem is >>> that I also want to write and run other programs. I'm using Idle and it >>> won't let me run more th

Re: [Tutor] running more than one python program at the same time

2012-08-29 Thread Alan Gauld
On 29/08/12 01:09, Dave Angel wrote: On 08/28/2012 07:19 PM, Ben Fishbein wrote: Stupid question: how do I run a program from the terminal? Ben@mymachine:~$ python mydir/myscript.py If the script takes arguments, you'd put them after the script name. If it doesn't take arguments you can do