function scope
Hi everybody, I am quite new to python and using it for my thesis. Luckily I found out some kind of behavior surprising to me and so unwanted in my code. I could not find any explanation, so solution for the code. It is simply like this: /*li = another_module.global_variable f=simpleCut(li) def simpleCut(d=dict()): temp=d for i in temp.keys(): if(temp[i] == ...) : temp[i]=new_value return temp */ here /*simpleCut(d=dict())*/ is a function that changes the value of the key in the d if it satisfies conditions and returns the new dictionary. what i do not understand is, when i checked the original dictionary /*li,*/ i also found out that, the value of that key(operated in the if statement) had also been changed. so, simply, the simpleCut function also changes the variables of its own argument, even there is a 'temp' variable. That is a scandal for my code:) please tell me, if this is not possible and i am missing another thing in my code, or if this kind of behavior is possible, what is the philosophy of it, and how can i change it??? cheers B.D. -- http://mail.python.org/mailman/listinfo/python-list
Re: function scope
Tim Roberts wrote: Mike Kent wrote: On Feb 2, 6:40 pm, Baris Demir wrote: def simpleCut(d=dict()): temp=d for i in temp.keys(): if(temp[i] == ...) : temp[i]=new_value return temp You have been bitten by the shared default parameter noobie trap: http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects Actually, he hasn't. His problem is more fundamental. However, this is still a good thing for you to point out now and then. Thanks a lot for the replies guys. They all helped a lot. And, I guess, I should read a lot more about python, it is not as simple as it seems at the beginning, or for the beginners:) cheers BD -- http://mail.python.org/mailman/listinfo/python-list
3D plotting in a GUI
Hi all, I need to develop a GUI for some scientific data processing operations and this GUI should work well with a 3D plotting module, also with NumPy and SciPy for sure. I made a search about packages but, there are plenty of these modules available. What kind of a package or a package of packages might be the best way for this work. BTW I do not want to use MayaVi. It is too much actually. Thanks in advance. BD -- http://mail.python.org/mailman/listinfo/python-list
Re: 3D plotting in a GUI
Stef Mientki wrote: Baris Demir wrote: Hi all, I need to develop a GUI for some scientific data processing operations and this GUI should work well with a 3D plotting module, also with NumPy and SciPy for sure. I made a search about packages but, there are plenty of these modules available. What kind of a package or a package of packages might be the best way for this work. BTW I do not want to use MayaVi. It is too much actually. What do you mean by "too much actually" ? What's the GUI you had in mind ? What kind of scientific data processing do you've in mind ? cheers, Stef I am quite experienced about python programming but this is going to be my first GUI design. I need to draw some 2D graphs (also capability for 3D graphs might be very delicious) and do some mathematical operations on them like adding, substracting, smoothing, integration, detecting peak points and marking them, fourier transformations and etc. on WindowsXP. And then I want to convert this python code into a .exe by using py2exe. I said Mayavi is too much for me because I thought that it would be more likeyl to have problems while using a big package like MayaVi with py2exe. Thanks in advance. BD -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list