Re: Is it possible to pass a parameter by reference?
It is usually clearer to explicitely return values that are changed by a function and re-assign it to the same variable, x=something1 a = something2 def f1(s,t): # do something with t, # do something to s return s a = f1(a,x) Be aware however that you can wrap 'a' in a list for the same effect, (but it is not as easy to read). x=something1 aa = [something2] def f2(ss,t): s= ss[0] # do something with t, # do something to s ss[0]=s f2(aa,x) a=aa[0] -- Pad. -- http://mail.python.org/mailman/listinfo/python-list
Re: function expression with 2 arguments
? -- http://mail.python.org/mailman/listinfo/python-list
lambda strangeness??
I was playing with lambdas and list compregensions and came across this unexpected behaviour: adds = [lambda y: (y + n) for n in range(10)] adds[0](0) 9 for n in range(5): print adds[n](42) ... 42 43 44 45 46 adds[0](0) 4 Can anyone explain the different answers I'm getting? FWIW the behaviour I expected was what seems to happen inside the for loop... It seems to somehow be related to the last value in the range(), am I somehow picking that up as y? If so why? Or is that just a coincidence? And why did it work inside the for loop? Puzzled, Alan G. Author of the Learn to Program website http://www.freenetpages.co.uk/hp/alan.gauld -- http://mail.python.org/mailman/listinfo/python-list
Re: lambda strangeness??
On Sun, 27 Feb 2005 09:07:28 + (UTC), Alan Gauld [EMAIL PROTECTED] wrote: adds = [lambda y: (y + n) for n in range(10)] adds[0](0) 9 for n in range(5): print adds[n](42) ... 42 43 the for loop... It seems to somehow be related to the last value in the range(), am I somehow picking that up as y? Further exploration suggests I'm picking it up as n not y, if that indeed is what's happening... Alan G. Author of the Learn to Program website http://www.freenetpages.co.uk/hp/alan.gauld -- http://mail.python.org/mailman/listinfo/python-list
wxPython/IEHtmlWindow documentation (what events are available ?)
Hi - I've got a script which is making use of ... import wx.lib.iewinas iewin ... and so ... self.ie = iewin.IEHtmlWindow(self, -1, style = wx.NO_FULL_REPAINT_ON_RESIZE) ... but I can't find any documentation about what a IEHtmlWindow object might do - in particular what I might do with the events. I have some sample code and I've taken a look at iewin.py but what I would like to know is when the various events are going to fire ? 'DOCUMENTCOMPLETE' seems fairly self-explanatory but others such as 'BEFORENAVIGATE2' and 'STATUSTEXTCHANGE' are less guessable. I've looked at (what I think is) the MS documentation but I cannot find references to any of these events - can anyone point me information please ? Thanks Richard. -- http://mail.python.org/mailman/listinfo/python-list
best XSLT processor?
Which XSLT processor is the most reliable? requirement: + must support Python 2.4 + must run w/ Windows (and Linux) + not super slow My python project needs a XSLT processor + Docbook's XSLT to translate from docbook-xml - HTML. PyXML? is it reliable? Slow? 4Suite? some said it is buggy (lots of work arounds)? Others ??? Thx! -- http://mail.python.org/mailman/listinfo/python-list
Controlling Pc From Server?
Hello NG, I am trying to find some information about the possibility to control two (or more) clients (PCs) via a Python application running on a main server. Ideally, this application should be able to monitor (almost in real time) the activity of these clients (which applications are launched, closed and so on, if this is even possible, obviously). Does anyone have to share some information/pointer? Thank you a lot. Andrea. -- http://mail.python.org/mailman/listinfo/python-list
Re: lambda strangeness??
Alan Gauld wrote: I was playing with lambdas and list compregensions and came across this unexpected behaviour: adds = [lambda y: (y + n) for n in range(10)] adds[0](0) 9 for n in range(5): print adds[n](42) ... 42 43 44 45 46 adds[0](0) 4 Can anyone explain the different answers I'm getting? FWIW the behaviour I expected was what seems to happen inside the for loop... It seems to somehow be related to the last value in the range(), am I somehow picking that up as y? If so why? You're picking it up not as y but as n, since n in the lambda is evaluated when you call the lambde, not when you define it. Or is that just a coincidence? And why did it work inside the for loop? In the loop you are giving n exactly the values you intended it to have inside the lambda. Check what happens when you use a different loop variable: for i in range(5): print adds[i](0) 9 9 9 9 9 I guess you could something like this instead: adds=[] for n in range(10): def f(y, n=n): return y+n adds.append(f) adds[0](0) 0 adds[0](5) 5 adds[9](5) 14 -- Codito ergo sum Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list
Re: fdups: calling for beta testers
John Machin wrote: I've tested it intensively Famous Last Words :-) ;-) (1) Manic s/w producing lots of files all the same size: the Borland C[++] compiler produces a debug symbol file (.tds) that's always 384KB; I have 144 of these on my HD, rarely more than 1 in the same directory. Not sure what you want me to do about it. I've decreased the minimum block size once more, to accomodate for more files of the same length without increasing the total amount of memory used. (2) There appears to be a flaw in your logic such that it will find duplicates only if they are in the *SAME* directory and only when there are no other directories with two or more files of the same size. Ooops... A really stupid mistake on my side. Corrected. (3) Your fdups-check gadget doesn't work on Windows; the commands module works only on Unix but is supplied with Python on all platforms. The results might just confuse a newbie: Why not use the Python filecmp module? Done. It's also faster AND it works better. Thanks for the suggestion. Please fetch the new version from http://www.homepages.lu/pu/fdups.html. -pu -- http://mail.python.org/mailman/listinfo/python-list
Text To Speech with pyTTS
Hi, I was wondering if anyone has had any luck with the python text to speech (pyTTS) module available on Sourceforge: http://sourceforge.net/projects/uncassist I have followed the tutorial for pyTTS at: http://www.cs.unc.edu/~parente/tech/tr02.shtml Using the first simple speech example: import pyTTS tts = pyTTS.Create() tts.Speak(Hello World!) I get the following error on the call to pyTTS.Create() C:\Program Files\Python23\Lib\site-packages\pyTTSpython ActivePython 2.3.2 Build 232 (ActiveState Corp.) based on Python 2.3.2 (#49, Nov 13 2003, 10:34:54) [MSC v.1200 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. import pyTTS tts = pyTTS.Create() Traceback (most recent call last): File stdin, line 1, in ? File C:\Program Files\Python23\Lib\site-packages\pyTTS\__init__.py, line 28, in Create raise ValueError('%s not supported' % api) ValueError: SAPI not supported I followed the instructions in the tutorial in order and installed the required packages in the following order, given that I already had an ActiveState Python 2.3 installation under Windows XP. 1) wxPython2.5-win32-unicode-2.5.3.1-py23.exe (didn't already have this and some of the pyTTS demos need it) 2) Microsoft SAPI 5.1 (SAPI5SpeechInstaller.msi) 3) Extra Microsoft Voices (SAPI5VoiceInstaller.msi) 4) pyTTS-3.0.win32-py2.3.exe (pyTTS for Python 2.3 under windows) I ran the example and it didn't work. I didn't initially install Mark Hammond's Python win32all extensions, because they already come with ActiveState Python. So I tried installing the win32all (win32all-163.exe) package just in case, but I still get the SAPI not supported error. Anyone get this working - any suggestions? Or am I missing something obvious? Thanks In Advance. Mike P. -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting HTML to ASCII
Grant Edwards [EMAIL PROTECTED] wrote: First, make it work. Then make it work right. Then worry about how fast it is. Premature optimization... That could be - but then again, most of the comments I've seen for that particular issue are for rather old releases. It seems to use a quadratic algorithm for remembering where the links point, or something. I wrote a very crude but very fast renderer in C that I can post if someone wants it, which is what I use for this purpose. If lynx really is too slow, try w3m or links. Both do a better job of rendering anyway. They lay out tables more/less as expected (though navigation in tables for links seems to be an afterthought). -- Thomas E. Dickey http://invisible-island.net ftp://invisible-island.net -- http://mail.python.org/mailman/listinfo/python-list
Googlewhacker
Hi folks, Has anyone seen 'Googlewhack Adventure'? http://www.davegorman.com/googlewhack.htm I wrote a script to generate Googlewhacks - thought I'd share it with you. I'd better stop running it as I fear Google may ban my IP for making 20 searches a seconds.. Will McGugan import random import urllib2 import threading WHACKER_THREADS = 20 random.seed() wordlist = [ line.rstrip() for line in file(word.lst) ] whacks = file( whacks.txt, a ) class WhackerThread( threading.Thread ): excluded = /dict .lst word.lst .txt words.split() def run(self): def check_word( word ): url = http://dictionary.reference.com/search?q=%s; % word dict_page = urllib2.urlopen( url ).read() return Did You Mean not in dict_page def is_excluded(page): for word in WhackerThread.excluded: if word in page: return True return False while( True ): word_a = random.choice( wordlist ) #word_a = haggis word_b = random.choice( wordlist ) words = word_a + + word_b google_url = http://www.google.com/search?hl=enq=%s+%sbtnG=Google+Search; % ( word_a, word_b ) opener = urllib2.build_opener() opener.addheaders = [('User-agent', 'Mozilla/5.0')] google_page = opener.open(google_url).read() if is_excluded( google_page ): print words + (probably a word list) continue if Results b1/b - b1/b of b1/b in google_page: if not check_word( word_a ): print %s (%s is not in dicionary.com) % (words, word_a) elif not check_word( word_b ): print %s (%s is not in dicionary.com) % (words, word_b) else: print words + WHACK! print whacks, words whacks.flush() else: print words + (no whack) Threads= [ WhackerThread() for _ in xrange(WHACKER_THREADS) ] for whacker_thread in Threads: whacker_thread.start() -- http://mail.python.org/mailman/listinfo/python-list
Re: Googlewhacker
Will McGugan wrote: Hi folks, Has anyone seen 'Googlewhack Adventure'? http://www.davegorman.com/googlewhack.htm I wrote a script to generate Googlewhacks - thought I'd share it with you. I'd better stop running it as I fear Google may ban my IP for making 20 searches a seconds.. Oops, wrong script.. Will import random import urllib2 import threading WHACKER_THREADS = 20 random.seed() wordlist = [ line.rstrip() for line in file(word.lst) ] whacks = file( whacks.txt, a ) class WhackerThread( threading.Thread ): excluded = /dict .lst word.lst .txt words.split() def run(self): def check_word( word ): url = http://dictionary.reference.com/search?q=%s; % word dict_page = urllib2.urlopen( url ).read() return No entry found not in dict_page def is_excluded(page): for word in WhackerThread.excluded: if word in page: return True return False while( True ): word_a = random.choice( wordlist ) #word_a = haggis word_b = random.choice( wordlist ) words = word_a + + word_b google_url = http://www.google.com/search?hl=enq=%s+%sbtnG=Google+Search; % ( word_a, word_b ) opener = urllib2.build_opener() opener.addheaders = [('User-agent', 'Mozilla/5.0')] google_page = opener.open(google_url).read() if is_excluded( google_page ): print words + (probably a word list) continue if Results b1/b - b1/b of b1/b in google_page: if not check_word( word_a ): print %s (%s is not in dicionary.com) % (words, word_a) elif not check_word( word_b ): print %s (%s is not in dicionary.com) % (words, word_b) else: print words + WHACK! print whacks, words whacks.flush() else: print words + (no whack) Threads= [ WhackerThread() for _ in xrange(WHACKER_THREADS) ] for whacker_thread in Threads: whacker_thread.start() -- http://mail.python.org/mailman/listinfo/python-list
Re: string methods (warning, newbie)
Jimmy Retzlaff wrote: Anthonyberet wrote: Is there a string mething to return only the alpha characters of a string? eg 'The Beatles - help - 03 - Ticket to ride', would be 'TheBeatlesTickettoride' If not then how best to approach this? I have some complicated plan to cut the string into individual characters and then concatenate a new string with the ones that return true with the .isalpha string method. Is there an easier way? The approach you are considering may be easier than you think: filter(str.isalpha, 'The Beatles - help - 03 - Ticket to ride') 'TheBeatleshelpTickettoride' Thanks very much - that's the level of knowledge of Python that I just don't have yet - everything I try to do seems to have a much easier way, that I haven't encountered yet :) I shall read up on the elements of your code to understand exactly what it is doing. -- http://mail.python.org/mailman/listinfo/python-list
Re: error: db type could not be determined
Thank you for your reply, Jhon. It was useful advice. Take a hint: they say Google is your friend, but better still is the source in lib\*.py -- it's quite legible, you don't need an Internet connection, and there sure ain't no ads in the margin. And don't just open it in emergencies: pick a module that covers a topic that interests you and just read it. You'll see good coding style, good ways of doing things, wise utterances by the timbot, ... I am new to programing so I was wasting a lot of time to fix bug, only struggling with my code where an error has occured then read throug an book at hand. I didn't think of such an approch to solve problems and read error messages. Thank you again very much for the imformative advice. -- http://mail.python.org/mailman/listinfo/python-list
Re: Controlling Pc From Server?
[EMAIL PROTECTED] said the following on 2/27/2005 4:44 AM: Hello NG, I am trying to find some information about the possibility to control two (or more) clients (PCs) via a Python application running on a main server. Ideally, this application should be able to monitor (almost in real time) the activity of these clients (which applications are launched, closed and so on, if this is even possible, obviously). Does anyone have to share some information/pointer? Thank you a lot. Andrea. Andrea, Since you have not specified any operating system, my suggestion is for you to go for a generic solution like pyheartbeat. Pyheartbeat is a program with server and client components and uses UDP to monitor which client computers are down and which, active. You can modify pyheartbeat to do what you are wanting, by wrapping your monitoring functions and sending that information back to the server. To make things more elegant, you could probably come up with an XML schema (or other formatted text like JSON or use Pickle to serialize/de-serialze data structures) so that the information is machine-friendly but you still can translate the XML for a pretty display on the server. Pyheartbeat can be found at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52302 If you are using Windows NT-based technology, you can setup your clients so that all activity is logged to the server; I believe there are 3rd pary applications available that can do this for you. Sorry, I don't know the specifics on how to do it. For *nix OSes, you can have the syslog daemon log to a remote machine instead of the local. So, you can log all activity to the UNIX server. (Though, to me, it appears that you are looking for remote top like functionality for networked PCs). Thanks, -Kartic -- http://mail.python.org/mailman/listinfo/python-list
Controlling Pc From Server?
Hello Kartic NG, Thank you for your prompt answer. In effect, I'm trying to work on a NT network of 6 PC (plus the server). Sorry to not have been clearer. Ideally, I'm trying to monitor the Internet activity of each client (PC) on this network (but I'm not a boss trying to control my emplyees, I'm just curious on it). I would like to know which PC is connected to Internet (by starting something like a timer for every PC, and then periodically check if a particular PC is connected or not). This should be done from the main server. Did I make myself clear? Do you think it would be a huge task? Sorry, it may be a very basic question, but thank you for your help. Andrea. -- http://mail.python.org/mailman/listinfo/python-list
Re: Controlling Pc From Server?
[EMAIL PROTECTED] said the following on 2/27/2005 8:40 AM: Hello Kartic NG, Thank you for your prompt answer. In effect, I'm trying to work on a NT network of 6 PC (plus the server). Sorry to not have been clearer. Ideally, I'm trying to monitor the Internet activity of each client (PC) on this network (but I'm not a boss trying to control my emplyees, I'm just curious on it). I would like to know which PC is connected to Internet (by starting something like a timer for every PC, and then periodically check if a particular PC is connected or not). This should be done from the main server. Did I make myself clear? Do you think it would be a huge task? Sorry, it may be a very basic question, but thank you for your help. Andrea. Sounds like you are spying :-D Your requirement may sound basic but I don't *think* it is simple to do. Since you are using NT, you can probably see if there is some Network Usage auditing tool. This might cost you some $$ or may be you can find some shareware. For a homegrown solution, if I am not mistaken, you will have to use libpcap (or pypcap) to monitor the packets being sent and received, taking care to exclude the local subnet (or your reporting will be skewed as packets sent to the monitoring server will also be included!). You can check http://www.monkey.org/~dugsong/pypcap/ for more details...and may be for more ideas. Thanks, -Kartic -- http://mail.python.org/mailman/listinfo/python-list
Re: Controlling Pc From Server?
[EMAIL PROTECTED] a écrit : Hello Kartic NG, Thank you for your prompt answer. In effect, I'm trying to work on a NT network of 6 PC (plus the server). Sorry to not have been clearer. Ideally, I'm trying to monitor the Internet activity of each client (PC) on this network (but I'm not a boss trying to control my emplyees, I'm just curious on it). I would like to know which PC is connected to Internet (by starting something like a timer for every PC, and then periodically check if a particular PC is connected or not). This should be done from the main server. Did I make myself clear? Do you think it would be a huge task? Sorry, it may be a very basic question, but thank you for your help. Andrea. If what you want is to monitor internet requests, the best place to do so is the gateway of your network. If you don't have access to the gateway, you can always set your server as the gateway for your machines and your server will need to redirect the IP flux to the real gateway. That way, you don't need anything on the client side. On the server, just look at the fluxes toward the internet and you can do wathever you want with it. After that, as I don't know the windows implementation of a gateway, I can't help you ... Pierre -- http://mail.python.org/mailman/listinfo/python-list
Re: Controlling Pc From Server?
Kartic said the following on 2/27/2005 8:54 AM: For a homegrown solution, if I am not mistaken, you will have to use libpcap (or pypcap) to monitor the packets being sent and received, taking care to exclude the local subnet (or your reporting will be skewed as packets sent to the monitoring server will also be included!). You can check http://www.monkey.org/~dugsong/pypcap/ for more details...and may be for more ideas. http://winpcap.polito.it/docs/man/html/group__remote__help.html - Should help. This uses the Winpcap library. Not sure if the same can be done using the Python bindings for pcap. -- http://mail.python.org/mailman/listinfo/python-list
Re: class factory example needed (long)
Gary Ruben wrote: I have a class factory problem. You could say that my main problem is that I don't understand class factories. My specific problem: I have a class with several methods I've defined. To this class I want to add a number of other class methods where the method names are taken from a list. For each list member, I want to build a method having the list member name so that I can override another method of the same name for objects which are instances of this class. Finally, I want my class factory which creates the method to call the overridden method. I'm sure my description is confusing, so I'll try to illustrate it. import Numeric # The Numeric module contains a whole lot of methods which operate on certain number types class foo: this is a number type class def __init__(self, value): self.value = float(value) def __str__(self): . . other methods here . import string ufuncs = string.split( sqrt arccos arccosh arcsin arcsinh arctan arctanh cos cosh tan tanh log10 sin sinh sqrt absolute fabs floor ceil fmod exp log conjugate )# these are the methods from Numeric that I want to override/wrap for my number type for u in ufuncs: I need something here which builds methods called sqrt(), arccos(), etc. An illustrative example of the class methods I want to build with some sort of class factory is def sqrt(self): val = Numeric.sqrt(self.value) return foo(Numeric.sqrt(self.value) + 42) def arccos(self): val = Numeric.arccos(self.value) return foo(Numeric.arccos(self.value) + 42) if __name__ == __main__: a = 9 b = foo(7) print Numeric.sqrt(a) print Numeric.sqrt(b) This would print 3 7 Note that the methods I want to create under program control are all identical in form. In this example they all call the wrapped method with an argument 42 greater than the value of the number. Does anyone have an example where they've done something similar or could help me out with an example? thanks in anticipation, Gary Hi Gary, you want your 'class factory' to change the methods of Numeric, so that they accept foo objects and return foo objects? I've not the slightest idea how to achieve that. If OTOH you want your foo class to have sqrt, arccos, etc. methods without defining them explicitly, I think you're looking for something like: . import Numeric . . class Foo(object): . def __init__(self, value): . self.value = float(value) . for u in ['sqrt', 'cos', 'tan']: . setattr(self, u, lambda uf=getattr(Numeric, u): . uf(self.value + 42.0)) f = Foo(7) f.sqrt() 7.0 HTH Rainer -- http://mail.python.org/mailman/listinfo/python-list
Re: problem installing wxPython 2.5.3, wxWidgets installed ok
[EMAIL PROTECTED] a écrit: I'm trying to install wxPython 2.5.3.1 using Python 2.3.2 on a Fedora 2 machine. I have python in a non-standard place, but I'm using --prefix with the configure script to point to where I have everything. The make install in $WXDIR seemed to go fine. I have the libxw* libraries in my lib/ directory libwx_base-2.5.so@libwx_gtk_adv-2.5.so.3.0.0* libwx_base-2.5.so.3@ libwx_gtk_core-2.5.so@ libwx_base-2.5.so.3.0.0* libwx_gtk_core-2.5.so.3@ libwx_base_net-2.5.so@libwx_gtk_core-2.5.so.3.0.0* libwx_base_net-2.5.so.3@ libwx_gtk_gl-2.4.so@ libwx_base_net-2.5.so.3.0.0* libwx_gtk_gl-2.4.so.0@ libwx_base_xml-2.5.so@libwx_gtk_gl-2.4.so.0.1.1* libwx_base_xml-2.5.so.3@ libwx_gtk_html-2.5.so@ libwx_base_xml-2.5.so.3.0.0* libwx_gtk_html-2.5.so.3@ libwx_gtk-2.4.so@ libwx_gtk_html-2.5.so.3.0.0* libwx_gtk-2.4.so.0@ libwx_gtk_xrc-2.5.so@ libwx_gtk-2.4.so.0.1.1* libwx_gtk_xrc-2.5.so.3@ libwx_gtk_adv-2.5.so@ libwx_gtk_xrc-2.5.so.3.0.0* libwx_gtk_adv-2.5.so.3@ I also have a wx/ directory under my lib. directory. The problem is when I try to do a 'python setup.py install' in the ./wxPython directory. I get a message about not finding a config file for wx-config and then several errors during gcc compiles. python setup.py build Found wx-config: /project/c4i/Users_Share/williams/Linux/bin/wx-config Using flags: --toolkit=gtk2 --unicode=no --version=2.5 Warning: No config found to match: /project/c4i/Users_Share/williams/Linux/bin/wx-config --toolkit=gtk2 --unicode=no --version=2.5 --cxxflags in /project/c4i/Users_Share/williams/Linux/lib/wx/config If you require this configuration, please install the desired library build. If this is part of an automated configuration test and no other errors occur, you may safely ignore it. You may use wx-config --list to see all configs available in the default prefix. ... Preparing OGL... Preparing STC... Preparing GIZMOS... running build running build_py copying wx/__version__.py - build-gtk2/lib.linux-i686-2.3/wx running build_ext building '_core_' extension creating build-gtk2/temp.linux-i686-2.3 creating build-gtk2/temp.linux-i686-2.3/src creating build-gtk2/temp.linux-i686-2.3/src/gtk gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -DSWIG_GLOBAL -DHAVE_CONFIG_H -DWXP_USE_THREAD=1 -UNDEBUG -DXTHREADS -D_REENTRANT -DXUSE_MTSAFE_API -Iinclude -Isrc -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/X11R6/include -I/usr/include/atk-1.0 -I/usr/include/pango-1.0 -I/usr/include/freetype2 -I/usr/include/freetype2/config -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/project/c4i/Users_Share/williams/Linux/include/python2.3 -c src/libpy.c -o build-gtk2/temp.linux-i686-2.3/src/libpy.o -O3 gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -DSWIG_GLOBAL -DHAVE_CONFIG_H -DWXP_USE_THREAD=1 -UNDEBUG -DXTHREADS -D_REENTRANT -DXUSE_MTSAFE_API -Iinclude -Isrc -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/X11R6/include -I/usr/include/atk-1.0 -I/usr/include/pango-1.0 -I/usr/include/freetype2 -I/usr/include/freetype2/config -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/project/c4i/Users_Share/williams/Linux/include/python2.3 -c src/gtk/_core_wrap.cpp -o build-gtk2/temp.linux-i686-2.3/src/gtk/_core_wrap.o -O3 cc1plus: warning: command line option -Wstrict-prototypes is valid for Ada/C/ObjC but not for C++ In file included from src/gtk/_core_wrap.cpp:400: include/wx/wxPython/wxPython_int.h:19:19: wx/wx.h: No such file or directory include/wx/wxPython/wxPython_int.h:21:25: wx/busyinfo.h: No such file or directory include/wx/wxPython/wxPython_int.h:22:22: wx/caret.h: No such file or directory include/wx/wxPython/wxPython_int.h:23:25: wx/choicebk.h: No such file or directory include/wx/wxPython/wxPython_int.h:24:24: wx/clipbrd.h: No such file or directory include/wx/wxPython/wxPython_int.h:25:25: wx/colordlg.h: No such file or directory include/wx/wxPython/wxPython_int.h:26:23: wx/config.h: No such file or directory include/wx/wxPython/wxPython_int.h:27:23: wx/cshelp.h: No such file or directory include/wx/wxPython/wxPython_int.h:28:25: wx/dcmirror.h: No such file or directory include/wx/wxPython/wxPython_int.h:29:21: wx/dcps.h: No such file or directory include/wx/wxPython/wxPython_int.h:30:24: wx/dirctrl.h: No such file or directory include/wx/wxPython/wxPython_int.h:31:23: wx/dirdlg.h: No such file or directory include/wx/wxPython/wxPython_int.h:32:20: wx/dnd.h: No such file or directory include/wx/wxPython/wxPython_int.h:33:24: wx/docview.h: No such file or directory include/wx/wxPython/wxPython_int.h:34:24: wx/encconv.h: No such file or directory include/wx/wxPython/wxPython_int.h:35:25: wx/fdrepdlg.h: No such file or direct ... Why isn't there a
Beginner PyGTK and MySQL abuse request
Hey, I've spent far too long being spoilt by a relatively simplistic just do it style of database application in use at work and have decided to try my hand at some Python + MySQL + GTK over the next few days. I've managed to steal/write a short script that asks for some input and searches a database and print the results and was wondering if people would have the time to suggest better ways of doing the limited set of things it does? ---search.py--- #!/usr/bin/env python import pygtk pygtk.require('2.0') import gtk import adodb class AddressSearch: def delete_event(self, widget, data=None): gtk.main_quit() return gtk.FALSE def btn_search(self, widget, data=None): conn = adodb.NewADOConnection('mysql') conn.Connect('localhost','root','','rtl') sql = select * from address where match(Address1, Address2, Address3, Address4, Address5) against('+ + self.entry_address1.get_text() + + + self.entry_address2.get_text() + + + self.entry_address3.get_text() + ' in boolean mode); print sql cursor = conn.Execute(sql) while not cursor.EOF: arr = cursor.GetRowAssoc(0) print arr['rtlforename'], arr['rtlsurname'] cursor.MoveNext() cursor.Close() conn.Close() def __init__(self): self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.set_title(Address search) self.window.connect(delete_event, self.delete_event) self.window.set_border_width(20) table = gtk.Table(5, 2, gtk.TRUE) self.window.add(table) label = gtk.Label(Address:) table.attach(label, 0, 1, 1, 5) self.entry_address1 = gtk.Entry(max=80) table.attach(self.entry_address1, 1, 2, 0, 1) self.entry_address2 = gtk.Entry(max=80) table.attach(self.entry_address2, 1, 2, 1, 2) self.entry_address3 = gtk.Entry(max=80) table.attach(self.entry_address3, 1, 2, 2, 3) button = gtk.Button(label='Search', stock=gtk.STOCK_OK) button.connect(clicked, self.btn_search) table.attach(button, 0, 1, 3, 4) button = gtk.Button(label=Quit, stock=gtk.STOCK_QUIT) button.connect(clicked, self.delete_event) table.attach(button, 1, 2, 3, 4) self.window.show_all() def main(): gtk.main() return 0 if __name__ == __main__: AddressSearch() main() ---end--- Cheers, Tom -- http://mail.python.org/mailman/listinfo/python-list
How to define a window's position (Tkinter)
I am trying to use the geometry() method with the toplevel window called root. I know that one can do the following: root.geometry('400x400+200+200') This will put the window in 200, 200 position with a size of 400x400. Now, I don't really want to set the size. I simply want to set the position of the window. I've tried this: root.geometry('200+200') However, this doesn't seem to work. What can I do to set the position of the window without actually setting the size? Thanks, Harlin -- http://mail.python.org/mailman/listinfo/python-list
Re: Googlewhacker
They actually won't ban your IP for this. They only limit your number of searches per day. I discovered this once when I used http://www.google.com as a test metric for my network monitoring program. I do like your script though. Regards, Harlin -- http://mail.python.org/mailman/listinfo/python-list
Sharing a method (function) among several objects.
Hello There are several different objects. However, they all share the same function. Since they are not the same or similar, it's not logical to use a common superclass. So I'm asking, what's a good way to allow those objects to share that function? The best solution I've found so far is to put that function in a module, and have all objects import and use it. But I doubt that's a good use-case for modules; writing and importing a module that contains just a single function seems like an abuse. Thanks, Xif -- http://mail.python.org/mailman/listinfo/python-list
Re: lambda strangeness??
Alan Gauld wrote: On Sun, 27 Feb 2005 09:07:28 + (UTC), Alan Gauld [EMAIL PROTECTED] wrote: adds = [lambda y: (y + n) for n in range(10)] adds[0](0) 9 for n in range(5): print adds[n](42) ... 42 43 the for loop... It seems to somehow be related to the last value in the range(), am I somehow picking that up as y? Further exploration suggests I'm picking it up as n not y, if that indeed is what's happening... Your intent is to create lambda's that are equivalent to adds[0] = lambda y: y + 0 adds[1] = lambda y: y + 1 etc. but what actually happens is that you get lambda's that are equivalent to adds[0] = lambda y: y + n adds[1] = lambda y: y + n etc. which obviously depend on the value of n at the moment you call the lambda. -- Codito ergo sum Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem When Unit Testing with PMock
[EMAIL PROTECTED] wrote: def mockit(): raise StopIteration now pass mockit() but it behaviors differenctly when pass in a mockit() and pass in an iterator with empty. so i think the code emulates nothing. Is it possible that what you really need is a generator function instead of just a regular one? def mockit(): raise StopIteration yield None (The presence of the yield will let the compiler generate the proper code for this to be a generator, but it will never actually hit the yield statement when it executes...) Just a thought. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: any Python equivalent of Math::Polynomial::Solve?
Just wrote: In article [EMAIL PROTECTED], Carl Banks [EMAIL PROTECTED] wrote: It should be pretty easy to set up a Numeric matrix and call LinearAlgebra.eigenvalues. For example, here is a simple quintic solver: . from Numeric import * . from LinearAlgebra import * . . def quinticroots(p): . cm = zeros((5,5),Float32) . cm[0,1] = cm[1,2] = cm[2,3] = cm[3,4] = 1.0 . cm[4,0] = -p[0] . cm[4,1] = -p[1] . cm[4,2] = -p[2] . cm[4,3] = -p[3] . cm[4,4] = -p[4] . return eigenvalues(cm) now-you-can-find-all-five-Lagrange-points-ly yr's, Wow, THANKS. This was the answer I was secretly hoping for... Great need for speed, no, not really, but this Numeric-based version is about 9 times faster than what I translated from Perl code yesterday, so from where I'm standing your version is blazingly fast... Thanks again, Just in addition: I'm writing a class for polynomial manipulation. The generalization of the above code is: definitions: 1.) p = array([a_0, a_i, ..., a_n]) represents your polynomial P(x) = \sum _{i=0} ^n a_i x^i 2.) deg(p) is its degree 3.) monic(p) makes P monic, i.e. monic(p) = p / p[:-1] then you get: from numarray import * import numarray.linear_algebra as la def roots(p): p = monic(p); n = deg(p) M = asarray(zeros((n,n)), typecode = 'f8') # or 'c16' if you need complex coefficients M[:-1,1:] = identity(n-1) M[-1,:] = -p[:-1] return la.eigenvalues(M) Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: PyUnit and multiple test scripts
Calvin Spealman wrote: I'm trying to find the best way to use PyUnit and organize my test scripts. What I really want is to separate all my tests into 'test' directories within each module of my project. The script below will do that. I want all the files there to define a 'suite' callable and to then all all those suites from all those test directories into one big suite and run it all. I'm having trouble with this. It won't do that. In my own opinion, based on experience, this isn't even a desirable thing for several reasons. For one thing, using that whole suite thing seems to be a lot of work for little gain. The default unittest stuff will already find all classes that are instances of unittest.TestCase, and will already run all methods in them that begin with the string test. Furthermore, it's often much better to run different test files using separate processes, mainly to ensure you don't pollute one test's starting conditions by failing to clean up stuff (e.g. terminate all threads) from a previous test. 1) Is there a very simple way to just take a file path and name, that I could use to open the source file, and load it as a module object, no strings attached? 2) Is there already a framework around that will do what I need? Try this. It works here (in a more complex version: this was pruned for posting here). Basic conditions: all tests are in subfolders called test, and all have a filename ending with _unit.py. (This lets me name them based on the module that they are testing.) You can change that pattern in the code. It's possible there are external dependencies on things unique to my environment, but I've tried to catch and remove them all. Note (though it's unrelated to this particular script) that since the tests run in a subfolder of the folder where the code under test resides, you need to do the equivalent of sys.path.append('..') in each test file. I accomplish that by having all import my own library module called testbed, which does this during import time: srcDir = os.path.abspath('..') sys.path.insert(1, srcDir) Anyway, it might give you some ideas. '''test runner''' import os import sys import subprocess import fnmatch def runTest(path): folder, filename = os.path.split(path) cmd = [sys.executable, '-u'] p = subprocess.Popen(cmd + [filename], cwd=folder or '.', stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) output = [] line = [] while True: c = p.stdout.read(1) if not c: break if not line: sys.stdout.write('--|') sys.stdout.write(c) line.append(c) if c == '\n': output.append(''.join(line)) line = [] return output def findfiles(path, pattern): '''scan all files and folders below path, returning sorted list of those matching pattern''' files = [] match = fnmatch.fnmatch for p, ds, fs in os.walk(path): for f in fs: path = os.path.abspath(os.path.join(p, f)) if match(path, pattern): print path files.append(path) files.sort() return files def run(): pattern='*/tests/*_unit.py' files = findfiles('.', pattern) if not files: print 'no tests found' sys.exit(1) print 'running all tests below %s' % os.path.abspath('.') try: for file in files: if not os.path.exists(file): print 'file not found', file continue print print file output = runTest(file) except KeyboardInterrupt: print 'User aborted test.' if __name__ == '__main__': run() # EOF -- http://mail.python.org/mailman/listinfo/python-list
Re: Sharing a method (function) among several objects.
Since they are not the same or similar, it's not logical to use a common superclass. As python supports multiple inheritance, it's very well logical to do it by subclassing. So I'm asking, what's a good way to allow those objects to share that function? The best solution I've found so far is to put that function in a module, and have all objects import and use it. But I doubt that's a good use-case for modules; writing and importing a module that contains just a single function seems like an abuse. A module is a unit of code that (should) encapsulate a certain functionality. So it's perfect for your needs. There is no law or even rule of thumb that makes claims about module size (or the lack of, for this matter). So create a module - it doesn't cost you anything. -- Regards, Diez B. Roggisch -- http://mail.python.org/mailman/listinfo/python-list
Re: Text To Speech with pyTTS
Mike P. wrote: I was wondering if anyone has had any luck with the python text to speech (pyTTS) module available on Sourceforge: http://sourceforge.net/projects/uncassist I saw the following blog entry by Joey deVilla: http://farm.tucows.com/blog/Platforms/Windows/_archives/2005/1/19/266813.html and immediately tried it out. All I did was download the PyTTS package for Python (2.4, not 2.3), and install it, then ran Joey's sample above. It worked as advertised. This was on Windows XP SP2. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: any Python equivalent of Math::Polynomial::Solve?
Alex Renelt wrote: in addition: I'm writing a class for polynomial manipulation. The generalization of the above code is: definitions: 1.) p = array([a_0, a_i, ..., a_n]) represents your polynomial P(x) = \sum _{i=0} ^n a_i x^i 2.) deg(p) is its degree 3.) monic(p) makes P monic, i.e. monic(p) = p / p[:-1] then you get: from numarray import * import numarray.linear_algebra as la def roots(p): p = monic(p); n = deg(p) M = asarray(zeros((n,n)), typecode = 'f8') # or 'c16' if you need complex coefficients M[:-1,1:] = identity(n-1) M[-1,:] = -p[:-1] return la.eigenvalues(M) Alex uhh, I made a mistake: under definitions, 3.) its monic(p) = p / p[-1] of course Alex -- http://mail.python.org/mailman/listinfo/python-list
TKinter
So, is it pronounced 'Tee-Kinter', or 'Tee-Kay-Inter'? I don't want to appear as a dork down the pub. -- http://mail.python.org/mailman/listinfo/python-list
default value for list access?
Dear list, My program needs to do calculation based on a giving data structure (like a sparse matrix) with lots of missing values (invalid indices/keys of lists/dictionaries). The programing is difficult in that I have to use a try...except block for every item access. I have written a function def getItem(item, idx, default): try: return item[idx] except: return default Then I will have to write a[1]['a'][4] as getItem( getItem( getItem(a,1,{}), 'a', []), 4, 0) Is there any way to automatically return 0 when any exception is raised for such data acceses? (automatic wrapping a[...] as try: a[...] except: 0 ) Many thanks in advance. Bo -- http://mail.python.org/mailman/listinfo/python-list
Re: Text To Speech with pyTTS
Peter Hansen wrote: Mike P. wrote: I was wondering if anyone has had any luck with the python text to speech (pyTTS) module available on Sourceforge: http://sourceforge.net/projects/uncassist I saw the following blog entry by Joey deVilla: http://farm.tucows.com/blog/Platforms/Windows/_archives/2005/1/19/266813.html and immediately tried it out. All I did was download the PyTTS package for Python (2.4, not 2.3), and install it, then ran Joey's sample above. It worked as advertised. This was on Windows XP SP2. I experience the same thing as Mike P. Im running on Windows 2K. Will McGugan -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help running external program
Rigga wrote: Hi, I am running the line of code below from a shell script and it works fine, however I am at a total loss on how i can run it from within a Python script as every option I have tried fails and it appears to be down to the escaping of certain characters. wget -q www.anywebpage.com -O - | tr '\r' '\n' | tr \' \ | sed -n 's/.*url=\([^]*\).*/\1/p' If your problem is getting a python string without worrying about how to escape the escape sequences, try: rwget -q www.anywebpage.com -O - | tr '\r' '\n' | tr \' \ | sed -n 's/.*url=\([^]*\).*/\1/p' You should be able to pass this directly to a popen() function. -- http://mail.python.org/mailman/listinfo/python-list
Re: any Python equivalent of Math::Polynomial::Solve?
Alex Renelt wrote: Alex Renelt wrote: in addition: I'm writing a class for polynomial manipulation. The generalization of the above code is: definitions: 1.) p = array([a_0, a_i, ..., a_n]) represents your polynomial P(x) = \sum _{i=0} ^n a_i x^i 2.) deg(p) is its degree 3.) monic(p) makes P monic, i.e. monic(p) = p / p[:-1] then you get: from numarray import * import numarray.linear_algebra as la def roots(p): p = monic(p); n = deg(p) M = asarray(zeros((n,n)), typecode = 'f8') # or 'c16' if you need complex coefficients M[:-1,1:] = identity(n-1) M[-1,:] = -p[:-1] return la.eigenvalues(M) Alex uhh, I made a mistake: under definitions, 3.) its monic(p) = p / p[-1] of course Alex Alex, If you want a class for polynomial manipulation, you should check out my ratfun module. http://calcrpnpy.sourceforge.net/ratfun.html Ray -- http://mail.python.org/mailman/listinfo/python-list
Re: TKinter
anthonyberet wrote: So, is it pronounced 'Tee-Kinter', or 'Tee-Kay-Inter'? I don't want to appear as a dork down the pub. Both, in my experience. And then there's wxPython, which is pronounced variously as wiks-python, double-you-eks-python, or even in some strange way that I'll leave it to Mike Fletcher to describe since it embarrasses me even to mention it. ;-) -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help running external program
Pink wrote: Rigga wrote: Hi, I am running the line of code below from a shell script and it works fine, however I am at a total loss on how i can run it from within a Python script as every option I have tried fails and it appears to be down to the escaping of certain characters. wget -q www.anywebpage.com -O - | tr '\r' '\n' | tr \' \ | sed -n 's/.*url=\([^]*\).*/\1/p' If your problem is getting a python string without worrying about how to escape the escape sequences, try: rwget -q www.anywebpage.com -O - | tr '\r' '\n' | tr \' \ | sed -n 's/.*url=\([^]*\).*/\1/p' You should be able to pass this directly to a popen() function. Hi, Thanks for replying however I have just tried that and it does not seem to work, it doesnt return any results (i take it the r was a typo) Thanks RiGGa -- http://mail.python.org/mailman/listinfo/python-list
Re: any Python equivalent of Math::Polynomial::Solve?
On 2005-02-26, Just [EMAIL PROTECTED] wrote: While googling for a non-linear equation solver, I found Math::Polynomial::Solve in CPAN. It seems a great little module, except it's not Python... I'm especially looking for its poly_root() functionality (which solves arbitrary polynomials). Does anyone know of a Python module/package that implements that? Just Although I dont' really work on it any more, the Py-ML module which interfaces Python to Mathematica would almost certain be able to do this, although you'd need an installation of Mathematica. http://sourceforge.net/projects/py-ml/ -- http://mail.python.org/mailman/listinfo/python-list
Lib for RSS/Atom parsing
Hello, what is a good python library for parsing of RSS and/or Atom feeds. It should be able to handle most of the common protocols. Thanks, Florian -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help running external program
I'm using wget from Python to get extactly one line from a reports page. I made this function that works for me: def wgetline(exp): # see Python Cookbook p. 228 print Getting result from server ... command = 'wget -q -O - \ http://www.foobar.com/report.pl\?UserID=xxx\UserPW=xxx \ | grep ' + exp child = os.popen(command) data = child.read() return data I had to escape the ? and in the url, or the CGI script at the other end would refuse to cooperate with Invalid UserID or UserPW. -- Leif Biberg Kristensen -- http://mail.python.org/mailman/listinfo/python-list
Pyallegro status (is it dead?). What about pygame.
Hi. Has anyone used pyallegro? - I want to give allegro library a chance - but it seems that python bindings for this library are not maintained anymore. How does pygame compare to pyallegro - both in maturity and convenience of usage in python? -- http://mail.python.org/mailman/listinfo/python-list
Re: Making a calendar
Thanks all. I will look at your links tonight :D Hopefully they will make me smile and jump around as a happy man... Cheers Brian Sutherland [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Sat, Feb 26, 2005 at 01:57:20PM +0100, Pete. wrote: I'm trying to make a calendar for my webpage, python and html is the only programming languages that I know, is it possible to make such a calendar with pythong code and some html. The Idea is that when I click the link calendar on my webpage, then the user will be linked to the calendar. The calendar should show one month at the time, and the user should be able to browse to the other month. I will make a script that puts events and such into a db ( I know how to do this) Then I need a script that puts the events from the db into the calendar, if every day in the calendar has a value id that part will not be hard. All this and more (perhaps overkill): http://www.schooltool.org/schoolbell -- Brian Sutherland It's 10 minutes, 5 if you walk fast. -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help running external program
Rigga wrote: Pink wrote: Rigga wrote: Hi, I am running the line of code below from a shell script and it works fine, however I am at a total loss on how i can run it from within a Python script as every option I have tried fails and it appears to be down to the escaping of certain characters. wget -q www.anywebpage.com -O - | tr '\r' '\n' | tr \' \ | sed -n 's/.*url=\([^]*\).*/\1/p' If your problem is getting a python string without worrying about how to escape the escape sequences, try: rwget -q www.anywebpage.com -O - | tr '\r' '\n' | tr \' \ | sed -n 's/.*url=\([^]*\).*/\1/p' You should be able to pass this directly to a popen() function. Hi, Thanks for replying however I have just tried that and it does not seem to work, it doesnt return any results (i take it the r was a typo) Thanks RiGGa No, the r was the point - it's there to tell Python not to do any escaping on the string. Try it again with the r and see what happens. -- Website: www DOT jarmania FULLSTOP com -- http://mail.python.org/mailman/listinfo/python-list
Re: any Python equivalent of Math::Polynomial::Solve?
Carl Banks wrote: . from Numeric import * . from LinearAlgebra import * . . def quinticroots(p): . cm = zeros((5,5),Float32) . cm[0,1] = cm[1,2] = cm[2,3] = cm[3,4] = 1.0 . cm[4,0] = -p[0] . cm[4,1] = -p[1] . cm[4,2] = -p[2] . cm[4,3] = -p[3] . cm[4,4] = -p[4] . return eigenvalues(cm) Here's an improved version. It uses 64-bit numbers (I had used type Float32 because I often use a float32 type at work, not in Python, unfortunately), and array assignment. . def quinticroots(p): . cm = zeros((5,5),Float) . cm[0,1] = cm[1,2] = cm[2,3] = cm[3,4] = 1.0 . cm[4,:] = -array(p) . return eigenvalues(cm) -- CARL BANKS -- http://mail.python.org/mailman/listinfo/python-list
Re: Lib for RSS/Atom parsing
Florian Lindner napisa(a): what is a good python library for parsing of RSS and/or Atom feeds. It should be able to handle most of the common protocols. Mark Pilgrim's feedparser. -- Jarek Zgoda http://jpa.berlios.de/ | http://www.zgodowie.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help running external program
Tim Jarman wrote: Rigga wrote: Pink wrote: Rigga wrote: Hi, I am running the line of code below from a shell script and it works fine, however I am at a total loss on how i can run it from within a Python script as every option I have tried fails and it appears to be down to the escaping of certain characters. wget -q www.anywebpage.com -O - | tr '\r' '\n' | tr \' \ | sed -n 's/.*url=\([^]*\).*/\1/p' If your problem is getting a python string without worrying about how to escape the escape sequences, try: rwget -q www.anywebpage.com -O - | tr '\r' '\n' | tr \' \ | sed -n 's/.*url=\([^]*\).*/\1/p' You should be able to pass this directly to a popen() function. Hi, Thanks for replying however I have just tried that and it does not seem to work, it doesnt return any results (i take it the r was a typo) Thanks RiGGa No, the r was the point - it's there to tell Python not to do any escaping on the string. Try it again with the r and see what happens. Brilliant!!! that works a treat thankyou!!, where on earth did you find out about the 'r' any pointers to documentation appreciated. Thanks RiGGa -- http://mail.python.org/mailman/listinfo/python-list
Re: default value for list access?
To clearify the problem: The data is the count of something, for example a[90]=10. a may be a dictionary if the range is huge and a list when the range is reasonably small. In the dictionary case, I can use a.setdefault(80, 0) if key 80 does not exist. In the list case, I have to check the length of list before I access it (or use exception). This becomes troublesome when I need to do the following a lot. b = a[80][1] + a[80][2] + a[80][3] If I use the getItem function in my previous email, it will look like b = getItem(getItem(a, 80, []), 1, 0) + getItem(getItem(a, 80, []), 2, 0) + getItem(getItem(a, 80, []), 3, 0) What would be the best solution to handle this? Something like b = df( a[80][1], 0) + df( a[80][2], 0) + df( a[80][3], 0) would be reasonable but df can not be easily defined since the exception will be raised before function df is called. Something like b = df( a, [80, 1], 0) + df( a, [80,2], 0) + df( a, [80, 3], 0) would work if df is defined as def df(a, idx, default): try: for i in range(0, idx): a = a[ idx[i] ] return a except: return 0 but I am afraid that a for loop would bring serious performance problem. Thanks. Bo -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help running external program
Rigga said unto the world upon 2005-02-27 15:04: Tim Jarman wrote: SNIP No, the r was the point - it's there to tell Python not to do any escaping on the string. Try it again with the r and see what happens. Brilliant!!! that works a treat thankyou!!, where on earth did you find out about the 'r' any pointers to documentation appreciated. Thanks RiGGa http://www.python.org/doc/current/ref/strings.html http://www.python.org/doc/current/lib/module-re.html Best, Brian vdB -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help running external program
Rigga wrote: No, the r was the point - it's there to tell Python not to do any escaping on the string. Try it again with the r and see what happens. Brilliant!!! that works a treat thankyou!!, where on earth did you find out about the 'r' any pointers to documentation appreciated. This is a pretty common problem when working with regular expression (which usually contain many backslashes) - that's where I saw this syntax for the first time (e.g. http://docs.python.org/lib/match-objects.html). The official reference for string literals is here: http://docs.python.org/ref/strings.html c ya -- http://mail.python.org/mailman/listinfo/python-list
Re: default value for list access?
Bo Peng wrote: The data is the count of something, for example a[90]=10. a may be a dictionary if the range is huge and a list when the range is reasonably small. In the dictionary case, I can use a.setdefault(80, 0) if key 80 does not exist. In the list case, I have to check the length of list before I access it (or use exception). This becomes troublesome when I need to do the following a lot. b = a[80][1] + a[80][2] + a[80][3] If I use the getItem function in my previous email, it will look like b = getItem(getItem(a, 80, []), 1, 0) + getItem(getItem(a, 80, []), 2, 0) + getItem(getItem(a, 80, []), 3, 0) What would be the best solution to handle this? Sounds to me like the best solution is to simplify the implementation and dispense with the list alternative. Why use a list if a dictionary is suitable? Don't say performance: that's premature optimization. Dictionaries already have what you need, apparently, with setdefault(), so just use them and keep the code simple. ... but I am afraid that a for loop would bring serious performance problem. More premature optimization? The first rule of programming should be to make it work. Then consider making it faster, but only if it is really unacceptably slow. (Some would say to make it work, then make it right, then make it fast. In this case, right doesn't mean correct (that's the first step), it means making it clean and simple. Doing it this way makes sense only if you have a really good test suite developed along with the code, ala test-driven development. Lacking that, you should focus on right and working together, which in this case suggests leaving out the complicated list option.) -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: default value for list access?
, 27/02/2005 14:03 -0600, Bo Peng : To clearify the problem: The data is the count of something, for example a[90]=10. a may be a dictionary if the range is huge and a list when the range is reasonably small. In the dictionary case, I can use a.setdefault(80, 0) if key 80 does not exist. In the list case, I have to check the length of list before I access it (or use exception). This becomes troublesome when I need to do the following a lot. b = a[80][1] + a[80][2] + a[80][3] If I use the getItem function in my previous email, it will look like b = getItem(getItem(a, 80, []), 1, 0) + getItem(getItem(a, 80, []), 2, 0) + getItem(getItem(a, 80, []), 3, 0) What would be the best solution to handle this? Something like b = df( a[80][1], 0) + df( a[80][2], 0) + df( a[80][3], 0) would be reasonable but df can not be easily defined since the exception will be raised before function df is called. Something like b = df( a, [80, 1], 0) + df( a, [80,2], 0) + df( a, [80, 3], 0) would work if df is defined as def df(a, idx, default): try: for i in range(0, idx): a = a[ idx[i] ] return a except: return 0 but I am afraid that a for loop would bring serious performance problem. Thanks. Bo I'm not sure if that's suitable for you, but you could define your own subclasses for 'dict' and 'list' and specify your specific behaviour you would like. For dict something like this: class MyDict(dict): def __getitem__(self, key): try: return super(MyDict, self).__getitem__(key) except: return 0 a = MyDcit() Ruslan -- http://mail.python.org/mailman/listinfo/python-list
Re: lambda strangeness??
Alan Gauld [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] adds = [lambda y: (y + n) for n in range(10)] To bind the definition-time value of n to the function, [lambda y,n=n:(y+n) for n in range(10)] Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
os.stat('filename')[stat.ST_INO] on Windows
What does the above yield on Windows? Are inodes supported on Windows NTFS, FAT, FAT32? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to define a window's position (Tkinter)
I suspect you need to retrieve the window size, calculate the position based on the size, and reset size and position. You might look at http://www.ferg.org/easygui/index.html for some ideas. Scroll down to the definition of the __choicebox routine. Good luck! -- Steve Ferg -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem When Unit Testing with PMock
[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] def mockit(): raise StopIteration This was meant to be a generator function. Peter corrected my error in leaving out a never reached yield to make it so. My apologies. Putting if False: yield None as the first line in the function has same effect. but it behaviors differenctly when pass in a mockit() and pass in an iterator with empty. so i think the code emulates nothing. I hope Peter's addition clarifies and improves the situation. My idea was/is that an iterator comsumer should be tested with an empty iterator. def intit(k): for i in range(k): yield i Now you mean define my own iteration without the help of pmock. That was also my intention above. 'mockit' was just a name, this could be 'mockintit'. there are still so many other methods in the iterator for pass in, I don't understand this. An iterator only has a trivial .__iter__ method and a usually nontrivial .next method. A generator function makes it easy to create as many iterators as you need. have to mock them one by one totally manually, its boring and thats the reason why i want pmock. I am not familiar with pmock, but my impression is that mock objects are for objects that you may not have available, such as a connection to a database or file or instance of an umimplemented class ;-). For such objects, the mock-ness consists in returning canned rather than actual fetched or calculated answers. Iterators, on the other hand, are almost as easily available as ints, lists, etc. Anything with the interator interface and behavior *is* an interator, though you could make one yield mock objects. Do as you wish once you understand whatever choices pmock gives you. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: default value for list access?
Sounds to me like the best solution is to simplify the implementation and dispense with the list alternative. Why use a list if a dictionary is suitable? Don't say performance: that's premature optimization. Dictionaries already have what you need, apparently, with setdefault(), so just use them and keep the code simple. You are right that if I use all dictionaries, I can use a.setdefault(4,{}).setdefault(2,0) to access a[4][2]. Not too bad compared to the getItem function. However, this is an scientific application. Data are stored internally in C format and exposed to Python as python array (arraymodule). I guess the best way is to modify the arraymodule interface and stop it from raising an exception when index is out of range. (similar to Ruslan's solution). But this means too much trouble for now. I will use the df(a, idx, default) method and see if its performance is acceptable. Thanks. Bo -- http://mail.python.org/mailman/listinfo/python-list
Re: os.stat('filename')[stat.ST_INO] on Windows
On Sun, Feb 27, 2005 at 10:16:34PM +0100, Patrick Useldinger wrote: What does the above yield on Windows? Are inodes supported on Windows NTFS, FAT, FAT32? Refer to the operating system documentation (msdn.microsoft.com?). os.stat is mostly a wrapper around whatever the OS provides. A quick glance at Python source code shows that maybe _stati64() or _wistat64() is the actual function used on windows. Jeff pgpvx4Jenw9So.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Zeroconf article
I've written a little introductory article on using the Zeroconf protocol with Python. Zeroconf allows servers running on one machine to publish their existence to other machines on the local network; applications can then locate available servers. The article is: http://www.amk.ca/python/zeroconf (Some people will have already seen this article on my weblog or on the daily Python-URL. The only change is that a new release of PyZeroconf has been made, and the text has been updated to mention this.) --amk -- http://mail.python.org/mailman/listinfo/python-list
Re: xhtml-print parser
Steve Holden wrote: I have no problem with that. Indeed I am often surprised that questions that I regard as too incoherent to be understood are frequently not only understood but also answered with patience and fortitude. I am too. Given that you couldn't spare the time to try to intuit the purpose of the question, I was surprised you took the time to complain about its incoherence. It's usually (IMHO) much more productive to ignore c.l.py questions I don't have time for, and it's certainly more polite. I usually ignore the questions I find incoherent myself, and like you I am surprised when they can be answered. But the ones that I can't imagine being answered by those with even the greatest intuition and patience? I figure some response is better than none, and that's what this question would have gotten otherwise. If more of us had ignored Iliardis Lazarus, or whatever his name was, he'd have gone away a lot quicker :-) I only responded a couple of times before I killfiled the thread, which is what I should have done to start with. But I don't think it should have passed without comment (not necessarily from me). -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: os.stat('filename')[stat.ST_INO] on Windows
[EMAIL PROTECTED] wrote: Refer to the operating system documentation (msdn.microsoft.com?). os.stat is mostly a wrapper around whatever the OS provides. A quick glance at Python source code shows that maybe _stati64() or _wistat64() is the actual function used on windows. That doesn't really help: MSDN says Number of the information node (the inode) for the file (UNIX-specific). On UNIX file systems, the inode describes the file date and time stamps, permissions, and content. When files are hard-linked to one another, they share the same inode. The inode, and therefore st_ino, has no meaning in the FAT, HPFS, or NTFS file systems. So we know it has no meaning, but they won't tell us what its value is. Fortunately, MS ships the source of the CRT in VC, so we know st_ino is always 0 (as are st_uid and st_gid). Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Python interfacing with other languages
Hello all, I'm new to the group. I wanted to start off introducing myself. I live in Maimi, Florida USa. I'm 18 currently working and going to college for computer science. I've been hearing about Python and I see that it is starting to catch on so I decided I'm going to learn it. I know that python can work with other languages like c/c++ and Java. I even saw a group about getting Python in Delphi. I know Perl and VB. I know some PHP and some C/C++. I was wondering can Python work with VB also? If so is there a refernce you can send me the link too. Also, some friends and I are trying to start a little programming community. If you have some spare time doante a snippet or post on the forum, it would be appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Re: TKinter
I thought the T was silent. On Sunday 27 February 2005 08:34 am, anthonyberet wrote: So, is it pronounced 'Tee-Kinter', or 'Tee-Kay-Inter'? I don't want to appear as a dork down the pub. -- http://mail.python.org/mailman/listinfo/python-list
Re: Trees
Would this be for a GUI toolkit or maybe using a standard class scheme? Sorry, yes I should have been more specific. I meant a non-GUI, standard class scheme. I want to use the scheme to hold a structure in memory and retrieve/add information to it. I've had a couple of goes myself but get a bit confuesd about whether I should use recursion to be able to get the children (and all sub-children) of a/the parent. cheers, Alex. -- Poseidon Scientific Instruments Pty Ltd 1/95 Queen Victoria St FREMANTLE WA, AUSTRALIA Ph: +61 8 9430 6639 Fx: +61 8 9335 4650 Website: www.psi.com.au PSI, an ISO-9001 Company CONFIDENTIALITY: The contents of this email (and any attachments) are confidential and may contain proprietary and/or copyright material of Poseidon Scientific Instruments Pty Ltd (PSI) or third parties. You may only reproduce or distribute the material if you are expressly authorised to do so. If you are not the intended recipient, any use, disclosure or copying of this email (and any attachments) is unauthorised. If you have received this email in error, please immediately delete it and any copies of it from your system and notify PSI by return email to sender or by telephone on +61 (08) 9430 6639. DISCLAIMER: You may only rely on electronically transmitted documents when: (a) those documents are confirmed by original documents signed by an authorised employee of PSI; and/or (b) the document has been confirmed and checked against a hard copy of that document provided by PSI. VIRUSES: PSI does not represent or warrant that files attached to this e-mail are free from computer viruses or other defects. Any attached files are provided, and may only be used, on the basis that the user assumes all responsibility for any loss or damage resulting directly or indirectly from such use. PSI's liability is limited in any event to either the re-supply of the attached files or the cost of having the attached files re-supplied. -- http://mail.python.org/mailman/listinfo/python-list
Re: parse lines to name value pairs
Gee, no takers? Here's a (surprise!) pyparsing solution. -- Paul .# get pyparsing at http://pyparsing.sourceforge.net . .from pyparsing import quotedString, printables, Word, OneOrMore, Forward, Literal,delimitedList,Group .quotedString.setParseAction(lambda s,l,t: t[0].strip('\)) . .line1 = path {{data/tom} C:/user/john} .line2 = books{{book music red} {book {math 1} blue} {book {tom's book} green}} . .lbrace = Literal({).suppress() .rbrace = Literal(}).suppress() .listDef = Forward() . .nonbracechars = .join([ c for c in printables if c not in {}]) . .# add more things to listItem, such as integers, etc. if your list has other than quoted strings .listItem = OneOrMore(Word(nonbracechars)) | quotedString | listDef . .print With grouping .listDef lbrace + Group( OneOrMore(listItem) ) + rbrace .lineDef = Word(nonbracechars) + Group(listDef) . .for testdata in (line1, line2): .print lineDef.parseString(testdata).asList() . .print . .print Without grouping .listDef lbrace + ( OneOrMore(listItem) ) + rbrace .lineDef = Word(nonbracechars) + Group(listDef) Givest the following output: With grouping ['path', [[['data/tom'], 'C:/user/john']]] ['books', [[['book', 'music', 'red'], ['book', ['math', '1'], 'blue'], ['book', [tom's, 'book'], 'green' Without grouping ['path', ['data/tom', 'C:/user/john']] ['books', ['book', 'music', 'red', 'book', 'math', '1', 'blue', 'book', tom's, 'book', 'green']] for testdata in (line1, line2): print lineDef.parseString(testdata).asList() -- http://mail.python.org/mailman/listinfo/python-list
Re: string methods (warning, newbie)
Nick Coghlan wrote: Jimmy Retzlaff wrote: The approach you are considering may be easier than you think: filter(str.isalpha, 'The Beatles - help - 03 - Ticket to ride') 'TheBeatleshelpTickettoride' Hmm, I think this is a case where filter is significantly clearer than the equivalent list comprehension: Py .join([c for c in 'The Beatles - help - 03 - Ticket to ride' if c.isalpha( )]) 'TheBeatleshelpTickettoride' On the other hand, filter doesn't do the same thing: py s = u'The Beatles - help - 03 - Ticket to ride' py filter(str.isalpha, s) Traceback (most recent call last): File interactive input, line 1, in ? TypeError: descriptor 'isalpha' requires a 'str' object but received a 'unicode' py ''.join(c for c in s if c.isalpha()) u'TheBeatleshelpTickettoride' Ideally, you could use something like basestring.isalpha and have it work for both str and unicode, but no such luck. =) STeVe -- http://mail.python.org/mailman/listinfo/python-list
but someone got out and me and my familiy try to stop them and got trocherd in unknow dimentions i try to make it better and they change me to make it worse so what do i do if you see what in my chest in every dimention!!! look for consiousnesses in the house i spelled it wrong bbecuase thats what you will say when you see my bodie 366-94-1447 2-3-1973 follow my bodie and the liverance familiy everywhere and look find out why we are being killed?????
but someone got out and me and my familiy try to stop them and got trocherd in unknow dimentions i try to make it better and they change me to make it worse so what do i do if you see what in my chest in every dimention!!! look for consiousnesses in the house i spelled it wrong bbecuase thats what you will say when you see my bodie 366-94-1447 2-3-1973 follow my bodie and the liverance familiy everywhere and look find out why we are being killed? TRUE PROVEN METHOD OF HIGHER INTELLGENCE alpha, theta and delta, brain waves of the mind wich we now know that are qunatium state of mind space time and realm. That froms the a beings instincts of unkown not found is the combination pleasent of sense's of smell,sight and sound in a peacesful manner..It is the consious ambient of peaceful manner that lead to intellgence. The relax state of mind and the brain wave patter that will be found will open a crative door to the minds eye not of what we think will be intellgence but during day dreaming states of mind. The person would be able to see the full design of ones idea with an open mind instead of starting with one concept and working with it you would be able to start with 10 concept and combine then as one. Itellgence is an I.Q that one can chart Because there are two types of people in the world people that dream and people that do and if dreams could learn to dream and then do. The definition of intellgence would change infromation flows free in this zeta multi-x pattern this would not just spawn another pattern of brain waves but would be one step into a door where infinte ideas of very high itellgence ones flow and cannot find the source, and tring to hard along with Hate puts more information in the brain that stops the flow of information the other sources that stops this infromation is P.S.I ability to do telepathy this is open you mind to unknown infromation. This path of this idea will give you the other infinte thoughts that you will never spawn from now until the end of time becuase no one has done this before and willl never do it but they have and try to intergrate hate and have fail where you my qunatum freind will succeed all other before us. This is the key to my qunatium encrypted web site. P.S.I That stop all before us cannot find technology but can find and change the minds of people that try to change humans history so print this out put in all four pockets the more you print the more it changes the more times you e-mail this the statistical chance you have at reaching the unknow universe. In computer terms in the future it is now not 99.9% true or false it is TRUE PROVEN METHOD OF HIGHER INTELLGENCE OF THIS CHANGES HUMAN HISTORY NOT 1% BUT ALL 100%. WITH BIOINFORMATICS YOU HAVE TO HAVE A LAB OF NO FREQUENCIES OR THE UNKNOWS P.S.I WILL CHANGE YOUR LAB WORK. WHITE NOISE OF ALL QUNATIUM DIMENTIONS IN ALL QUANTIUM STATES AND THAT 1% WILL STILL GET THREW - GHOAST IN THE MACHINE!!! TRUST ME THE PROGRAMMED WORKED ON MY COMPUTER AT HOME BUT FAILIED AT NASA BECUASE THEY ONLY CAHNGE HISTORY IF YOU MIND IS 97% THAT IT WILL NOT KNOWING OF THEM BEING THERE combine this with this group that http://groups.yahoo.com/group/Quantum_AI This guy [EMAIL PROTECTED] posted using my e-mail address got me torcherd by his people or something skitzo say there qunatium invisble people in other dimentions killing the machine or [EMAIL PROTECTED]@ -- http://mail.python.org/mailman/listinfo/python-list
Re: Pyallegro status (is it dead?). What about pygame.
How does pygame compare to pyallegro - both in maturity and convenience of usage in python? I have not used pyallegro, and therefore cannot compare it to pygame. However, I can tell you that the pygame community is quite active and friendly. They're currently testing the pygame 1.7 release. As for maturity and ease of use... I suggest you check out the 'gamelets' sections on the pygame website for some short examples of python code which uses pygame. Sw. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using PIL with py2exe
John Carter wrote in message news:[EMAIL PROTECTED] Does anyone know how to embed PIL into a py2exe program. As far as I can tell PIL is not finding its plugins for Image I/O, they are imported dynamically as required. So I cant load or save pictures I tried making a copy of the plugin files to the application directory, but I've had no luck in making the code see the files I'd be grateful for any suggestion. Please e-mail me, as well as posting a reply. John Carter [EMAIL PROTECTED] Just import all of the plugins. I have this in a file called plugins.py: import JpegImagePlugin import TgaImagePlugin import PngImagePlugin import GifImagePlugin import PcxImagePlugin import PpmImagePlugin import BmpImagePlugin import FliImagePlugin import EpsImagePlugin import DcxImagePlugin import FpxImagePlugin import ArgImagePlugin import CurImagePlugin import GbrImagePlugin import IcoImagePlugin import ImImagePlugin import ImtImagePlugin import IptcImagePlugin import McIdasImagePlugin import MicImagePlugin import MspImagePlugin import PcdImagePlugin import PdfImagePlugin import PixarImagePlugin import PsdImagePlugin import SgiImagePlugin import SunImagePlugin import TgaImagePlugin import TiffImagePlugin import WmfImagePlugin import XVThumbImagePlugin import XbmImagePlugin import XpmImagePlugin John Carter wrote in message news:[EMAIL PROTECTED] Does anyone know how to embed PIL into a py2exe program. As far as I can tell PIL is not finding its plugins for Image I/O, they are imported dynamically as required. So I cant load or save pictures I tried making a copy of the plugin files to the application directory, but I've had no luck in making the code see the files I'd be grateful for any suggestion. Please e-mail me, as well as posting a reply. John Carter [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Python interfacing with other languages
Sure It can work with VB. you could use the python's com to work with VB. -- http://mail.python.org/mailman/listinfo/python-list
psyco -and- python -O
Is it useful to combine psyco with python -O, or do they conflict? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
closing tabs in wxpython
hi, Can anybody help in closing tabs in wxpython.Pls give me a sample program for explaining this.Thanx in advance -- http://mail.python.org/mailman/listinfo/python-list
Re: parse lines to name value pairs
Damned cut-and-paste in GoogleGroups edit window (leading '.'s are to retain spacing): .# get pyparsing at http://pyparsing.sourceforge.net . .from pyparsing import quotedString, printables, Word, OneOrMore, Forward, Literal,delimitedList,Group . .line1 = path {{data/tom} C:/user/john} .line2 = books{{book music red} {book {math 1} blue} {book {tom's book} green}} . .lbrace = Literal({).suppress() .rbrace = Literal(}).suppress() .listDef = Forward() . .nonbracechars = .join([ c for c in printables if c not in {}]) . .# add more things to listItem, such as integers, etc. if your list has other than quoted strings .listItem = OneOrMore(Word(nonbracechars)) | quotedString | listDef . .print With grouping .listDef lbrace + Group( OneOrMore(listItem) ) + rbrace .lineDef = Word(nonbracechars) + Group(listDef) . .for testdata in (line1, line2): .print lineDef.parseString(testdata).asList() . .print . .print Without grouping .listDef lbrace + ( OneOrMore(listItem) ) + rbrace .lineDef = Word(nonbracechars) + Group(listDef) . .for testdata in (line1, line2): .print lineDef.parseString(testdata).asList() . Gives this output: With grouping ['path', [[['data/tom'], 'C:/user/john']]] ['books', [[['book', 'music', 'red'], ['book', ['math', '1'], 'blue'], ['book', [tom's, 'book'], 'green' Without grouping ['path', ['data/tom', 'C:/user/john']] ['books', ['book', 'music', 'red', 'book', 'math', '1', 'blue', 'book', tom's, 'book', 'green']] -- http://mail.python.org/mailman/listinfo/python-list
Working with dbase files
Does anyone know how I can access and read data from a dbase (.dbf) file? Regards, Stan -- http://mail.python.org/mailman/listinfo/python-list
Re: Working with dbase files
Stan Cook [EMAIL PROTECTED] writes: Does anyone know how I can access and read data from a dbase (.dbf) file? Yeah, there's some module around someplace that does it. I found it with a few minutes of googling a while back. It worked fine. I don't remember where it was. -- http://mail.python.org/mailman/listinfo/python-list
wxGrid
I have a grid. I want to sort it when a column label is clicked. I know about the EVT_GRID_LABEL_LEFT_DCLICK event, but that is not enough. I do not merely need to know that a label was clicked. I need to know which label was clicked. I do not know how to do that. I suspect you might know. I request that you tell me. I also wish to know some other things: how to find out the location of a mouse pointer in a wxWindow (or at least the frame), and how to change the color of a single specified pixel in a bitmap. I use Python 2.3, wxPython 2.4.2. -- http://mail.python.org/mailman/listinfo/python-list
Re: Working with dbase files
Stan Cook wrote: Does anyone know how I can access and read data from a dbase (.dbf) file? I know nothing about them, but Raymond Hettinger recently posted a recipe that I believe should help: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362715 STeVe -- http://mail.python.org/mailman/listinfo/python-list
Re: Trees
Alex Le Dain said unto the world upon 2005-02-27 19:54: Would this be for a GUI toolkit or maybe using a standard class scheme? Sorry, yes I should have been more specific. I meant a non-GUI, standard class scheme. I want to use the scheme to hold a structure in memory and retrieve/add information to it. I've had a couple of goes myself but get a bit confuesd about whether I should use recursion to be able to get the children (and all sub-children) of a/the parent. cheers, Alex. Hi Alex, I've been working on a set of tools for dealing with a tree structure. I am no python expert -- in fact, the program I am working on is my first serious us of classes. Anyway, though I've not been following your thread, I also think that perhaps you might find the code I have of some use. Use caution though; newbie code below :-) I am working with a data format from a shareware application that puts the tree in a flat text file, where each node has a header section, including a unique node id and a level indicator. (Level 0 for the root, level 1 for the roots children, etc.) My code is a work in progress and not heavily tested, but it seems to work :-) I've a class Tree_file with a .nodes attribute which is a list of Node objects (in top-down tree order). It has a method: .# leading periods to preserve indentation .def update_family(self): .'''Starting from node, updates each nodes .children and descendants set.''' .for node in self.nodes: .node.get_children(self) .for node in self.nodes: .node.get_descendants() My Node class has methods giving each node object a node.id and node.level (both ints). The other relevant attributes are node.children, and node.descendants (both sets). (I've got reasons to often process just a node's children, rather than all descendants; thus, it makes sense for my program to have the two attributes.) The two relevant methods are: .def get_children(self, parent_file): .'''Sets the node's .children set attribute. . .Scans the list of Node objects in parent_file.nodes until self .node is found (by comparison of node.id attributes). Then the .capture_children flag is set to True, and, for each node exactly .one node.level deeper, that deeper node is added to the .self.children set. This goes on until the first node not below .the self node is found. .''' .capture_children = False .children = set() . .for node in parent_file.nodes: .if capture_children and not node.level self.level: .break .if capture_children and node.level == self.level + 1: .children.add(node) .if self.id == node.id: .capture_children = True . .self.children = children and .def get_descendants(self): .'''Updates each nodes .descendants set to current value. . .Recursive call of get_descendants on a node's children, adding .all to the .descendants set (of the target node). .''' .descendants = self.children.copy() .for node in self.children: .node.get_descendants() .for n in node.descendants: .descendants.add(n) .self.descendants = descendants Anyway, all caveats notwithstanding, I hope that is of some use to you. Best, Brian vdB -- http://mail.python.org/mailman/listinfo/python-list
Re: wxGrid
Gensek wrote: I have a grid. I want to sort it when a column label is clicked. I know about the EVT_GRID_LABEL_LEFT_DCLICK event, but that is not enough. I do not merely need to know that a label was clicked. I need to know which label was clicked. I do not know how to do that. I suspect you might know. I request that you tell me. I also wish to know some other things: how to find out the location of a mouse pointer in a wxWindow (or at least the frame), and how to change the color of a single specified pixel in a bitmap. I use Python 2.3, wxPython 2.4.2. Hi, In C++, you can use event.GetColumn() to get that info. Look at wxGridEvent. If I were you, I would try to see if these functions are also available on wxPython Michalis -- http://mail.python.org/mailman/listinfo/python-list
[ python-Bugs-1152726 ] Default class args get clobbered by prior instances.
Bugs item #1152726, was opened at 2005-02-26 22:10 Message generated for change (Comment added) made by rhettinger You can respond by visiting: https://sourceforge.net/tracker/?func=detailatid=105470aid=1152726group_id=5470 Category: Python Interpreter Core Group: Python 2.3 Status: Closed Resolution: Invalid Priority: 8 Submitted By: Simon Drabble (sdrabble) Assigned to: Nobody/Anonymous (nobody) Summary: Default class args get clobbered by prior instances. Initial Comment: OS: SuSE Linux 9.2 kernel 2.6.4 Python: 2.3.3 Define a class where the __init__() method takes a default arg of list type. Instantiate this class, and append/ extend the value of its default arg. Instantiate the class again, and the value from the first instance will overwrite the second. The bug is known to exist in 2.3.3, but may exist in subsequent releases also. The attached file illuminates the problem. -- Comment By: Raymond Hettinger (rhettinger) Date: 2005-02-27 08:18 Message: Logged In: YES user_id=80475 Sorry, this is not a bug. It is part of how Python works. In general, do not use mutables for default values. Instead, write something like: def f(x, seq=None): if seq is None: seq = [] . . . There is a FAQ on the subject: http://www.python.org/doc/faq/general.html#why-are-default-values-shared-between-objects -- You can respond by visiting: https://sourceforge.net/tracker/?func=detailatid=105470aid=1152726group_id=5470 ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[ python-Bugs-673797 ] setting socket timeout crashes SSL?
Bugs item #673797, was opened at 2003-01-23 19:58 Message generated for change (Comment added) made by pristine777 You can respond by visiting: https://sourceforge.net/tracker/?func=detailatid=105470aid=673797group_id=5470 Category: Python Library Group: Python 2.3 Status: Closed Resolution: Fixed Priority: 5 Submitted By: Craig Allen (cba037) Assigned to: Nobody/Anonymous (nobody) Summary: setting socket timeout crashes SSL? Initial Comment: First: bravo for compiling SSL support in the 2.3 binaries! I can connect fine to a secure web server using HTTPS. However, when I set a socket default timeout, I get errors: import socket socket.setdefaulttimeout(30.0) import urllib f = urllib.urlopen('https://members.tufts-health.com/memindex.html') print f.read() === Traceback (most recent call last): File quot;testssl.pyquot;, line 9, in ? f = urllib.urlopen('https://members.tufts-health.com/memindex.html') File quot;/usr/lib/python2.3/urllib.pyquot;, line 76, in urlopen return opener.open(url) File quot;/usr/lib/python2.3/urllib.pyquot;, line 181, in open return getattr(self, name)(url) File quot;/usr/lib/python2.3/urllib.pyquot;, line 375, in open_https h.endheaders() File quot;/usr/lib/python2.3/httplib.pyquot;, line 695, in endheaders self._send_output() File quot;/usr/lib/python2.3/httplib.pyquot;, line 581, in _send_output self.send(msg) File quot;/usr/lib/python2.3/httplib.pyquot;, line 548, in send self.connect() File quot;/usr/lib/python2.3/httplib.pyquot;, line 945, in connect ssl = socket.ssl(realsock, self.key_file, self.cert_file) socket.sslerror: (2, 'The operation did not complete (read)') === This is on Linux; similar behaviour on Win2K. -- Comment By: pristine777 (pristine777) Date: 2005-02-27 11:32 Message: Logged In: YES user_id=1228732 This bug has resurfaced in Python 2.4. The exact same code as in the original bug report gives the same error. I also tried using urllib2 and it gives the same result. I have tried this only on Windows (both XP professional SP2, and Windows Server 2003). I am unable to re-open this bug report so should I just file a new one? Thanks! -- Comment By: Neal Norwitz (nnorwitz) Date: 2003-02-03 13:43 Message: Logged In: YES user_id=33168 The patch was checked in, so I'm closing this bug. Please re-open if there are any problems. -- Comment By: Geoff Talvola (gtalvola) Date: 2003-01-31 09:55 Message: Logged In: YES user_id=88162 This is fixed by patch 676472 so when that patch is checked in, this bug can be closed. -- You can respond by visiting: https://sourceforge.net/tracker/?func=detailatid=105470aid=673797group_id=5470 ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[ python-Bugs-1153163 ] reflected operator not used when operands have the same type
Bugs item #1153163, was opened at 2005-02-27 20:09 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detailatid=105470aid=1153163group_id=5470 Category: Python Interpreter Core Group: Python 2.4 Status: Open Resolution: None Priority: 5 Submitted By: HughSW (hughsw) Assigned to: Nobody/Anonymous (nobody) Summary: reflected operator not used when operands have the same type Initial Comment: The reflected operators, e.g. __radd__, are used when the left operand does not have the non-reflected operator, *unless* the right operand is of the same type. The documentation on the Emulating numeric types page doesn't mention this peculiar exclusion. Of the reflected operators it says: These methods are called to implement the binary arithmetic operations (+, -, *, /, %, divmod(), pow(), **, , , , ^, |) with reflected (swapped) operands. These functions are only called if the left operand does not support the corresponding operation. For instance, to evaluate the expression x-y, where y is an instance of a class that has an __rsub__() method, y.__rsub__(x) is called. This code demonstrates the correct behavior and then the problem: class A(object): def __radd__(self, other): return '__radd__', other print None + A() print A() + A() giving ('__radd__', None) Traceback (most recent call last): File C:/Temp/reflectedbug.py, line 6, in -toplevel- print A() + A() TypeError: unsupported operand type(s) for +: 'A' and 'A' I've replaced None in the first print statement with many kinds of builtin objects, instances of other classes, and with instances of subclasses of A. In all these cases the __radd__ operator is used as documented. I've only seen the problem when the two operands are of the same type. This problem also occurs during the backing-off to plain operators that occurs when augmented operators, e.g. __iadd__, aren't implemented by the type and the operands are of the same type. This problem is present in 2.4 on Linux and Windows, and in the current CVS version (2.5a0, 27-Feb-05) on Linux. -- You can respond by visiting: https://sourceforge.net/tracker/?func=detailatid=105470aid=1153163group_id=5470 ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[ python-Bugs-1153171 ] reflected operator not used when operands have the same type
Bugs item #1153171, was opened at 2005-02-27 20:23 Message generated for change (Settings changed) made by hughsw You can respond by visiting: https://sourceforge.net/tracker/?func=detailatid=105470aid=1153171group_id=5470 Category: Python Interpreter Core Group: Python 2.4 Status: Open Resolution: Duplicate Priority: 5 Submitted By: HughSW (hughsw) Assigned to: Nobody/Anonymous (nobody) Summary: reflected operator not used when operands have the same type Initial Comment: The reflected operators, e.g. __radd__, are used when the left operand does not have the non-reflected operator, *unless* the right operand is of the same type. The documentation on the Emulating numeric types page doesn't mention this peculiar exclusion. Of the reflected operators it says: These methods are called to implement the binary arithmetic operations (+, -, *, /, %, divmod(), pow(), **, , , , ^, |) with reflected (swapped) operands. These functions are only called if the left operand does not support the corresponding operation. For instance, to evaluate the expression x-y, where y is an instance of a class that has an __rsub__() method, y.__rsub__(x) is called. This code demonstrates the correct behavior and then the problem: class A(object): def __radd__(self, other): return '__radd__', other print None + A() print A() + A() giving ('__radd__', None) Traceback (most recent call last): File C:/Temp/reflectedbug.py, line 6, in -toplevel- print A() + A() TypeError: unsupported operand type(s) for +: 'A' and 'A' I've replaced None in the first print statement with many kinds of builtin objects, instances of other classes, and with instances of subclasses of A. In all these cases the __radd__ operator is used as documented. I've only seen the problem when the two operands are of the same type. This problem also occurs during the backing-off to plain operators that occurs when augmented operators, e.g. __iadd__, aren't implemented by the type and the operands are of the same type. This problem is present in 2.4 on Linux and Windows, and in the current CVS version (2.5a0, 27-Feb-05) on Linux. -- You can respond by visiting: https://sourceforge.net/tracker/?func=detailatid=105470aid=1153171group_id=5470 ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[ python-Bugs-1153171 ] reflected operator not used when operands have the same type
Bugs item #1153171, was opened at 2005-02-27 20:23 Message generated for change (Comment added) made by hughsw You can respond by visiting: https://sourceforge.net/tracker/?func=detailatid=105470aid=1153171group_id=5470 Category: Python Interpreter Core Group: Python 2.4 Status: Open Resolution: Duplicate Priority: 5 Submitted By: HughSW (hughsw) Assigned to: Nobody/Anonymous (nobody) Summary: reflected operator not used when operands have the same type Initial Comment: The reflected operators, e.g. __radd__, are used when the left operand does not have the non-reflected operator, *unless* the right operand is of the same type. The documentation on the Emulating numeric types page doesn't mention this peculiar exclusion. Of the reflected operators it says: These methods are called to implement the binary arithmetic operations (+, -, *, /, %, divmod(), pow(), **, , , , ^, |) with reflected (swapped) operands. These functions are only called if the left operand does not support the corresponding operation. For instance, to evaluate the expression x-y, where y is an instance of a class that has an __rsub__() method, y.__rsub__(x) is called. This code demonstrates the correct behavior and then the problem: class A(object): def __radd__(self, other): return '__radd__', other print None + A() print A() + A() giving ('__radd__', None) Traceback (most recent call last): File C:/Temp/reflectedbug.py, line 6, in -toplevel- print A() + A() TypeError: unsupported operand type(s) for +: 'A' and 'A' I've replaced None in the first print statement with many kinds of builtin objects, instances of other classes, and with instances of subclasses of A. In all these cases the __radd__ operator is used as documented. I've only seen the problem when the two operands are of the same type. This problem also occurs during the backing-off to plain operators that occurs when augmented operators, e.g. __iadd__, aren't implemented by the type and the operands are of the same type. This problem is present in 2.4 on Linux and Windows, and in the current CVS version (2.5a0, 27-Feb-05) on Linux. -- Comment By: HughSW (hughsw) Date: 2005-02-27 20:31 Message: Logged In: YES user_id=1146279 Someone remove this accidental repost. Thanks. -- You can respond by visiting: https://sourceforge.net/tracker/?func=detailatid=105470aid=1153171group_id=5470 ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[ python-Bugs-1153163 ] reflected operator not used when operands have the same type
Bugs item #1153163, was opened at 2005-02-27 20:09 Message generated for change (Comment added) made by hughsw You can respond by visiting: https://sourceforge.net/tracker/?func=detailatid=105470aid=1153163group_id=5470 Category: Python Interpreter Core Group: Python 2.4 Status: Open Resolution: None Priority: 5 Submitted By: HughSW (hughsw) Assigned to: Nobody/Anonymous (nobody) Summary: reflected operator not used when operands have the same type Initial Comment: The reflected operators, e.g. __radd__, are used when the left operand does not have the non-reflected operator, *unless* the right operand is of the same type. The documentation on the Emulating numeric types page doesn't mention this peculiar exclusion. Of the reflected operators it says: These methods are called to implement the binary arithmetic operations (+, -, *, /, %, divmod(), pow(), **, , , , ^, |) with reflected (swapped) operands. These functions are only called if the left operand does not support the corresponding operation. For instance, to evaluate the expression x-y, where y is an instance of a class that has an __rsub__() method, y.__rsub__(x) is called. This code demonstrates the correct behavior and then the problem: class A(object): def __radd__(self, other): return '__radd__', other print None + A() print A() + A() giving ('__radd__', None) Traceback (most recent call last): File C:/Temp/reflectedbug.py, line 6, in -toplevel- print A() + A() TypeError: unsupported operand type(s) for +: 'A' and 'A' I've replaced None in the first print statement with many kinds of builtin objects, instances of other classes, and with instances of subclasses of A. In all these cases the __radd__ operator is used as documented. I've only seen the problem when the two operands are of the same type. This problem also occurs during the backing-off to plain operators that occurs when augmented operators, e.g. __iadd__, aren't implemented by the type and the operands are of the same type. This problem is present in 2.4 on Linux and Windows, and in the current CVS version (2.5a0, 27-Feb-05) on Linux. -- Comment By: HughSW (hughsw) Date: 2005-02-28 01:09 Message: Logged In: YES user_id=1146279 I've looked into this a little. Newbie that I am, I don't know where the x = slotw(v, w); call goes (in binary_op1() in abstract.c near line 377) AFAICT, this code in abstract.c behaves reasonably, so problem would seem to be in the tp_as_number slot-function that's getting called. And whereever that is, it's not the binary-op functions in classobject.c that I thought it would be -- You can respond by visiting: https://sourceforge.net/tracker/?func=detailatid=105470aid=1153163group_id=5470 ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com