String multi-replace
Hi All, I have to eliminate diacritics in a fairly large file. Inspired by http://code.activestate.com/recipes/81330/, I came up with the following code: #! /usr/bin/env python import re nodia={chr(196)+chr(130):'A', # mamaliga chr(195)+chr(130):'A', # A^ chr(195)+chr(142):'I', # I^ chr(195)+chr(150):'O', # OE chr(195)+chr(156):'U', # UE chr(195)+chr(139):'A', # AE chr(197)+chr(158):'S', chr(197)+chr(162):'T', chr(196)+chr(131):'a', # mamaliga chr(195)+chr(162):'a', # a^ chr(195)+chr(174):'i', # i^ chr(195)+chr(182):'o', # oe chr(195)+chr(188):'u', # ue chr(195)+chr(164):'a', # ae chr(197)+chr(159):'s', chr(197)+chr(163):'t' } name=R\xc3\xa2\xc5\x9fca regex = re.compile((%s) % |.join(map(re.escape, nodia.keys( print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) But it won't work; I end up with: Traceback (most recent call last): File multirep.py, line 25, in module print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) File multirep.py, line 25, in lambda print regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], name) TypeError: 'type' object is not subscriptable What am I doing wrong? Thanks for your advice, SxN -- http://mail.python.org/mailman/listinfo/python-list
Re: String multi-replace
Thanks for your answers. Benjamin Kaplan: of course dict is a type... silly me! I'll blame it on the time (it's midnight here). Chris Rebert: I'll have a look. Thank you both, SxN -- http://mail.python.org/mailman/listinfo/python-list
Re: String multi-replace
Steven D'Aprano: the original file is 139MB (that's the typical size for it). Eliminating diacritics is just a little toping on the cake; the processing is something else. Thanks anyway for your suggestion, SxN PS Perhaps I should have mention that I'm on Python 2.7 -- http://mail.python.org/mailman/listinfo/python-list
Autocompletion
Hi All, Does anybody knows about a module to assist with text autocompletion for a given dictionary? Thanks, SxN __ Ask a question on any topic and get answers from real people. Go to Yahoo! Answers and share what you know at http://ca.answers.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Autocompletion
Sorry for being careless in my choice of words: when I wrote dictionary, I meant a collection of words in any given human language, not a Python dictionary. Perhaps I should try to explain a bit more what I try to accomplish: in a notebook the user will write text, and certain words (collected in a, let's say, vocabulary) need this feature. Ideally, I'd like to start the autocompletion feature when the widget gets the focus, and stop it when focus is lost. Moreover, when starting, a numeric parameter should dictate that the autocompletion will kick in after writing the respective number of characters. I said notebook because that's my intended use, but any kind of text entry should have the same behaviour if autocompletion is associated with it. I am targeting an English and a French vocabulary. SxN __ Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now http://ca.toolbar.yahoo.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Some test fail on my new Python 2.6
Thanks for the pointers. Here are some answers: Ok, so DBM wasn't built because it couldn't find the external symbol 'dbm_firstkey'. I have no idea off the top of my head why that would happen, but I don't think you really care at the moment since you are trying to get tkinter working. If you do care we can come back to that. Although I can live without it, I do use sometime dbm. And then, again, there are other ways to accomplish the same, so it's not critical. building '_tkinter' extension gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -DWITH_APPINIT=1 -DWITH_BLT=1 -I/usr/X11R6/include -I. -I/install/Python-2.6.1/./Include -I. -IInclude -I./Include -I/usr/local/include -I/install/Python-2.6.1/Include -I/install/Python-2.6.1 -c /install/Python-2.6.1/Modules/_tkinter.c -o build/temp.linux-i686-2.6/install/Python-2.6.1/Modules/_tkinter.o gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -DWITH_APPINIT=1 -DWITH_BLT=1 -I/usr/X11R6/include -I. -I/install/Python-2.6.1/./Include -I. -IInclude -I./Include -I/usr/local/include -I/install/Python-2.6.1/Include -I/install/Python-2.6.1 -c /install/Python-2.6.1/Modules/tkappinit.c -o build/temp.linux-i686-2.6/install/Python-2.6.1/Modules/tkappinit.o gcc -pthread -shared build/temp.linux-i686-2.6/install/Python-2.6.1/Modules/_tkinter.o build/temp.linux-i686-2.6/install/Python-2.6.1/Modules/tkappinit.o -L/usr/X11R6/lib64 -L/usr/X11R6/lib -L/usr/local/lib -lBLT -ltk8.5 -ltcl8.5 -lX11 -o build/lib.linux-i686-2.6/_tkinter.so *** WARNING: renaming _tkinter since importing it failed: libtk8.5.so: cannot open shared object file: No such file or directory Now, this one is clear. It couldn't find libtk8.5.so when it tried to use _tkinter.so. So either that symlink doesn't exist, or points to a nonexistent library, or there's something wrong with your load library path, so that python isn't finding it when it tries to do the load. If you don't know what that last one means, check out 'man ldconfig'. # pwd /usr/local/lib # ls libpq.so.4libtcl8.4.so libtclstub8.4.a libtk8.4.so libtkstub8.4.a python2.4 tcl8.4 tclConfig.sh tk8.5 libpq.so.4.0 libtcl8.5.so libtclstub8.5.a libtk8.5.so libtkstub8.5.a tcl8 tcl8.5 tk8.4 tkConfig.sh It's there! test_multiprocessing test_multiprocessing skipped -- OSError raises on RLock creation, see issue 3111! According to the referenced bug, this may be a result of your not having /dev/shm mounted, but in any case it is more a bug in the tests than a bug in your system or setup. # mount /dev/hda3 on / type reiserfs (rw,noatime) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) udev on /dev type tmpfs (rw,nosuid) devpts on /dev/pts type devpts (rw) shm on /dev/shm type tmpfs (rw,noexec,nosuid,nodev) usbfs on /proc/bus/usb type usbfs (rw,devmode=0664,devgid=85) It's there, but if it is about a known bug in the test, maybe we should just ignore it? test_socket test test_socket failed -- Traceback (most recent call last): File /install/Python-2.6.1/Lib/test/test_socket.py, line 474, in testSockName my_ip_addr = socket.gethostbyname(socket.gethostname()) gaierror: [Errno -2] Name or service not known This probably means that you haven't properly defined 'localhost' in your /etc/hosts file. # cat /etc/hosts # /etc/hosts # # This file describes a number of hostname-to-address # mappings for the TCP/IP subsystem. It is mostly # used at boot time, when no name servers are running. # On small systems, this file can be used instead of a # named name server. Just add the names, addresses # and any aliases to this file... # 127.0.0.1 localhost # IPV6 versions of localhost and co ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts There is a localhost definition. Is it not correct? test_sys test test_sys failed -- Traceback (most recent call last): File /install/Python-2.6.1/Lib/test/test_sys.py, line 354, in test_43581 self.assert_(sys.__stdout__.encoding == sys.__stderr__.encoding) AssertionError This one is puzzling. Did you modify 'site.py'? Or perhaps you redirected stdout and stderr to different places and they wound up with different encodings for some reason. In which case that one would be a bug in the tests as well. No, I didn't, nor have I done anything with stdout, stderror. When I ran the test, I did a make test | tee test.rez, which in my mind should have been harmless. The output for individual test_httpservers was posted here: http://mail.python.org/pipermail/python-list/2009-April/708041.html Thanks again SxN __ Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now http://ca.toolbar.yahoo.com. --
Re: Some test fail on my new Python 2.6
Hello again, /usr/local/lib is in /etc/ld.so.conf. The files are real. However, creating symlinks in /usr/lib targeting the libraries in /usr/local/lib, then recompiling, solved the tkinter problem. So, the conclusion is that only /usr/lib is consulted for the tcl/tk libraries. multiprocessing - do I need it? Probably not. I can fork() a new process, so I can manage. I don't know what am I loosing without multiprocessing. socket was solved as suggested, by adding the host name in /etc/hosts, like this: 127.0.0.1 localhost dsr-1 sys doesn't fail anymore after recompilation (have no clue why). htttpservers is still failing the same. Everything is done as root. I'll move on with make install. Thanks for your help; I'm progressing :-) SxN __ Instant Messaging, free SMS, sharing photos and more... Try the new Yahoo! Canada Messenger at http://ca.beta.messenger.yahoo.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Some test fail on my new Python 2.6
Run 'make test' instead of running them one by one. I did it *before* going one by one. I then tried individual tests in hope of getting hints of what to look for. Actualy, for the first three tests, the make test script commented that it is unusual for them to fail on my platform (linux2). SxN __ Instant Messaging, free SMS, sharing photos and more... Try the new Yahoo! Canada Messenger at http://ca.beta.messenger.yahoo.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Some test fail on my new Python 2.6
I wanted to replace my old Python 2.4 and tcl/tk 8.4 with tcl/tk 8.5.6 and Python 2.6, mainly so that I can enjoy ttk. tcl/tk was installed from sources without any problem, I started a wish and worked. Now, for the Python, here are all the issues signaled by make test: running build running build_ext building 'dbm' extension gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -DHAVE_GDBM_NDBM_H -I. -I/install/Python-2.6.1/./Include -I. -IInclude -I./Include -I/usr/local/include -I/install/Python-2.6.1/Include -I/install/Python-2.6.1 -c /install/Python-2.6.1/Modules/dbmmodule.c -o build/temp.linux-i686-2.6/install/Python-2.6.1/Modules/dbmmodule.o gcc -pthread -shared build/temp.linux-i686-2.6/install/Python-2.6.1/Modules/dbmmodule.o -L/usr/local/lib -lgdbm -o build/lib.linux-i686-2.6/dbm.so *** WARNING: renaming dbm since importing it failed: build/lib.linux-i686-2.6/dbm.so: undefined symbol: dbm_firstkey building '_tkinter' extension gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -DWITH_APPINIT=1 -DWITH_BLT=1 -I/usr/X11R6/include -I. -I/install/Python-2.6.1/./Include -I. -IInclude -I./Include -I/usr/local/include -I/install/Python-2.6.1/Include -I/install/Python-2.6.1 -c /install/Python-2.6.1/Modules/_tkinter.c -o build/temp.linux-i686-2.6/install/Python-2.6.1/Modules/_tkinter.o gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -DWITH_APPINIT=1 -DWITH_BLT=1 -I/usr/X11R6/include -I. -I/install/Python-2.6.1/./Include -I. -IInclude -I./Include -I/usr/local/include -I/install/Python-2.6.1/Include -I/install/Python-2.6.1 -c /install/Python-2.6.1/Modules/tkappinit.c -o build/temp.linux-i686-2.6/install/Python-2.6.1/Modules/tkappinit.o gcc -pthread -shared build/temp.linux-i686-2.6/install/Python-2.6.1/Modules/_tkinter.o build/temp.linux-i686-2.6/install/Python-2.6.1/Modules/tkappinit.o -L/usr/X11R6/lib64 -L/usr/X11R6/lib -L/usr/local/lib -lBLT -ltk8.5 -ltcl8.5 -lX11 -o build/lib.linux-i686-2.6/_tkinter.so *** WARNING: renaming _tkinter since importing it failed: libtk8.5.so: cannot open shared object file: No such file or directory Failed to find the necessary bits to build these modules: _sqlite3 bsddb185 sunaudiodev To find the necessary bits, look in setup.py in detect_modules() for the module's name. Failed to build these modules: _tkinter dbm running build_scripts find ./Lib -name '*.py[co]' -print | xargs rm -f ./python -E -tt ./Lib/test/regrtest.py -l test_aepack test_aepack skipped -- No module named aepack test_al test_al skipped -- No module named al test_applesingle test_applesingle skipped -- No module named macostools test_bsddb185 test_bsddb185 skipped -- No module named bsddb185 test_bsddb3 test_bsddb3 skipped -- Use of the `bsddb' resource not enabled test_cd test_cd skipped -- No module named cd test_cl test_cl skipped -- No module named cl test_codecmaps_cn test_codecmaps_cn skipped -- Use of the `urlfetch' resource not enabled test_codecmaps_hk test_codecmaps_hk skipped -- Use of the `urlfetch' resource not enabled test_codecmaps_jp test_codecmaps_jp skipped -- Use of the `urlfetch' resource not enabled test_codecmaps_kr test_codecmaps_kr skipped -- Use of the `urlfetch' resource not enabled test_codecmaps_tw test_codecmaps_tw skipped -- Use of the `urlfetch' resource not enabled test_curses test_curses skipped -- Use of the `curses' resource not enabled test_dbm test_dbm skipped -- No module named dbm test_gl test_gl skipped -- No module named gl test_httpservers test test_httpservers failed -- errors occurred; run in verbose mode for details test_imgfile test_imgfile skipped -- No module named imgfile test_kqueue test_kqueue skipped -- test works only on BSD test_linuxaudiodev test_linuxaudiodev skipped -- Use of the `audio' resource not enabled test_macos test_macos skipped -- No module named MacOS test_macostools test_macostools skipped -- No module named macostools test_multiprocessing test_multiprocessing skipped -- OSError raises on RLock creation, see issue 3111! test_normalization test_normalization skipped -- Use of the `urlfetch' resource not enabled test_ossaudiodev test_ossaudiodev skipped -- Use of the `audio' resource not enabled test_pep277 test_pep277 skipped -- test works only on NT+ test_py3kwarn test_py3kwarn skipped -- test.test_py3kwarn must be run with the -3 flag test_scriptpackages test_scriptpackages skipped -- No module named aetools test_socket test test_socket failed -- Traceback (most recent call last): File /install/Python-2.6.1/Lib/test/test_socket.py, line 474, in testSockName my_ip_addr = socket.gethostbyname(socket.gethostname()) gaierror: [Errno -2] Name or service not known test_socketserver test_socketserver skipped -- Use of the `network' resource not enabled test_sqlite test_sqlite skipped -- no sqlite available test_startfile test_startfile skipped -- cannot import name startfile
Some test fail on my new Python 2.6
Hi All, I just downloaded and compiled Python 2.6 on a Gentoo Linux, IBM NetVista. After going through the usual steps (./configure, make), I ran a test (make test), and got some unexpected issues, which are detailed here: # ./python Lib/test/test_tcl.py Traceback (most recent call last): File Lib/test/test_tcl.py, line 6, in module from Tkinter import Tcl File /install/Python-2.6.1/Lib/lib-tk/Tkinter.py, line 39, in module import _tkinter # If this fails your Python may not be configured for Tk # ./python Lib/test/test_dbm.py Traceback (most recent call last): File Lib/test/test_dbm.py, line 3, in module import dbm ImportError: No module named dbm # ./python Lib/test/test_multiprocessing.py Traceback (most recent call last): File Lib/test/test_multiprocessing.py, line 1825, in module main() File Lib/test/test_multiprocessing.py, line 1822, in main test_main(unittest.TextTestRunner(verbosity=2).run) File Lib/test/test_multiprocessing.py, line 1788, in test_main raise TestSkipped(OSError raises on RLock creation, see issue 3111!) test.test_support.TestSkipped: OSError raises on RLock creation, see issue 3111! What is issue 3111? Couldn't find any reference to it. Two more: # ./python Lib/test/test_httpservers.py test_command (__main__.BaseHTTPServerTestCase) ... ok test_handler (__main__.BaseHTTPServerTestCase) ... ok test_head_keep_alive (__main__.BaseHTTPServerTestCase) ... ok test_header_close (__main__.BaseHTTPServerTestCase) ... ok test_internal_key_error (__main__.BaseHTTPServerTestCase) ... ok test_request_line_trimming (__main__.BaseHTTPServerTestCase) ... ok test_return_custom_status (__main__.BaseHTTPServerTestCase) ... ok test_return_header_keep_alive (__main__.BaseHTTPServerTestCase) ... ok test_send_blank (__main__.BaseHTTPServerTestCase) ... ok test_version_bogus (__main__.BaseHTTPServerTestCase) ... ok test_version_digits (__main__.BaseHTTPServerTestCase) ... ok test_version_invalid (__main__.BaseHTTPServerTestCase) ... ok test_version_none (__main__.BaseHTTPServerTestCase) ... ok test_version_none_get (__main__.BaseHTTPServerTestCase) ... ok test_get (__main__.SimpleHTTPServerTestCase) ... FAIL test_head (__main__.SimpleHTTPServerTestCase) ... ok test_invalid_requests (__main__.SimpleHTTPServerTestCase) ... ok test_authorization (__main__.CGIHTTPServerTestCase) ... FAIL test_headers_and_content (__main__.CGIHTTPServerTestCase) ... FAIL test_invaliduri (__main__.CGIHTTPServerTestCase) ... ok test_post (__main__.CGIHTTPServerTestCase) ... FAIL == FAIL: test_get (__main__.SimpleHTTPServerTestCase) -- Traceback (most recent call last): File Lib/test/test_httpservers.py, line 243, in test_get self.check_status_and_reason(response, 404) File Lib/test/test_httpservers.py, line 219, in check_status_and_reason self.assertEquals(response.status, status) AssertionError: 200 != 404 == FAIL: test_authorization (__main__.CGIHTTPServerTestCase) -- Traceback (most recent call last): File Lib/test/test_httpservers.py, line 340, in test_authorization (res.read(), res.getheader('Content-type'), res.status)) AssertionError: ('Hello World\n', 'text/html', 200) != ('', None, 200) == FAIL: test_headers_and_content (__main__.CGIHTTPServerTestCase) -- Traceback (most recent call last): File Lib/test/test_httpservers.py, line 321, in test_headers_and_content (res.read(), res.getheader('Content-type'), res.status)) AssertionError: ('Hello World\n', 'text/html', 200) != ('', None, 200) == FAIL: test_post (__main__.CGIHTTPServerTestCase) -- Traceback (most recent call last): File Lib/test/test_httpservers.py, line 328, in test_post self.assertEquals(res.read(), '1, python, 123456\n') AssertionError: '' != '1, python, 123456\n' -- Ran 21 tests in 3.149s FAILED (failures=4) # ./python Lib/test/test_socket.py testCrucialConstants (__main__.GeneralModuleTests) ... ok testDefaultTimeout (__main__.GeneralModuleTests) ... ok testGetServBy (__main__.GeneralModuleTests) ... ok testGetSockOpt (__main__.GeneralModuleTests) ... ok testHostnameRes (__main__.GeneralModuleTests) ... ok testIPv4toString (__main__.GeneralModuleTests) ... ok testIPv6toString (__main__.GeneralModuleTests) ... ok testInterpreterCrash (__main__.GeneralModuleTests) ... ok testNewAttributes (__main__.GeneralModuleTests) ... ok testNtoH (__main__.GeneralModuleTests) ... ok
Re: Function stopping a function
In my situation, there is a device with keyboard that allows some user input. In the same time, the device is connected to a standard PC, and there may be some communication there. The lengthy_function() resides and executes in the device, and so is cancel(). Lengthy_function() is pretty linear: according to some conditions, the user is asked for this or that. Than, with the new conditions, lenghty_function() may need to communicate with the PC. And now, with the updated conditions, may ask more stuff from user. At any time the user can press a CANCEL button, or the PC can generate a CANCEL. What I have now is a global variable which cancel() will change and then, each if statement in lenghty_function() will check that variable, together with its specific condition. I was hopping that there may be a more elegant solution. No threads involved in my design (apart for what the device may have to handle events like button-press and serial communication). Thanks everyone for your answers. Regards, SxN Get easy, one-click access to your favorites. Make Yahoo! your homepage. http://www.yahoo.com/r/hs -- http://mail.python.org/mailman/listinfo/python-list
Function stopping a function
Hi All, We all know that a function can launch the execution of another function. How can a function stop the execution of another function? For instance, lenghty_function() executes, when an external event triggers cancel(), which is supposed to abruptly stop lengthy_function(), reset some variables and exit immediately. Thanks for your advice SxN Be a better sports nut! Let your teams follow you with Yahoo Mobile. Try it now. http://mobile.yahoo.com/sports;_ylt=At9_qDKvtAbMuh1G1SQtBI7ntAcJ -- http://mail.python.org/mailman/listinfo/python-list
Re: Enter Enter... troubles
It works, thanks. Sorin Need Mail bonding? Go to the Yahoo! Mail QA for great tips from Yahoo! Answers users. http://answers.yahoo.com/dir/?link=listsid=396546091 -- http://mail.python.org/mailman/listinfo/python-list
Enter Enter... troubles
Hi All, In my application I have a class like this: from Tkinter import * class MyClass: def __init__(self, root): self.property=value self.aButton=Button(root, text='Press me!') self.aButton.bind('Return', self.handler) self.aButton.bind('KP_Enter',self.handler) ... def handler(self,event): self.aButton.unbind('Return') self.aButton.unbind('KP_Enter') ... localVar=self.property self.property=newCalculatedValue ... self.aButton.bind('Return', self.handler) self.aButton.bind('KP_Enter',self.handler) The idea is to prevent a fast user (like my boss) to press repeatedly the enter key and create havoc with self.property and localVar. But it doesn't work: my boss manages to start at least twice the handler (which, among other things creates a Toplevel, so I end up with a messy screen). How should I proceed? Thanks for your advices, Sorin - Sucker-punch spam with award-winning protection. Try the free Yahoo! Mail Beta.-- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.5 install on Gentoo Linux: failed dmb and _tkinter
# ldconfig -p | grep /usr/local/lib libtk8.4.so (libc6) = /usr/local/lib/libtk8.4.so libtcl8.4.so (libc6) = /usr/local/lib/libtcl8.4.so Sorin Now that's room service! Choose from over 150,000 hotels in 45,000 destinations on Yahoo! Travel to find your fit. http://farechase.yahoo.com/promo-generic-14795097 -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.5 install on Gentoo Linux: failed dmb and _tkinter
Did you add /usr/local/lib to /etc/ld.so.conf? It's there Sorin Do you Yahoo!? Everyone is raving about the all-new Yahoo! Mail beta. http://new.mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
Python 2.5 install on Gentoo Linux: failed dmb and _tkinter
Hi All, After a disaster in which I lost my whole harddrive, I decided to install the newest everything that I use. I put the latest Gentoo Linux, with gcc 4.1.1, installed tcl/tk 8.4.14 and tried Python 2.5. I tried with and without the suggested -fwrapv compiler option, and make gave me the same: code # make case $MAKEFLAGS in \ *-s*) CC='gcc -pthread -fwrapv' LDSHARED='gcc -pthread -fwrapv -shared' OPT='-DNDEBUG -g -O3 -Wall -Wstrict-prototypes' ./python -E ./setup.py -q build;; \ *) CC='gcc -pthread -fwrapv' LDSHARED='gcc -pthread -fwrapv -shared' OPT='-DNDEBUG -g -O3 -Wall -Wstrict-prototypes' ./python -E ./setup.py build;; \ esac running build running build_ext db.h: found (4, 2) in /usr/include db lib: using (4, 2) db-4.2 building 'dbm' extension gcc -pthread -fwrapv -fPIC -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -DHAVE_GDBM_NDBM_H -I. -I/plus/install/Python-2.5/./Include -I./Include -I. -I/usr/local/include -I/plus/install/Python-2.5/Include -I/plus/install/Python-2.5 -c /plus/install/Python-2.5/Modules/dbmmodule.c -o build/temp.linux-i686-2.5/plus/install/Python-2.5/Modules/dbmmodule.o gcc -pthread -fwrapv -shared build/temp.linux-i686-2.5/plus/install/Python-2.5/Modules/dbmmodule.o -L/usr/local/lib -lgdbm -o build/lib.linux-i686-2.5/dbm.so *** WARNING: renaming dbm since importing it failed: build/lib.linux-i686-2.5/dbm.so: undefined symbol: dbm_firstkey building '_tkinter' extension gcc -pthread -fwrapv -fPIC -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11R6/include -I. -I/plus/install/Python-2.5/./Include -I./Include -I. -I/usr/local/include -I/plus/install/Python-2.5/Include -I/plus/install/Python-2.5 -c /plus/install/Python-2.5/Modules/_tkinter.c -o build/temp.linux-i686-2.5/plus/install/Python-2.5/Modules/_tkinter.o gcc -pthread -fwrapv -fPIC -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11R6/include -I. -I/plus/install/Python-2.5/./Include -I./Include -I. -I/usr/local/include -I/plus/install/Python-2.5/Include -I/plus/install/Python-2.5 -c /plus/install/Python-2.5/Modules/tkappinit.c -o build/temp.linux-i686-2.5/plus/install/Python-2.5/Modules/tkappinit.o gcc -pthread -fwrapv -shared build/temp.linux-i686-2.5/plus/install/Python-2.5/Modules/_tkinter.o build/temp.linux-i686-2.5/plus/install/Python-2.5/Modules/tkappinit.o -L/usr/X11R6/lib64 -L/usr/X11R6/lib -L/usr/local/lib -ltk8.4 -ltcl8.4 -lX11 -o build/lib.linux-i686-2.5/_tkinter.so *** WARNING: renaming _tkinter since importing it failed: libtk8.4.so: cannot open shared object file: No such file or directory running build_scripts /code I have libtk: code # ls -l /usr/local/lib/libtk8.4.so -r-xr-xr-x 1 root root 906285 Jan 10 16:08 /usr/local/lib/libtk8.4.so /code I can start wish. I need Tkinter for sure, and I'll like to have dbm. How should I proceed? Thanks for your advice, Sorin Have a burning question? Go to www.Answers.yahoo.com and get answers from real people who know. -- http://mail.python.org/mailman/listinfo/python-list
But it was yesterday here!
(the quote is from 'Le gendarme et les extra-terrestres', a must-see Frech comedy)Hi All,I'm trying to use the smtplib - I did it so many times already. The import statement fails, as theSMTP name cannot be imported. Digging more, I found that SMTP fails becauseemail.base64MIME cannot be imported (ImportError:No module named base64MIME).I don't understand why, as the file is in the right location, has the correct access rights (I'm onLinux), and it's content is not corrupt. I also tried to import email.__init__ and end up with the same error.The only way that works is to navigate to the email directory and perform the import base64MIME there.What may have happened?Thanks,Sorin-- http://mail.python.org/mailman/listinfo/python-list
But it was yesterday here!
I bet you have an email.py somewhere in your sources... You won the bet. I owe you one :-)Thanks,Sorin-- http://mail.python.org/mailman/listinfo/python-list
Tkinter question
Thanks for everybody's advice, on both forums (tkinter-discuss python-list).I end up using Fredrik's Lundh solution, since, in my project, multiple buttons are using the same callback, and their creation is controlled by the interaction with the user.Thanks again,Sorin-- http://mail.python.org/mailman/listinfo/python-list
Tkinter question
Hi All,Is it possible to have a widget id while it is created?Something like this:Button(root, text='...', command= lambda v=widget id: fn(v)).grid()and then the function:def fn(v): v['bg']='BLUE' # or maybe nametowidget(v)['bg']='BLUE'Thanks,Sorin-- http://mail.python.org/mailman/listinfo/python-list
overrideredirect and Text widget
Hi again,Last afternoon I posted a question regarding the loss of keyboard in an undecorated window. Last night I tried again, at home, and the same code worked fine. The difference: it failed under (Gentoo) Linux, it succeeded under Win 2000, both running Python 2.4.x.So, I guess, my question now is how to achieve the desired behaviour under Linux?Thanks for your advice,Sorin-- http://mail.python.org/mailman/listinfo/python-list
I need some help with a regexp please
Hi,My $0.02:re.compile('^\w+([\.-]?\w+)[EMAIL PROTECTED]([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|intl|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$')I picked it up from the Net, and while it may be not perfect (you've got lots of reply's telling you why),it's good enough for me.Good luck,Sorin-- http://mail.python.org/mailman/listinfo/python-list
overrideredirect and Text widget
Hi,I'm trying to place in an undecorated window a Text widget, and a button to close the window/save widget's content. My test code is the following:codefrom Tkinter import *root=Tk()root['bg']='' # transparent backgroundroot.overrideredirect(1) # get rid of borderroot.geometry("+80+120") # place on screenroot.focus_set() # take focusbt=Button(text="End",command=root.quit)bt.grid(row=0, stick=E) # a button to allow window's closuretx=Text(bg='white',height=3)tx.grid() # a text widgettx.focus() # give focus to textroot.mainloop()/codeOn my machine it doesn't give focus to Text. Any advice?Thanks,Sorin-- http://mail.python.org/mailman/listinfo/python-list
Tkinter listbox:get
lb.curselection() won't return an integer, but a tuple of strings. Also, a StringVar receives a new value with the set() method. So, you'll have to write something like:idx=lb.curselection()StringValue.set(lb.get(int(idx[0])))This will grab the first value from the tuple, convert it in integer, and pass it to lb.get() to extract the line in your Listbox, and set it in your Entry via the StringVar. If you allow multiple selections from your Listbox, you may have more than one value in idx, and you'll have to decide how you intend to process them.Check any of these (or both):http://www.pythonware.com/library/tkinter/introduction/index.htmhttp://infohost.nmt.edu/tcc/help/pubs/tkinter/They're both easy to follow, and you'll save more time, than asking one little think at a time, and then waiting for someone to answer.Good luck!Sorin-- http://mail.python.org/mailman/listinfo/python-list
rollover effect
Hi, For the right-click event, you should use a bind to Button-3. If you have a new version of Python, chances are that you already have Tix installed. Tix, like Pmw, is an extension package for Tkinter, and it also offers a Balloon widget. See the following example: code from Tix import * r=Tk() l=Label(r,text='This is my label') def fn(e): global l print 'Right clicked :-)' l.bind('Button-3',fn) l.grid() b=Balloon(r) b.bind_widget(l,balloonmsg='text in balloon') r.mainloop() /code If you're a beginer, than you may want to have a look to some of the following links regarding Tkinter and extensions: http://www.pythonware.com/library/tkinter/introduction/index.htm http://infohost.nmt.edu/tcc/help/pubs/tkinter/ http://www.ferg.org/thinking_in_tkinter/index.html http://mail.python.org/pipermail/tkinter-discuss/ http://www.3dartist.com/WP/python/tknotes.htm http://tkinter.unpy.net/wiki/FrontPage http://www.faqts.com/knowledge_base/index.phtml/fid/264 http://pmw.sourceforge.net/doc/index.html http://heim.ifi.uio.no/~hpl/Pmw.Blt/doc/ http://pmwcontribd.sourceforge.net/ http://tcltk.free.fr/blt/ http://tkinter.unpythonic.net/bwidget/BWman/ http://tcltk.free.fr/Bwidget/ http://tktreectrl.sourceforge.net/treectrl.html http://tix.sourceforge.net/docs.shtml http://groups.yahoo.com/group/tix/messages/1 http://cvs.sourceforge.net/viewcvs.py/tkta http://www.tkzinc.org/ble/ http://tktreectrl.sourceforge.net/Understanding TkTreeCtrl.html http://cvs.sourceforge.net/viewcvs.py/*checkout*/tktable/tile-www/doc/index.html http://wiki.tcl.tk/6172http://www.faqts.com/knowledge_base/view.phtml/aid/3728 http://www.faqts.com/knowledge_base/view.phtml/aid/3728 I see I have a rather long list of bookmarks ;-) I hope this helps. Sorin __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
How to let a loop run for a while before checking for break condition?
to Fredrik Lundh I'm afraid Claudio Grondi can't use your solution, as he needs it hosted on Windows, which lacks signal.alarm. to Claudio Grondi How about splitting your loop in two? The first loop would check for your boolean, which is changed by your timer, the second loop will check for your normal exit condition? Sorin __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
How to let a loop run for a while before checking for break condition?
I am thinking on something in the following form: code import time import thread delay=True def fn() global delay time.sleep(your_amount_of_time_in_seconds) delay=False thread.start_new_thread(fn,()) while delay: statement 1 statement 2 ... while other_condition: statement 1 statement 2 ... /code Or, if you need to use break, the second loop may be something like: code while True: statement 1 statement 2 ... if other_condition: break other_statements ... /code The two while loops have the same content, but the first is terminated after a pre-determined amount of time, while the second by another condition. Usually the content of the too loops, being the same, is a call to a function that does the actual work. In your case, as time seems to be critical, you don't want to spend it in function-call overheads, so you repeat (cut'n'paste) the relevant code. Of course, the price to be paid is in maintenance headache: you'll have to make all the changes in both loops, to keep consistency. I hope this helps. Sorin __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
signal - no update 'til I move the mouse
Hi, My project needs to allow some inter-process communication. That one is solved, and when an answer is sent, it goes to its destination via a signal. Then, the Tkinter screen needs to be updated, so the user can take the next action. On my laptop it works instantly, on my desktop, only after I move the mouse inside my application's window. Configurations: Laptop: Dell Latitude C600, Gentoo Linux, kernel 2.6.11, Python 2.4.1, KDE 3.3.x Desktop: IBM NetVista, Gentoo Linux, kernel 2.6.11, Python 2.4.2, KDE 3.4.x I am pretty sure that's not a Tkinter related issue, since I tested some print statements and they behave in a similar way, but what can it be? Thanks for your advise, Sorin __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
Tkinter's createfilehandler - attempt to run parallel threads
Hi,The project that I'm working for runs a PostgreSQL database on a remote machine and several Python clients all over the place. The objects usualy have in their constructor a query to the database. As the query is executed on the remote machine, I'm trying to be fancy and execute it while building my Tkinter interface.The following code illustrates what I'm attempting to do:code#! /usr/bin/pythonfrom pg import DBfrom Tkinter import *class thrd: def __init__(s,r): print 'Executing __init__' db=DB('design',host='xx.xx.xx.xx',user='') # relevant IP and user needed print 'db=DB(...' tkinter.createfilehandler(db,tkinter.READABLE|tkinter.WRITABLE,s.th) print 'createfile...' Label(r,text='Let\'s see the results').grid() print 'Label...' s.b=Button(r,text='GO') print 's.b=Button...' s.b.bind('Button-1',s.rslt) print 's.b.bind...' s.b.grid() print 's.b.grid()' print '__init__ done' def th(s,db,msk): print '-Executing th' s.r=db.query('select * from customers limit 10').getresult() # some query print '-s.r=...' tkinter.deletefilehandler(db) print '-deletefile...' db.close() print '-db.close()' print '-th done' def rslt(s,e): for i in s.r: print iif __name__=='__main__': r=Tk() t=thrd(r) r.mainloop()/codeThe output is:Executing __init__codedb=DB(...createfile...Label...s.b=Button...s.b.bind...s.b.grid()__init__ done-Executing th-s.r=...-deletefile...-db.close()-th done/codeand it basicly shows that everything happens sequentialy. Pressing the button gives the expected result, so everything is correct. How can I obtain the desired parallelism?Thanks,Sorin Groups are talking. Were listening. Check out the handy changes to Yahoo! Groups. -- http://mail.python.org/mailman/listinfo/python-list
Tix Tree open/close issue
It works. Thanks Rob. Sorin __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
Tix Tree open/close issue
Hi, I tried for the first time a Tix Tree, so, if my question is naive, I apologize upfront. The following code: code from Tix import * r=Tk() tr=Tree(r) tr.subwidget('hlist').add('br1',text='branch 1') tr.subwidget('hlist').add('br1.b1',text='branch 1-1') tr.subwidget('hlist').add('br1.b1.b1',text='branch 1-1-1') tr.subwidget('hlist').add('br1.b1.b2',text='branch 1-1-2') tr.subwidget('hlist').add('br1.b2',text='branch 1-2') tr.subwidget('hlist').add('br1.b2.b1',text='branch 1-2-1') tr.subwidget('hlist').add('br1.b2.b2',text='branch 1-2-2') r.tk.call(tr,'setmode','br1','close') r.tk.call(tr,'setmode','br1.b1','open') r.tk.call(tr,'setmode','br1.b2','open') #tr.setmode('br1','close') #tr.setmode('br1.b1','open') #tr.setmode('br1.b2','open') tr.grid() r.mainloop() /code will show the whole tree, but will set correctly the (+) and (-) boxes. (The commented out statements where in place before direct calls to Tk - same result). I was hoping to have some branches hidden (the leaves, in this case). How should I proceed? Thanks, Sorin __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
Tkinter, grid, in_: widget definition order significant ?!
Hi,Working on my current project, I discovered the following behaviour: a widget defined before the window in which I try to grid it won't show up, but will take space and behave like it is there (blind typing proves it). A widget defined after the griding window will come up fine. The following example illustrates my point:codefrom Tkinter import *r=Tk()l1=Label(r, text='first label')f=Frame(r)f.grid()l1.grid(in_=f, row=0)l2=Label(r, text='second label')l2.grid(in_=f, row=1)/codeOn my system (Gentoo Linux, Python 2.4.1) l1 (defined before f) takes spaces, but is invisible, while l2 (defined after f) is OK.That's the way it is intended to be? How would I grid stuff in dynamically created windows?Thanks for your advice,Sorin Schwimmer How low will we go? Check out Yahoo! Messengers low PC-to-Phone call rates.-- http://mail.python.org/mailman/listinfo/python-list