Re: [Tutor] Data persistence problem

2013-06-23 Thread Fábio Santos
On 21 Jun 2013 07:36, "Arijit Ukil" wrote: > > I have following random number generation function > > def rand_int (): > rand_num = int(math.ceil (random.random()*1000)) > return rand_num > > I like to make the value of rand_num (return of rand_int) static/ unchanged after first call even

Re: [Tutor] Data persistence problem

2013-06-22 Thread Asokan Pichai
On Sun, Jun 23, 2013 at 2:45 AM, Mark Lawrence wrote: > On 22/06/2013 19:29, Jim Mooney wrote: > >> On 22 June 2013 04:00, Steven D'Aprano wrote: >> >> >> Speaking of Java, I get a kick out of this article and love to link to >>> it on >>> every possible opportunity: >>> >>> http://steve-yegge.b

Re: [Tutor] Data persistence problem

2013-06-22 Thread Mark Lawrence
On 22/06/2013 19:29, Jim Mooney wrote: On 22 June 2013 04:00, Steven D'Aprano wrote: Speaking of Java, I get a kick out of this article and love to link to it on every possible opportunity: http://steve-yegge.blogspot.com.au/2006/03/execution-in-kingdom-of-nouns.html Funny. Speaking of Jav

Re: [Tutor] Data persistence problem

2013-06-22 Thread Alan Gauld
On 22/06/13 12:00, Steven D'Aprano wrote: Speaking of Java, I get a kick out of this article and love to link to it on every possible opportunity: http://steve-yegge.blogspot.com.au/2006/03/execution-in-kingdom-of-nouns.html This could get seriously OT here... I found that an interesting bl

Re: [Tutor] Data persistence problem

2013-06-22 Thread Jim Mooney
On 22 June 2013 04:00, Steven D'Aprano wrote: > Speaking of Java, I get a kick out of this article and love to link to it on > every possible opportunity: > > http://steve-yegge.blogspot.com.au/2006/03/execution-in-kingdom-of-nouns.html Funny. Speaking of Java, I saw a used book on design patte

Re: [Tutor] Data persistence problem

2013-06-22 Thread Steven D'Aprano
On 22/06/13 12:26, Jim Mooney wrote: On 21 June 2013 16:56, ALAN GAULD wrote: if isinstance(dict(),typein): try: newdict = dict(zip(dl[::2],dl[1::2])) except TypeError: raise ValueError("input lists must be an even length") Not sure why TypeError and ValueError is used. I would

Re: [Tutor] Data persistence problem

2013-06-22 Thread Steven D'Aprano
On 22/06/13 09:00, Jim Mooney wrote: On 21 June 2013 14:59, ALAN GAULD wrote: Give us a clue, show us your code! I was hoping you wouldn't say that since it's another of my insane Lazy Typer programs to avoid typing, which are no doubt considered frivolous. Although I'm learning a lot doing

Re: [Tutor] Data persistence problem

2013-06-22 Thread Steven D'Aprano
On 22/06/13 11:10, Jim Mooney wrote: The ultimate in laziness would be to get the program to append to itself so I,don't have to cut and paste from the interpreter, but I'm running into some tacky problems. Although some of them are from the IDE. But others might be from the OS, and there are di

Re: [Tutor] Data persistence problem

2013-06-22 Thread Steven D'Aprano
On 22/06/13 00:32, Wolfgang Maier wrote: Arijit Ukil tcs.com> writes: I have following random number generation function def rand_int (): rand_num = int(math.ceil (random.random()*1000)) return rand_num I like to make the value of rand_num (return of rand_int) static/ unchanged afte

Re: [Tutor] Data persistence problem

2013-06-22 Thread Alan Gauld
On 22/06/13 03:26, Jim Mooney wrote: if isinstance(dict(),typein): try: newdict = dict(zip(dl[::2],dl[1::2])) except TypeError: raise ValueError("input lists must be an even length") Not sure why TypeError and ValueError is used. I used them because that's what I got in my testi

Re: [Tutor] Data persistence problem

