[Tutor] detecting data member changes

2007-04-24 Thread Luke Paireepinart
Supposing I have a class like this: class wiimote(object): def __init__(self): self.leds = [0,0,0,0] def updateLEDs(self): do_stuff()#write correct output report to wiimote to toggle LEDs. So basically what I want to do is that whenever the self.leds variable is changed,

Re: [Tutor] detecting data member changes

2007-04-24 Thread Alan Gauld
Luke Paireepinart [EMAIL PROTECTED] wrote class wiimote(object): def __init__(self): self.leds = [0,0,0,0] def updateLEDs(self): do_stuff()#write correct output report to wiimote to toggle LEDs. So basically what I want to do is that whenever the self.leds variable

[Tutor] scope/namespaces

2007-04-24 Thread ammar azif
Something in python disturbs me , when i write a for loop, i am able to access the variable declared in that loop after the loop finishes which i am not able to do in languages like c/c++ or java. Is it different in python? - Ahhh...imagining that

Re: [Tutor] scope/namespaces

2007-04-24 Thread Rikard Bosnjakovic
On 4/24/07, ammar azif [EMAIL PROTECTED] wrote: i am able to access the variable declared in that loop after the loop finishes which i am not able to do in languages like c/c++ or java. Is it different in python? I'm not sure what you mean with different, but the loop-variable is not

Re: [Tutor] Tkinter import error

2007-04-24 Thread Michael Lange
On Tue, 24 Apr 2007 00:09:21 +0100 Alan Gauld [EMAIL PROTECTED] wrote: John DeStefano [EMAIL PROTECTED] wrote I've run into an error that I've seen reported in several places, but none of the fixes seem to be working for me: when I try to import Tkinter I get a configuration error:

Re: [Tutor] detecting data member changes

2007-04-24 Thread Kent Johnson
Luke Paireepinart wrote: Supposing I have a class like this: class wiimote(object): def __init__(self): self.leds = [0,0,0,0] def updateLEDs(self): do_stuff()#write correct output report to wiimote to toggle LEDs. So basically what I want to do is that whenever

[Tutor] Question on UserDict class - copy function

2007-04-24 Thread Ketan Joshi
Hello All, I am very new to Python scripting. I have just started learning about Python. I have a question regarding UserDict class. UserDict class has a copy function which is defined as follows: def copy(self): if self.__class__ is UserDict: return UserDict(self.data) import

Re: [Tutor] scope/namespaces

2007-04-24 Thread Kent Johnson
ammar azif wrote: Something in python disturbs me , when i write a for loop, i am able to access the variable declared in that loop after the loop finishes which i am not able to do in languages like c/c++ or java. Is it different in python? Yes, it is different. In Python a block is

[Tutor] + converted to 25 in http string

2007-04-24 Thread govind goyal
Hi, I am using http to automate my Access point(AP) configuration where I sent following strings to AP server through script. params = urllib.urlencode ({'WRegion':USA,'ssid':wifi,'ap':ap,'ssid_enable':ssid_enable,* 'wire_mode':b+only,* 'w_channel':6,'lan_ac':everyone,'int_ac':everyone}) Above

Re: [Tutor] + converted to 25 in http string

