Re: [Tutor] introspection

2015-05-07 Thread Alex Kleider
On 2015-05-07 20:45, Dave Angel wrote: You also only showed it working on module globals. (For code at top-level, locals() returns the same as globals() ) You could also try it inside functions, where locals() really makes sense as a name. And you could try it in a nested function where there

Re: [Tutor] introspection

2015-05-07 Thread Dave Angel
On 05/07/2015 11:23 PM, Alex Kleider wrote: On 2015-05-07 19:10, Dave Angel wrote: def get_name(localmap, item): """As suggested. Returns 'a' name, not necessarily 'the' name.""" for name in localmap: if localmap[name] == item: This is not likely to be what was intende

Re: [Tutor] introspection

2015-05-07 Thread Alex Kleider
On 2015-05-07 19:10, Dave Angel wrote: def get_name(localmap, item): """As suggested. Returns 'a' name, not necessarily 'the' name.""" for name in localmap: if localmap[name] == item: This is not likely to be what was intended. You want if localmap[name] is

[Tutor] Tip (thank) your mentors

2015-05-07 Thread Ben Finney
Howdy all, I just received a private message that, briefly and simply, thanked me for advice I gave in this forum, explaining specifically how it helped the recipient understand a concept better. It made my day; I have a spring in my step now. Everyone, never hesitate to thank someone – privatel

Re: [Tutor] pointer puzzlement

2015-05-07 Thread Steven D'Aprano
On Thu, May 07, 2015 at 12:15:42PM -0700, Jim Mooney Py3.4.3winXP wrote: > I find this a bit confusing. Since the ID of K remains the same, so it's > the same object, why isn't it increasing each time. i.e, 20, 30, 40,. I > understand that it's immutable but doesn't that mean K is created each time

Re: [Tutor] introspection

2015-05-07 Thread Dave Angel
On 05/07/2015 09:50 PM, Alex Kleider wrote: On 2015-04-21 16:48, Cameron Simpson wrote: But it would not be schizophrenic to write a function that returned a name arbitrarily, by inspecting locals(). It depends whether you only need a name, or if you need "the" name. Write yourself a "find_nam

Re: [Tutor] introspection

2015-05-07 Thread Alex Kleider
On 2015-04-21 16:48, Cameron Simpson wrote: But it would not be schizophrenic to write a function that returned a name arbitrarily, by inspecting locals(). It depends whether you only need a name, or if you need "the" name. Write yourself a "find_name_from_locals(local_map, value)" function tha

Re: [Tutor] pointer puzzlement

2015-05-07 Thread Dave Angel
On 05/07/2015 07:51 PM, Dave Angel wrote: On 05/07/2015 04:54 PM, Jim Mooney Py3.4.3winXP wrote: On 7 May 2015 at 13:03, Emile van Sebille wrote: Compare to: def testid(K=100): K += 10 return 'the ID is', id(K), K Ah, thanks. I forgot small integers are saved in a table. I

Re: [Tutor] pointer puzzlement

2015-05-07 Thread Dave Angel
On 05/07/2015 05:25 PM, Alan Gauld wrote: On 07/05/15 21:54, Jim Mooney Py3.4.3winXP wrote: Ah, thanks. I forgot small integers are saved in a table. I was looking at a demo that pointers to defaults in function parameters are persistent. But remember they variables are NOT pointers. They are

Re: [Tutor] pointer puzzlement

2015-05-07 Thread Dave Angel
On 05/07/2015 04:54 PM, Jim Mooney Py3.4.3winXP wrote: On 7 May 2015 at 13:03, Emile van Sebille wrote: Compare to: def testid(K=100): K += 10 return 'the ID is', id(K), K Ah, thanks. I forgot small integers are saved in a table. I was looking at a demo that pointers to def

Re: [Tutor] pointer puzzlement

2015-05-07 Thread Dave Angel
On 05/07/2015 03:15 PM, Jim Mooney Py3.4.3winXP wrote: I find this a bit confusing. Since the ID of K remains the same, so it's the same object, why isn't it increasing each time. i.e, 20, 30, 40,. I understand that it's immutable but doesn't that mean K is created each time in local scope so it

Re: [Tutor] pointer puzzlement

2015-05-07 Thread Dave Angel
On 05/07/2015 04:03 PM, Emile van Sebille wrote: On 5/7/2015 12:15 PM, Jim Mooney Py3.4.3winXP wrote: I find this a bit confusing. Since the ID of K remains the same, so it's the same object, why isn't it increasing each time. i.e, 20, 30, 40,. I understand that it's immutable but doesn't that m

