On 04/04/2013 20:00, Jason Swails wrote:
On Thu, Apr 4, 2013 at 1:30 PM, Rotwang <sg...@hotmail.co.uk
<mailto:sg...@hotmail.co.uk>> wrote:
[...]

    I don't know whether this applies to the OP's code, but I can think
    of at least one reason why one would want both "import module" and
    "from module import*" at the top of one's code: monkey patching.


That was not happening in the OP's code (it actually had no references
to tkinter after the initial import).

Sure.


That said, if you change any
attributes inside tkinter (by binding names inside tkinter to another
object) after the top three lines, those changes will not percolate down
to the attributes imported via "from tkinter import *" -- you would
obviously have to do that work before importing the tkinter namespace
into the toplevel namespace.

What I had in mind was something like this:

# begin module derp.py

global_variable = 4

def f():
        print('global_variable == %i' % global_variable)

# end module derp.py

>>> # in the interactive interpreter...
>>> import derp
>>> from derp import *
>>> global_variable = 5
>>> f()
global_variable == 4
>>> derp.global_variable = 5
>>> f()
global_variable == 5


Off the top of my head I don't know whether there's any purpose to doing that kind of thing with tkinter, but I can conceive that it might be useful for e.g. changing widget default behaviour or something.


I'd be interested to see if there's actually an example where someone
does this in a way that would not be done better another way.

No idea, sorry.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to