Re: Multithreading tkinter question
Hello John, > Mark, > > I tried your code snippet with Python 2.3.4. Worked fine. Only problem was > that the program fell off the end and terminated before the second thread > could open the Tkinter window. So I added these lines at the end to make the > main thread wait:- > > from msvcrt import kbhit, getch > print "\n\nPress key to end" > while not kbhit(): pass > getch() And I added print "\n\nPress key to end" l = sys.stdin.readline() > Both your Hello and Quit buttons worked. In my case "Hello" works and "Quit" doesn't (GUI stays frozen). Linux, Python 2.3.3, pygtk-0.6.9. > ... > > It is not optimal in that 'otherThread' runs continuously even when the > label is not being updated. What a waste of cpu cycles! This shows up in > that other windows apps slow right down. What is needed is a comms method > between threads that causes a thread to block while it's waiting for data > rather than my continuous polling approach. Would a Queue help here? > Yes, it should help. A time ago I tried to write a tkinter application, and my test code is available: A complete Python Tkinter sample application for a long operation http://uucode.com/texts/pylongopgui/pyguiapp.html Maybe you find it interesting. -- Oleg -- http://mail.python.org/mailman/listinfo/python-list
dynamic unittest
Hello, I decided to re-use functionality of "unittest" module for my purposes. More precisely, I have a list of folders. For each folder, code should enter to the folder, execute a command and assert the output. It's reasonable to use "unittest" here, but the problem is that "unittest" doesn't support (== I haven't found how) dynamic creation of tests. I thought it would be very easy, but due to lack of closures in Python (more precisely, closures do exist, but they are counter-intuitive for lisp programmers), I failed. Finally, I found a way using a global variable. I exploit the fact that "unittest" uses "cmp" to arrange test cases. Therefore, if we have an array of test names and sequential number of running the common function, we know the name of the current test. Here is a sample code: --- import sys, unittest test_names = ['aaa', 'ddd', 'bbb'] test_names.sort() test_index = 0 class DynamicTestCase(unittest.TestCase): def one_test(self): global test_index test_name = test_names[test_index] test_index = test_index + 1 # Ok for 'aaa' and 'bbb', failure for 'ddd' assert test_name in ['aaa', 'bbb'] for test_name in test_names: func_name = 'test_' + test_name setattr(DynamicTestCase, func_name, DynamicTestCase.one_test) suite = unittest.makeSuite(DynamicTestCase, 'test_') if not unittest.TextTestRunner().run(suite).wasSuccessful(): sys.exit(1) --- I think this code might help others, so I post it to the group. Comments are welcome. -- Oleg Parashchenko olpa@ http://xmlhack.ru/ XML news in Russian http://uucode.com/blog/ Generative Programming, XML, TeX, Scheme XSieve at XTech 2006: http://xtech06.usefulinc.com/schedule/detail/44 -- http://mail.python.org/mailman/listinfo/python-list
Re: dynamic unittest
Hello Peter, thanks a lot. I've overlooked this simple way to create the right closure. -- Oleg -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing 2 similar strings?
Hello William, William Park <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > How do you compare 2 strings, and determine how much they are "close" to > each other? > ... If your strings are between 1 and 16 Kb, look at GetReuse SDK: http://getreuse.com/sdk/ It has Perl and Python bindings. You might be interested in the latter as you posted to comp.lang.python. I can't disclosure the algorithm. Here is an excerpt from the home page: The formula for the calculation of the similarity is based on the scientific research. Any other "good" method of calculations should produce results that are equivalent in some terms to the GetReuse results. -- olpa@ http://datahansa.com/ XML publishing and documentation management http://uucode.com/blog/ Generative Programming, XML, TeX, Scheme -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing 2 similar strings?
Hello, Scott David Daniels <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > William Park wrote: > > How do you compare 2 strings, and determine how much they are "close" to > > each other? > > Here's a really weird idea: Measure the size difference between the > pair of strings compressed together and compressed separately. > The idea isn't weird. The only problem is that naive approach failed. compress(a,b) != compress(b,a). Having an assumption that compressing is a good approximation for the Kolmogorov complexity, the correct formula is a bit more complicated. -- olpa@ http://datahansa.com/ XML publishing and documentation management http://uucode.com/blog/ Generative Programming, XML, TeX, Scheme -- http://mail.python.org/mailman/listinfo/python-list