Re: [Tutor] pointer puzzlement

2015-05-07 Thread Alan Gauld
On 07/05/15 21:54, Jim Mooney Py3.4.3winXP wrote: Ah, thanks. I forgot small integers are saved in a table. I was looking at a demo that pointers to defaults in function parameters are persistent. But remember they variables are NOT pointers. They are keys in a dictionary. Very different. Als

Re: [Tutor] pointer puzzlement

2015-05-07 Thread Jim Mooney Py3.4.3winXP
On 7 May 2015 at 13:03, Emile van Sebille wrote: > Compare to: > > def testid(K=100): > K += 10 > return 'the ID is', id(K), K > Ah, thanks. I forgot small integers are saved in a table. I was looking at a demo that pointers to defaults in function parameters are persistent. It use

Re: [Tutor] pointer puzzlement

2015-05-07 Thread Emile van Sebille
On 5/7/2015 12:15 PM, Jim Mooney Py3.4.3winXP wrote: I find this a bit confusing. Since the ID of K remains the same, so it's the same object, why isn't it increasing each time. i.e, 20, 30, 40,. I understand that it's immutable but doesn't that mean K is created each time in local scope so it sh

[Tutor] pointer puzzlement

2015-05-07 Thread Jim Mooney Py3.4.3winXP
I find this a bit confusing. Since the ID of K remains the same, so it's the same object, why isn't it increasing each time. i.e, 20, 30, 40,. I understand that it's immutable but doesn't that mean K is created each time in local scope so it should have a different ID each time? def testid(K=10):

Re: [Tutor] apache python cgi sockets error 13 (resend after joining the tutorial list)

2015-05-07 Thread Felix Dietrich
Stewart Lawton writes: > Hi I have tried Python TCPIP sockets and Unix sockets processed in a > python cgi script, called from apache under fedora19. In both cases a > permissions error is returned at sock.connect(). I have tried changing > permissions x and r w on ALL of user, group, other to no

Re: [Tutor] apache python cgi sockets error 13 (resend after joining the tutorial list)

2015-05-07 Thread Alan Gauld
Can you post again in plain text? The formatting below is all messed up, indentation and spacing errors abound. On 07/05/15 11:56, Stewart Lawton wrote: Hi I have tried Python TCPIP sockets and Unix sockets > processed in a python cgi script, Have you tried opening the same sockets in a script

[Tutor] apache python cgi sockets error 13 (resend after joining the tutorial list)

2015-05-07 Thread Stewart Lawton
Hi I have tried Python TCPIP sockets and Unix sockets processed in a python cgi script, called from apache under fedora19. In both cases a permissions error is returned at sock.connect(). I have tried changing permissions x and r w on ALL of user, group, other to no avail. In both cases the cgi

Re: [Tutor] Guess the number

2015-05-07 Thread Alan Gauld
On 07/05/15 05:09, Ikaia Leleiwi wrote: number might be. If the guess is lower then the inputted number then the user inputs the word 'higher' to indicate the computer needs to guess a higher number. If the guess is higher than the inputted number then the user inputs the word 'lower' to indic

[Tutor] Guess the number

2015-05-07 Thread Ikaia Leleiwi
I am having trouble writing a program that guesses a number inputted by the user. A number between 1-100 is inputted into the program and the computer produces a random integer that is the "guess" as to what the inputted number might be. If the guess is lower then the inputted number then the use

Re: [Tutor] Object references and garbage collection confusion

2015-05-07 Thread Brandon D
> > This is what was also confusing as well. I assumed that python stored > objects rather than simply assigning them. > On Tue, May 5, 2015 at 4:48 AM, Alan Gauld wrote: > On 05/05/15 05:29, Brandon D wrote: > >> Hello tutors, >> >> I'm having trouble understanding, as well as visualizing, how

Re: [Tutor] Object references and garbage collection confusion

2015-05-07 Thread Brandon D
Thanks Steven. I was just confused on the execution of when Python destroys objects that are no long bound or referenced. On Tue, May 5, 2015 at 2:00 PM, Steven D'Aprano wrote: > On Tue, May 05, 2015 at 12:29:59AM -0400, Brandon D wrote: > > Hello tutors, > > > > I'm having trouble understandin