2013-06-21 Thread Jim Mooney
On 21 June 2013 16:56, ALAN GAULD wrote: > if isinstance(dict(),typein): >try: newdict = dict(zip(dl[::2],dl[1::2])) >except TypeError: > raise ValueError("input lists must be an even length") Not sure why TypeError and ValueError is used. I would have thought StopIteration but expl

Re: [Tutor] Data persistence problem

2013-06-21 Thread Jim Mooney
On 21 June 2013 16:56, ALAN GAULD wrote: > > But that doesn't answer your question about incrementing the globals! :-) > To me it looks from your sample data like it is working! Good tips, though. Those sneaky zips are useful ;') Yes, the globals works fine. I just wondered if there was a way

Re: [Tutor] Data persistence problem

2013-06-21 Thread ALAN GAULD
 Just a wee thought:     if isinstance(dict(), typein): >        newdict = {} >        dl = instring.split() >        if len(dl) % 2 != 0: raise Exception ("list entries must be >even") # so they match >        for idx in range(0,len(dl),2): >            newdict[dl[idx]] = dl[idx+1] >The for loo

Re: [Tutor] Data persistence problem

2013-06-21 Thread Jim Mooney
On 21 June 2013 14:59, ALAN GAULD wrote: > > Give us a clue, show us your code! I was hoping you wouldn't say that since it's another of my insane Lazy Typer programs to avoid typing, which are no doubt considered frivolous. Although I'm learning a lot doing them ;') Okay, I have a snippet that

Re: [Tutor] Data persistence problem

2013-06-21 Thread ALAN GAULD
> ... I need to increment three different numbers that will > persist in the function. I tried a few examples I saw but I keep > getting the same number, so I'm doing something wrong Give us a clue, show us your code!   Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk/___

Re: [Tutor] Data persistence problem

2013-06-21 Thread Jim Mooney
On 21 June 2013 00:06, Alan Gauld wrote: > Or if you really don't like globals you could create > a generator function: Similar problem, by coincidence. Except I need a generator in a function to increment a variable each time the function is called, instead of giving it the same value every tim

Re: [Tutor] Data persistence problem

2013-06-21 Thread Wolfgang Maier
Arijit Ukil tcs.com> writes: > > I have following random number generation > function > def > rand_int (): >     rand_num = int(math.ceil > (random.random()*1000)) >     return > rand_num > I like to make the value of rand_num > (return of rand_int) static/ unchanged after first call even if it

Re: [Tutor] Data persistence problem

2013-06-21 Thread Dave Angel
On 06/21/2013 02:21 AM, Arijit Ukil wrote: I have following random number generation function def rand_int (): rand_num = int(math.ceil (random.random()*1000)) return rand_num I like to make the value of rand_num (return of rand_int) static/ unchanged after first call even if it is ca

Re: [Tutor] Data persistence problem

2013-06-21 Thread Peter Otten
Alan Gauld wrote: > rand_num = None > > def rand_int(): > global rand_num > if not rand_num: This will not recognize the (unlikely but possible) case that random.random() returns 0.0. So you better check for None explicitly if rand_num is None: >rand_num = int(math.ceil (

Re: [Tutor] Data persistence problem

2013-06-21 Thread Wolfgang Maier
Alan Gauld btinternet.com> writes: > > On 21/06/13 07:21, Arijit Ukil wrote: > > I have following random number generation function > > > > def*rand_int* (): > > rand_num = int(math.ceil (random.random()*1000)) > > returnrand_num > > > > I like to make the value of rand_num (return of rand_

Re: [Tutor] Data persistence problem

2013-06-21 Thread Alan Gauld
On 21/06/13 07:21, Arijit Ukil wrote: I have following random number generation function def*rand_int* (): rand_num = int(math.ceil (random.random()*1000)) returnrand_num I like to make the value of rand_num (return of rand_int) static/ unchanged after first call even if it is called multi

[Tutor] Data persistence problem

2013-06-20 Thread Arijit Ukil
I have following random number generation function def rand_int (): rand_num = int(math.ceil (random.random()*1000)) return rand_num I like to make the value of rand_num (return of rand_int) static/ unchanged after first call even if it is called multiple times. If x= rand_int () return