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

2012-08-28 Thread Jerry Zhang
2012/8/28 Richard D. Moores > 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 ValueErr

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

2012-08-28 Thread Richard D. Moores
On Tue, Aug 28, 2012 at 12:13 AM, Jerry Zhang wrote: > > > 2012/8/28 Richard D. Moores > >> 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) #

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

2012-08-28 Thread Timo
Op 28-08-12 10:06, Richard D. Moores schreef: On Tue, Aug 28, 2012 at 12:13 AM, Jerry Zhang wrote: 2012/8/28 Richard D. Moores 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 =

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

2012-08-28 Thread Peter Otten
Timo wrote: > Op 28-08-12 10:06, Richard D. Moores schreef: >> On Tue, Aug 28, 2012 at 12:13 AM, Jerry Zhang >> wrote: >>> >>> 2012/8/28 Richard D. Moores >>> On Mon, Aug 27, 2012 at 6:33 PM, Japhy Bartlett wrote: > something like: > > def _validate_int(obj): >

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

2012-08-28 Thread Mark Lawrence
On 28/08/2012 05:13, Richard D. Moores wrote: 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('expec

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

2012-08-28 Thread Richard D. Moores
On Tue, Aug 28, 2012 at 1:21 AM, Timo wrote: > Op 28-08-12 10:06, Richard D. Moores schreef: >> What if I wanted 3., 1234., etc. to be considered ints, as they are by >> _validate_int() ? > > isinstance(3., (int, float)) > True > > Because 3. is a float, not int. And >>> isinstance(3.7, (i

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

2012-08-28 Thread Hugo Arts
On Tue, Aug 28, 2012 at 11:13 AM, Richard D. Moores wrote: > On Tue, Aug 28, 2012 at 1:21 AM, Timo wrote: > > Op 28-08-12 10:06, Richard D. Moores schreef: > > >> What if I wanted 3., 1234., etc. to be considered ints, as they are by > >> _validate_int() ? > > > > > isinstance(3., (int, flo

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

2012-08-28 Thread Peter Otten
Richard D. Moores wrote: > On Tue, Aug 28, 2012 at 1:21 AM, Timo wrote: >> Op 28-08-12 10:06, Richard D. Moores schreef: > >>> What if I wanted 3., 1234., etc. to be considered ints, as they are by >>> _validate_int() ? >> >> > isinstance(3., (int, float)) >> True >> >> Because 3. is a floa

[Tutor] Recursion always returns None

2012-08-28 Thread Dharmit Shah
Hello, I am trying to do the following : 1) Ask user for the length of the word that he'd like to guess (for hangman game). 2) Pick a random word from /usr/share/dict/words (which I understand is not the best choice for hangman). 3) Call a function that would pick a random word to proceed further

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

2012-08-28 Thread Wayne Werner
On Mon, 27 Aug 2012, Richard D. Moores wrote: 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

Re: [Tutor] Recursion always returns None

2012-08-28 Thread Hugo Arts
On Tue, Aug 28, 2012 at 1:23 PM, Dharmit Shah wrote: > Hello, > > I am trying to do the following : > > 1) Ask user for the length of the word that he'd like to guess (for > hangman game). > 2) Pick a random word from /usr/share/dict/words (which I understand > is not the best choice for hangman)

Re: [Tutor] Recursion always returns None

2012-08-28 Thread Steve Willoughby
On 28-Aug-12 04:23, Dharmit Shah wrote: Hello, I am trying to do the following : 1) Ask user for the length of the word that he'd like to guess (for hangman game). 2) Pick a random word from /usr/share/dict/words (which I understand is not the best choice for hangman). 3) Call a function that w

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

2012-08-28 Thread eryksun
On Tue, Aug 28, 2012 at 6:00 AM, Peter Otten <__pete...@web.de> wrote: > > Anyway here's an alternative implementation: > def vi(x): > ... if not isinstance(x, numbers.Number): > ... raise TypeError > ... if not int(x) == x: > ... raise ValueError You could tes

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

2012-08-28 Thread Peter Otten
eryksun wrote: > On Tue, Aug 28, 2012 at 6:00 AM, Peter Otten <__pete...@web.de> wrote: >> >> Anyway here's an alternative implementation: >> > def vi(x): >> ... if not isinstance(x, numbers.Number): >> ... raise TypeError >> ... if not int(x) == x: >> ... raise

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

2012-08-28 Thread eryksun
On Tue, Aug 28, 2012 at 9:08 AM, Peter Otten <__pete...@web.de> wrote: > > That would reject "floats with an integral value" and therefore doesn't > comply with the -- non-existing -- spec. Gotcha. >> >>> import numbers >> >>> isinstance("42", numbers.Integral) >> False >> >>> num

Re: [Tutor] Recursion always returns None

2012-08-28 Thread Dave Angel
On 08/28/2012 07:23 AM, Dharmit Shah wrote: > Hello, > > I am trying to do the following : > > 1) Ask user for the length of the word that he'd like to guess (for > hangman game). > 2) Pick a random word from /usr/share/dict/words (which I understand > is not the best choice for hangman). > 3) Call

Re: [Tutor] Recursion always returns None

2012-08-28 Thread Dharmit Shah
Hello, @Hugo Arts : Thank you! That was awesome to read. Thanks for the len() suggestion. @ Steve : Thank you. As suggested by Dave Angel, I am going to try the loop. And even before implementing it, I can feel that it's going to be more efficient than recursion. @Dave Angel : Thank you for the

Re: [Tutor] Recursion always returns None

2012-08-28 Thread Mark Lawrence
On 28/08/2012 16:51, Dharmit Shah wrote: @ Steve : Thank you. As suggested by Dave Angel, I am going to try the loop. And even before implementing it, I can feel that it's going to be more efficient than recursion. May I ask why you appear to be concerned with efficiency for a hangman game?

Re: [Tutor] Recursion always returns None

2012-08-28 Thread Alan Gauld
On 28/08/12 16:51, Dharmit Shah wrote: @Dave Angel : Thank you for the loop idea. It didn't strike me at all. For some reason some beginners seem to find recursion a natural pattern. Many others, including quite experienced programmers find it a mind bending concept. But as a general rule, wh

Re: [Tutor] Recursion always returns None

2012-08-28 Thread Steve Willoughby
On 28-Aug-12 09:03, Mark Lawrence wrote: On 28/08/2012 16:51, Dharmit Shah wrote: @ Steve : Thank you. As suggested by Dave Angel, I am going to try the loop. And even before implementing it, I can feel that it's going to be more efficient than recursion. May I ask why you appear to be conce

Re: [Tutor] Recursion always returns None

2012-08-28 Thread Steve Willoughby
On 28-Aug-12 09:13, Alan Gauld wrote: On 28/08/12 16:51, Dharmit Shah wrote: @Dave Angel : Thank you for the loop idea. It didn't strike me at all. For some reason some beginners seem to find recursion a natural pattern. There is a certain "hey, you can do that? That's cool!" factor when yo

[Tutor] Installing modules with easy_install

2012-08-28 Thread Ray Jones
I'm working on another Python replacement for a Bash script, and I ran into a need for enhanced time zone functions. Following directions I found on a web site, I did the following: # easy_install --upgrade pytz Searching for pytz Reading http://pypi.python.org/simple/pytz/ Reading http://pytz.sou

Re: [Tutor] Installing modules with easy_install

2012-08-28 Thread Joel Goldstick
On Tue, Aug 28, 2012 at 1:41 PM, Ray Jones wrote: > I'm working on another Python replacement for a Bash script, and I ran > into a need for enhanced time zone functions. Following directions I > found on a web site, I did the following: > > # easy_install --upgrade pytz > Searching for pytz > Rea

Re: [Tutor] Installing modules with easy_install

2012-08-28 Thread Peter Otten
Ray Jones wrote: > I'm working on another Python replacement for a Bash script, and I ran > into a need for enhanced time zone functions. Following directions I > found on a web site, I did the following: > > # easy_install --upgrade pytz > Searching for pytz > Reading http://pypi.python.org/simp

Re: [Tutor] Installing modules with easy_install

2012-08-28 Thread Ray Jones
On 08/28/2012 11:06 AM, Peter Otten wrote: > Ray Jones wrote: > >> I'm working on another Python replacement for a Bash script, and I ran >> into a need for enhanced time zone functions. Following directions I >> found on a web site, I did the following: >> >> # easy_install --upgrade pytz >> Searc

Re: [Tutor] Installing modules with easy_install

2012-08-28 Thread Steven D'Aprano
On 29/08/12 03:41, Ray Jones wrote: I'm working on another Python replacement for a Bash script, and I ran into a need for enhanced time zone functions. Following directions I found on a web site, I did the following: # easy_install --upgrade pytz [...] Everything I'm reading suggests that now

Re: [Tutor] Installing modules with easy_install

2012-08-28 Thread Peter Otten
Ray Jones wrote: > On 08/28/2012 11:06 AM, Peter Otten wrote: >> Ray Jones wrote: >> >>> I'm working on another Python replacement for a Bash script, and I ran >>> into a need for enhanced time zone functions. Following directions I >>> found on a web site, I did the following: >>> >>> # easy_inst

Re: [Tutor] Installing modules with easy_install

2012-08-28 Thread Ray Jones
On 08/28/2012 12:35 PM, Steven D'Aprano wrote: > On 29/08/12 03:41, Ray Jones wrote: >> I'm working on another Python replacement for a Bash script, and I ran >> into a need for enhanced time zone functions. Following directions I >> found on a web site, I did the following: >> >> # easy_install -

Re: [Tutor] Installing modules with easy_install

2012-08-28 Thread Ray Jones
On 08/28/2012 12:44 PM, Peter Otten wrote: > Ray Jones wrote: > >> On 08/28/2012 11:06 AM, Peter Otten wrote: >>> Ray Jones wrote: >>> I'm working on another Python replacement for a Bash script, and I ran into a need for enhanced time zone functions. Following directions I found on

Re: [Tutor] Installing modules with easy_install

2012-08-28 Thread eryksun
On Tue, Aug 28, 2012 at 2:39 PM, Ray Jones wrote: > >> Do you have multiple python installations on your machine? Do you run >> easy_install in one and ipython in another? > > Perhaps. But the module is not accessible from the 'python' shell, from > 'idle', or from iPython. > > As I peruse Synapti

Re: [Tutor] Installing modules with easy_install

2012-08-28 Thread Ray Jones
On 08/28/2012 12:35 PM, Steven D'Aprano wrote: > On 29/08/12 03:41, Ray Jones wrote: >> I'm working on another Python replacement for a Bash script, and I ran >> into a need for enhanced time zone functions. Following directions I >> found on a web site, I did the following: >> >> # easy_install --

Re: [Tutor] Installing modules with easy_install

2012-08-28 Thread Ray Jones
On 08/28/2012 12:52 PM, eryksun wrote: > On Tue, Aug 28, 2012 at 2:39 PM, Ray Jones wrote: >>> Do you have multiple python installations on your machine? Do you run >>> easy_install in one and ipython in another? >> Perhaps. But the module is not accessible from the 'python' shell, from >> 'idle',

Re: [Tutor] Installing modules with easy_install

2012-08-28 Thread eryksun
On Tue, Aug 28, 2012 at 4:00 PM, Ray Jones wrote: > > Oops. No, I see that /usr/local/lib/python2.7/dist-packages is included > in the sys.path. Now what? Good, but does sys.path contain /usr/local/lib/python2.7/dist-packages/pytz-2012d-py2.7.egg? ___ T

Re: [Tutor] Installing modules with easy_install

2012-08-28 Thread Ray Jones
On 08/28/2012 01:11 PM, eryksun wrote: > On Tue, Aug 28, 2012 at 4:00 PM, Ray Jones wrote: >> Oops. No, I see that /usr/local/lib/python2.7/dist-packages is included >> in the sys.path. Now what? > Good, but does sys.path contain > /usr/local/lib/python2.7/dist-packages/pytz-2012d-py2.7.egg? No.

Re: [Tutor] Installing modules with easy_install

2012-08-28 Thread Ray Jones
On 08/28/2012 01:11 PM, eryksun wrote: > On Tue, Aug 28, 2012 at 4:00 PM, Ray Jones wrote: >> Oops. No, I see that /usr/local/lib/python2.7/dist-packages is included >> in the sys.path. Now what? > Good, but does sys.path contain > /usr/local/lib/python2.7/dist-packages/pytz-2012d-py2.7.egg? More

Re: [Tutor] Installing modules with easy_install

2012-08-28 Thread Emile van Sebille
On 8/28/2012 1:17 PM Ray Jones said... On 08/28/2012 01:11 PM, eryksun wrote: On Tue, Aug 28, 2012 at 4:00 PM, Ray Jones wrote: Oops. No, I see that /usr/local/lib/python2.7/dist-packages is included in the sys.path. Now what? Good, but does sys.path contain /usr/local/lib/python2.7/dist-pack

Re: [Tutor] Installing modules with easy_install

2012-08-28 Thread Ray Jones
On 08/28/2012 01:35 PM, Emile van Sebille wrote: > On 8/28/2012 1:17 PM Ray Jones said... >> On 08/28/2012 01:11 PM, eryksun wrote: >>> On Tue, Aug 28, 2012 at 4:00 PM, Ray Jones wrote: Oops. No, I see that /usr/local/lib/python2.7/dist-packages is included in the sys.path. Now what

Re: [Tutor] Recursion always returns None

2012-08-28 Thread Alan Gauld
On 28/08/12 17:34, Steve Willoughby wrote: For some reason some beginners seem to find recursion a natural pattern. There is a certain "hey, you can do that? That's cool!" factor when you first discover recursion. My point was that it seems to be a natural idea for many beginners, they dis

Re: [Tutor] Recursion always returns None

2012-08-28 Thread Joel Goldstick
On Tue, Aug 28, 2012 at 5:14 PM, Alan Gauld wrote: > On 28/08/12 17:34, Steve Willoughby wrote: >>> For some reason some beginners seem to find recursion a natural pattern. >> >> >> There is a certain "hey, you can do that? That's cool!" factor when you >> first discover recursion. > > >

Re: [Tutor] Installing modules with easy_install

2012-08-28 Thread Emile van Sebille
On 8/28/2012 1:48 PM Ray Jones said... On 08/28/2012 01:35 PM, Emile van Sebille wrote: You installed this with easy_install, so the version of python therein referenced is the same one that now should have access to it. Try : which easy_install then cat the result. The first line points t

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

2012-08-28 Thread Benjamin Fishbein
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 than one script at a time. Do you know if there's a way to do this? Or do I need to buy a second computer? Thanks, Ben

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

2012-08-28 Thread Marc Tompkins
On Tue, Aug 28, 2012 at 3: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 than one script at a time. Do you know if there's a > way to

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

2012-08-28 Thread Ray Jones
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 than one script at a time. Do you know if there's a way to do this?

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

2012-08-28 Thread Brian van den Broek
On 28 Aug 2012 18:33, "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 than one script at a time. Do you know if there's a way to do this? Or

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

2012-08-28 Thread Ben Fishbein
I'm on a Mac. Using Lion. I just tried opening the terminal and typing "python." And I'm able to open several terminal windows this way. I think this should be able to run many programs simultaneously. Thanks for your help. -Ben On Tue, Aug 28, 2012 at 6:04 PM, Brian van den Broek < brian.van.den

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

2012-08-28 Thread Ben Fishbein
Stupid question: how do I run a program from the terminal? I've always just gone to the drop down menu and clicked run to do it in idle. On Tue, Aug 28, 2012 at 6:17 PM, Ben Fishbein wrote: > I'm on a Mac. Using Lion. I just tried opening the terminal and typing > "python." And I'm able to open

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

2012-08-28 Thread Dave Angel
On 08/28/2012 07:19 PM, Ben Fishbein wrote: > Stupid question: how do I run a program from the terminal? I've always just > gone to the drop down menu and clicked run to do it in idle. > > Haven't you noticed that the correct method of posting on this forum is to put your remarks AFTER the part yo

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

2012-08-28 Thread Steven D'Aprano
On 29/08/12 08:30, 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 than one script at a time. Then don't use IDLE. IDLE is for running code intera

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

2012-08-28 Thread akleider
> 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 than one script at a time. Do you know if there's >> a way to do