2007-04-24 Thread Martin Walsh
Hi, govind goyal wrote: Hi, I am using http to automate my Access point(AP) configuration where I sent following strings to AP server through script. params = urllib.urlencode ({'WRegion':USA,'ssid':wifi,'ap':ap,'ssid_enable':ssid_enable,* 'wire_mode':b+only,*

Re: [Tutor] + converted to 25 in http string

2007-04-24 Thread Kent Johnson
govind goyal wrote: Hi, I am using http to automate my Access point(AP) configuration where I sent following strings to AP server through script. params = urllib.urlencode({'WRegion':USA,'ssid':wifi,'ap':ap,'ssid_enable':ssid_enable,*'wire_mode':b+only,*

Re: [Tutor] scope/namespaces

2007-04-24 Thread Ezra Taylor
Sorry about that kent. I just realized I emailed you directly. Ezra On 4/24/07, Kent Johnson [EMAIL PROTECTED] wrote: ammar azif wrote: Something in python disturbs me , when i write a for loop, i am able to access the variable declared in that loop after the loop finishes which i am

Re: [Tutor] scope/namespaces

2007-04-24 Thread Kent Johnson
Ezra Taylor wrote: Hello Kent: How can we limit this functionality so that python behaves similar to other know languages. Maybe I should be asking what are the benifits of allow variables not being bound to a block of code. Why is this a problem? Don't try to turn

Re: [Tutor] Tkinter import error

2007-04-24 Thread John DeStefano
Michael Lange [EMAIL PROTECTED] wrote: Usually there is no need to pass extra arguments to configure. My guess is that you missed to install Tcl / Tk and/or the Tcl/Tk development packages before compiling python. That was it: I had both Tcl and Tk installed, but not the development packages

Re: [Tutor] detecting data member changes

2007-04-24 Thread Luke Paireepinart
Make leds a property: class wiimote(object): def __init__(self): self._leds = [0, 0, 0, 0] def _set_leds(self, leds): self._leds = leds self._updateLEDs() def _get_leds(self): return self._leds leds = property(_get_leds, _set_leds)

Re: [Tutor] Question on UserDict class - copy function

2007-04-24 Thread Rikard Bosnjakovic
On 4/24/07, Ketan Joshi [EMAIL PROTECTED] wrote: If so, why isn't this function defined as: def copy(self): import copy return copy.copy(self) The if-case in your code makes sure that the property __class__ is of UserDict-inheritance. I believe it's there in case of multiple

Re: [Tutor] detecting data member changes

2007-04-24 Thread Kent Johnson
Luke Paireepinart wrote: I know I could use a __setattr__ but then I'd have to access the leds using a dictionary with an 'LED' key mapped to the status array. It's not necessarily a bad thing for my own use, but it seems like it'd be off-putting to other people using my library. I don't

[Tutor] how to stop a function

2007-04-24 Thread shawn bright
hello all, i have a gui app that uses functions to respond to gui events. like def on_start_button_clicked(self, stuff): do this or that. now there is one function that i have a kinda nested if else conditions that i need to stop if necessary if value == 1: if next_val == 4: do

[Tutor] Fwd: how to stop a function

2007-04-24 Thread Andre Engels
-- Forwarded message -- From: Andre Engels [EMAIL PROTECTED] Date: 24 apr. 2007 17:18 Subject: Re: [Tutor] how to stop a function To: shawn bright [EMAIL PROTECTED] 2007/4/24, shawn bright [EMAIL PROTECTED]: hello all, i have a gui app that uses functions to respond to gui

Re: [Tutor] how to stop a function

2007-04-24 Thread Kent Johnson
shawn bright wrote: now there is one function that i have a kinda nested if else conditions that i need to stop if necessary if value == 1: if next_val == 4: do this or that else: here i need the function to just die do somthing here is there something i can

Re: [Tutor] how to stop a function

2007-04-24 Thread shawn bright
jeeze, thanks, sorry, stupid question. On 4/24/07, Kent Johnson [EMAIL PROTECTED] wrote: shawn bright wrote: now there is one function that i have a kinda nested if else conditions that i need to stop if necessary if value == 1: if next_val == 4: do this or that

Re: [Tutor] detecting data member changes

2007-04-24 Thread Luke Paireepinart
No, the above code should work with classinstance.leds. Maybe you are confusing __setattr__ - which affects attributes like .leds - with __setitem__ which is used for classinstance['leds'] Ah, yes. You hit the hail on the nead there, Kent. Thanks for clarifying that for me. Is this

Re: [Tutor] Exceptions while dealing with MySQL

2007-04-24 Thread Thanos Panousis
Thanks to everybody for the replies. I got some nice pointers. I know my design is nasty, but that is because I am learning...Putting object orientation in the mix, I have this question: I have an object, person, which is assosiated with some statistical data. Say for each person object, I need

Re: [Tutor] detecting data member changes

2007-04-24 Thread Kent Johnson
Luke Paireepinart wrote: I can see how some people might be surprised to know that changing classinstance.leds automagically sends a communication packet to the wii remote without their knowledge, but if they're aware of the side-effect, it seems to be a more elegant way of doing things to

Re: [Tutor] how to stop a function

2007-04-24 Thread Rikard Bosnjakovic
On 4/24/07, shawn bright [EMAIL PROTECTED] wrote: is there something i can do to make this happen? Use the keyword return. -- - Rikard - http://bos.hack.org/cv/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] detecting data member changes

2007-04-24 Thread Alan Gauld
Luke Paireepinart [EMAIL PROTECTED] wrote Is this properties method acceptable Python form or is it more proper to have modifying member functions like Alan said? Properties is fine and was one of the options that I suggested. However I didn't mean you should have modifying member functions

[Tutor] No return statement

2007-04-24 Thread Cecilia Alm
My apologies for asking a trivial question about programming practice. As mentioned in the online tutorial (http://docs.python.org/tut/node6.html#SECTION00670), functions which lack a return statement ('procedures') actually return None. For such functions, I assume it's preferred

Re: [Tutor] scope/namespaces

2007-04-24 Thread Alan Gauld
ammar azif [EMAIL PROTECTED] wrote Something in python disturbs me , when i write a for loop, i am able to access the variable declared in that loop after the loop finishes which i am not able to do in languages like c/c++ or java. That's a very recent change to C/C++ (1999

Re: [Tutor] scope/namespaces

2007-04-24 Thread Alan Gauld
Ezra Taylor wrote: How can we limit this functionality so that python behaves similar to other know languages. There are many other languages that work like Python. Including the original versions of C and C++... And other languages that don't have explicit loop

[Tutor] Clarification on Debugging under IDLE

2007-04-24 Thread J.T. Hurley
On the debug control, what is the difference between go, over, and out? Thank you, J.T. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Exceptions while dealing with MySQL

2007-04-24 Thread Alan Gauld
Thanos Panousis [EMAIL PROTECTED] wrote data. Say for each person object, I need an object variable called hairColor. This haircolor variable has to be filled through an SQL query, so the object must have some way to access a database cursor. The cool thing would be that all person objects

Re: [Tutor] No return statement

2007-04-24 Thread Andre Engels
My opinion is that one should not create or set a variable if its value is not used. In the case mentioned, you know what the return value will be, so there seems to be no reason to keep it. 2007/4/24, Cecilia Alm [EMAIL PROTECTED]: My apologies for asking a trivial question about programming

Re: [Tutor] Exceptions while dealing with MySQL

2007-04-24 Thread Kent Johnson
Thanos Panousis wrote: I have an object, person, which is assosiated with some statistical data. Say for each person object, I need an object variable called hairColor. This haircolor variable has to be filled through an SQL query, so the object must have some way to access a database cursor.

Re: [Tutor] No return statement

2007-04-24 Thread Cecilia Alm
OK, that's my opinion too. Thanks! 2007/4/24, Andre Engels [EMAIL PROTECTED]: My opinion is that one should not create or set a variable if its value is not used. In the case mentioned, you know what the return value will be, so there seems to be no reason to keep it. 2007/4/24, Cecilia Alm

Re: [Tutor] Clarification on Debugging under IDLE

2007-04-24 Thread Kent Johnson
J.T. Hurley wrote: On the debug control, what is the difference between go, over, and out? What debug control are you using? Debuggers usually have three kinds of stepping. The names vary but the concepts are the same: step in - execute the next line of code; if it is a subroutine call, stop

Re: [Tutor] No return statement

2007-04-24 Thread Alan Gauld
Cecilia Alm [EMAIL PROTECTED] wrote functions which lack a return statement ('procedures') actually return None. For such functions, I assume it's preferred to not catch None in a variable. You can catch it if you like, but since functions with no return *always* return None there is

Re: [Tutor] Clarification on Debugging under IDLE

2007-04-24 Thread Alan Gauld
J.T. Hurley [EMAIL PROTECTED] wrote On the debug control, what is the difference between go, over, and out? Cabeat, I haven't checked, but from memory: go = Run the program from the current point onwards until you hit the next break point or until it ends. over = step over the function on

Re: [Tutor] scope/namespaces

2007-04-24 Thread Ben Sherman
Am I wrong in my memory? When I was a wee lad prior to 99 for sure), I thought I would initialize my loops with: for (int x=0; x 10; x++) { } I am rapidly veering off topic. On 4/24/07, Alan Gauld [EMAIL PROTECTED] wrote: Correcting my own post! Alan Gauld [EMAIL PROTECTED] wrote That's

Re: [Tutor] Exceptions while dealing with MySQL

2007-04-24 Thread Thanos Panousis
I checked the SQLAlchemy and SQLObject projects, but they are not really relevant to what I am doing(moreover they are more than I can chew just yet:). I managed to get a class variable to hold a cursor via something like class person: cursor = MySQLdb.connect(stuff).cursor() BUT when I

Re: [Tutor] Clarification on Debugging under IDLE

2007-04-24 Thread J.T. Hurley
Kent: I'm using IDLE's built-in debugger. Alan: I just tried it out, and you were spot-on. Thank you both for your assistance. I think I've got the hang of it now. It'll certainly speed me up now that I don't have to step through each function. Thanks again, J.T.

Re: [Tutor] Exceptions while dealing with MySQL

2007-04-24 Thread Alan Gauld
Thanos Panousis [EMAIL PROTECTED] wrote in I managed to get a class variable to hold a cursor via something like class person: cursor = MySQLdb.connect(stuff).cursor() BUT when I make a function inside my class called myConnect, where I do error checking and so on, I can't make it

Re: [Tutor] scope/namespaces

2007-04-24 Thread Roel Schroeven
Ben Sherman schreef: Am I wrong in my memory? When I was a wee lad prior to 99 for sure), I thought I would initialize my loops with: for (int x=0; x 10; x++) { } If that was in C, it must have been a special feature of your compiler. -- If I have been able to see further, it was only

Re: [Tutor] scope/namespaces

2007-04-24 Thread Alan Gauld
Ben Sherman [EMAIL PROTECTED] wrote Am I wrong in my memory? When I was a wee lad prior to 99 for sure), I thought I would initialize my loops with: for (int x=0; x 10; x++) { You certainly could in C++ but I'm less sure about C. You certainly couldn't do that in C prior to ANSI C (in

Re: [Tutor] Clarification on Debugging under IDLE

2007-04-24 Thread Kent Johnson
Kent Johnson wrote: J.T. Hurley wrote: On the debug control, what is the difference between go, over, and out? What debug control are you using? Debuggers usually have three kinds of stepping. The names vary but the concepts are the same: step in - execute the next line of code; if it