Re: If Scheme is so good why MIT drops it?
in 121708 20090720 072858 Frank Buss wrote: >Bob Martin wrote: > >> I think the OP means "major PC operating systems". Those with a wider >> knowledge of the computer world would consider IBM's mainframe operating >> systems to be deserving of the description "major". > >Maybe you are right, if you mean big machines. I know mainframes a bit and >there are interesting concepts, like hot-swapping of CPU modules and >mainframes are very reliable. But expensive, too. I know at least one >client, who wants to change it to some cheap Linux boxes, like Google >demonstrates it. If you take care (e.g. Xen virtualization for easier >computer changing and RAID harddisks, if a downtime of some hours might be >ok), it doesn't matter if one PC goes out of order. > >But even on IBM mainframes you can install Linux or other Unix systems in >parallel to the usual operating systems for this machines, so except for >special cases, like embedded systems, the most installed and used operating >systems might be Unix-like systems and Windows. But looks like Python even >runs on more native operating systems for mainframes. Yes, a "platform" is really the combination of hardware architecture and operating system, so Linux on Intel and Linux on 390 are different platforms. -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
Bob Martin wrote: > I think the OP means "major PC operating systems". Those with a wider > knowledge of the computer world would consider IBM's mainframe operating > systems to be deserving of the description "major". Maybe you are right, if you mean big machines. I know mainframes a bit and there are interesting concepts, like hot-swapping of CPU modules and mainframes are very reliable. But expensive, too. I know at least one client, who wants to change it to some cheap Linux boxes, like Google demonstrates it. If you take care (e.g. Xen virtualization for easier computer changing and RAID harddisks, if a downtime of some hours might be ok), it doesn't matter if one PC goes out of order. But even on IBM mainframes you can install Linux or other Unix systems in parallel to the usual operating systems for this machines, so except for special cases, like embedded systems, the most installed and used operating systems might be Unix-like systems and Windows. But looks like Python even runs on more native operating systems for mainframes. -- Frank Buss, f...@frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de -- http://mail.python.org/mailman/listinfo/python-list
Re: Managing non-ascii filenames in python
> I thought the correct way to do this in python would be to scan the > dir > files=os.listdir(os.path.dirname( os.path.realpath( __file__ ) )) > > then print the filenames > for filename in files: > print filename > > but as expected teh filename is not correct - so correct it using the > file sysytems encoding > > print filename.decode(sys.getfilesystemencoding()) > > But I get > UnicodeEncodeError: 'charmap' codec can't encode character u'\u2014' > in position 6: character maps to As a starting point, you shouldn't be using byte-oriented APIs to access files on Windows; the specific byte-oriented API is os.listdir, when passed a directory represented as a byte string. So try: dirname = os.path.dirname(os.path.realpath(__file__)) dirname = dirname.decode(sys.getfilesystemencoding() files = os.listdir(dirname) This should give you the files as Unicode strings. > I need to be able to write (a representation) to the screen (and I > don't see why I should not get something as good as DOS shows). The command window (it's not really DOS anymore) uses the CP_OEMCP encoding, which is not available in Python. This does all the transliteration also, so you would have to write an extension module if you want to get the same transliteration (or try to get to the OEMCP encoding through ctypes). If you can live with a simpler transliteration, try print filename.encode(sys.stdout.encoding, "replace") > Write it to an XML file in UTF-8 > > and write it to a text file and be able to read it back in. > Again I was supprised that this was also difficult - it appears that > the file also wanted ascii. Should I have to open the file in binary > for write (I expect so) but then what encoding should I write in? You need to tell us how precisely you tried to do this. My guess is: if you now try again, with the filenames being Unicode strings, it will work fairly well. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
Steven D'Aprano writes: > Besides, one can legitimately disagree that 2/3 => 0 is the wrong thing > to do. It's the right thing to do if you're doing integer maths. I wonder whether 2/3 => ValueError is preferable. -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
in 121683 20090719 210126 Terry Reedy wrote: >Roy Smith wrote: >> In article <1cethsrrw8h6k$.9ty7j7u7zovn@40tude.net>, >> Frank Buss wrote: >> >>> there is one free unique implementation on the 3 major platforms Linux, >>> Windows and MacOS X >> >> Most people would still consider Solaris to be a "major platform". > >?? I do not, but I have no idea what comes in 4th after the other three >by whatever metric. I think the OP means "major PC operating systems". Those with a wider knowledge of the computer world would consider IBM's mainframe operating systems to be deserving of the description "major". -- http://mail.python.org/mailman/listinfo/python-list
Re: file write IOError Invalid argument
En Thu, 16 Jul 2009 17:41:39 -0300, Robert Robert escribió: I am trying to write a binary string to file on a windows network share. I get an IOError. I've read that it is because the file size is too large. I did a type( binaryString) and saw that it was type "str". So I loop through it one by one element and use f.write to write to file, and it worked without any error. However it took a long while to write to file. I was wondering how I could split this binary string into N number of chunks efficiently and write them to file. some_string[i:i+BLOCK_SIZE] returns a slice of the original string, starting at position i, with length BLOCK_SIZE. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
Carl Banks wrote: > On Jul 19, 4:29 pm, Tim Daneliuk wrote: >> Carl Banks wrote: >>> On Jul 19, 10:33 am, fft1976 wrote: On Jul 19, 9:55 am, Frank Buss wrote: > E.g. the number system: In many Lisp > implementations (/ 2 3) results in the fractional object 2/3. In Python > 2.6 > "2 / 3" results in "0". Looks like with Python 3.1 they have fixed it, now > it returns "0.66", which will result in lots of fun for porting > applications written for Python <= 2.6. How do you explain that something as inferior as Python beat Lisp in the market place despite starting 40 years later. >>> There was no reason to crosspost this here--looking at the original >>> thread on comp.lang.lisp it seems they were doing a surprisingly good >>> job discussing the issue. >>> I'm guessing it's because the fanboy Lispers like Ken Tifton were busy >>> with a flamewar in another thread (LISP vs PROLOG vs HASKELL). >>> Carl Banks >> This is an incredibly important discussion > > It might be an important question but a discussion on Usenet about it > is utterly useless. > > >> and is much weaker because >> it does not also include Pascal, BASIC, Ada, Oberon and Forth. > > In the same way that a movie is weaker because the director edited out > the bad scenes. > > >> In fact, >> picking a computer language is the most important discussion in >> Computer Science and eclipses even P=NP? in significance. I sure hope >> we can keep this thread going for a few months. > > Please feel free to extend this flame-war along for a few months on > comp.lang.lisp. Not here. > > > Carl Banks Uh Carl ... are you familiar with the concept of mocking humor? -- Tim Daneliuk tun...@tundraware.com PGP Key: http://www.tundraware.com/PGP/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Final Project
Fred Atkinson wrote: > I'm looking for some ideas here. > > I think I've mentioned I am taking a course in Python and PHP. > The professor wants each of us to pick a project to write in both > languages. It has to be something fairly complex and I'd like for it > to be something that would be useful on my Web site(s). > > I would be grateful for any and all suggestions. Useful for your webpage depends very much on what you think what you need and it is difficult to answer by others who don't know your needs. E.g. useful for me was a Python Blender script to create wireframe and solid models of platonic solids and a program for geodesic domes of parametrized detail level: http://www.frank-buss.de/shapeways/dome.py http://www.shapeways.com/mydesign?user_id=19157 It is my first bigger Python program, so ideas how it could be improved are welcome. Would be an interesting project to create a renderer for it, which can calculate this and other geometric figures as a CGI script to an image and display the result in the browser. Try this in PHP and Python and write about the experiences you made. Maybe don't forget to limit the access to the webpage or the size of the output image, to avoid trouble with your hosting provider, if you don't have your own server and anything slows down because of your rendering task :-) -- Frank Buss, f...@frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
On Sun, 19 Jul 2009 10:33:39 -0700, fft1976 wrote: > On Jul 19, 9:55 am, Frank Buss wrote: > >> E.g. the number system: In many Lisp >> implementations (/ 2 3) results in the fractional object 2/3. In Python >> 2.6 "2 / 3" results in "0". Looks like with Python 3.1 they have fixed >> it, now it returns "0.66", which will result in lots of fun for >> porting applications written for Python <= 2.6. > > How do you explain that something as inferior as Python beat Lisp in the > market place despite starting 40 years later. http://www.jwz.org/doc/worse-is-better.html Besides, one can legitimately disagree that 2/3 => 0 is the wrong thing to do. It's the right thing to do if you're doing integer maths. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: GMPY 1.10 alpha with support for Python 3
On Jul 19, 5:05 pm, casevh wrote: > GMPY 1.10 beta is now available. This version fixes an issue where > very large objects would be cached for reuse instead of being freed. Excellent! That explains the funny memory usage graph. > > Source code and Windows installers may be found > athttp://code.google.com/p/gmpy/downloads/list > Test results: import collatz_functions as cf # imports gmpy # the cf.Type12MH function does the equivalent # of the pure Python version of the function # using gmpy import time #3.1 gmpy 1.10 beta # t0 = time.time() n=10 for k in range(1,n): for i in range(1,n-2): print((str(cf.gmpy.numdigits(cf.Type12MH(k,i))).zfill(n)),end=' ') print() print() t1 = time.time() print(t1-t0) # 3.1 pure Python # ##t0 = time.time() ##n=10 ##for k in range(1,n): ## for i in range(1,n-2): ##print((str(cf.gmpy.numdigits( \ ## 2**(6*((i-1)*9**(k-1)+(9**(k-1)-1)//2+1)-1)-1 \ ## )).zfill(n)),end=' ') ## print() ##print() ##t1 = time.time() ## ##print(t1-t0) ## 3.1 gmpy 1.10 alpha ## ##02 04 06 07 09 11 13 ##09 25 42 58 74 91 000107 ##74 000221 000367 000513 000659 000806 000952 ##000659 001976 003293 004610 005926 007243 008560 ##005926 01 029627 041477 053328 065178 077028 ##053328 159981 266634 373287 479940 586593 693246 ##479940 0001439818 0002399696 0003359574 0004319453 0005279331 0006239209 ##0004319453 0012958355 0021597258 0030236161 0038875064 0047513967 0056152869 ##0038875064 0116625189 0194375315 0272125440 0349875565 0427625691 0505375816 ## ##3.3225422 ## funny memory usage display, different between 2.6 & 3.1, but funny regardless, ## memory remains allocated (~700 MB) when program halts ## 3.1 pure Python ## ##02 04 06 07 09 11 13 ##09 25 42 58 74 91 000107 ##74 000221 000367 000513 000659 000806 000952 ##000659 001976 003293 004610 005926 007243 008560 ##005926 01 029627 041477 053328 065178 077028 ##053328 159981 266634 373287 479940 586593 693246 ##479940 0001439818 0002399696 0003359574 0004319453 0005279331 0006239209 ##0004319453 0012958355 0021597258 0030236161 0038875064 0047513967 0056152869 ##0038875064 0116625189 0194375315 0272125440 0349875565 0427625691 0505375816 ## ##338.83217 ## memory usage seems normal, runs slow enough to observe memory being allocated ## and freed and remains freed when program halts ## 2.6 pure Python ## ##02 04 06 07 09 11 13 ##09 25 42 58 74 91 000107 ##74 000221 000367 000513 000659 000806 000952 ##000659 001976 003293 004610 005926 007243 008560 ##005926 01 029627 041477 053328 065178 077028 ##053328 159981 266634 373287 479940 586593 693246 ##479940 0001439818 0002399696 0003359574 0004319453 0005279331 0006239209 ##0004319453 0012958355 0021597258 0030236161 0038875064 0047513967 0056152869 ##aborted after ONE FULL WEEK of processing (only 8 of 9 rows completed) ## Something funny happened here. By the time I ran this test, there ## were 14 orphaned copies of pythonw.exe present, at least one of which ## was still running along with the real pair executing the program. Yet ## the Performance only registered ~50%. Normally, this would be 100% if ## two programs were running. Pure Python is a LOT slower than gmpy, ## but not THAT slow. These orphaned processes may be a Python 3.1 issue. ##=== ## 3.1 gmpy 1.10 beta ## ## 02 04 06 07 09 11 13 ## 09 25 42 58 74 91 000107 ## 74 000221 000367 000513 000659 000806 000952 ## 000659 001976 003293 004610 005926 007243 008560 ## 005926 01 029627 041477 053328 065178 077028 ## 053328 159981 266634 373287 479940 586593 693246 ## 479940 0001439818 0002399696 0003359574 0004319453 0005279331 0006239209 ## 0004319453 0012958355 0021597258 0030236161 0038875064 0047513967 0056152869 ## 0038875064 0116625189 0194375315 0272125440 0349875565 0427625691 0505375816 ## ## 2.4178283 ## memory usage now appears normal, no more allocated memory when program halts ## and it's so fast all we see on Performance graph is a small blip, much better ## than the 700-1400 MB it was all
Managing non-ascii filenames in python
I created the following filename in windows just as a test - “Dönåld’s™ Néphêws” deg°.txt The quotes are non -ascii, many non english characters, long hyphen etc. Now in DOS I can do a directory and it translates them all to something close. "Dönåld'sT Néphêws" deg°.txt I thought the correct way to do this in python would be to scan the dir files=os.listdir(os.path.dirname( os.path.realpath( __file__ ) )) then print the filenames for filename in files: print filename but as expected teh filename is not correct - so correct it using the file sysytems encoding print filename.decode(sys.getfilesystemencoding()) But I get UnicodeEncodeError: 'charmap' codec can't encode character u'\u2014' in position 6: character maps to All was working well till these characters came along I need to be able to write (a representation) to the screen (and I don't see why I should not get something as good as DOS shows). Write it to an XML file in UTF-8 and write it to a text file and be able to read it back in. Again I was supprised that this was also difficult - it appears that the file also wanted ascii. Should I have to open the file in binary for write (I expect so) but then what encoding should I write in? I have been beating myself up with this for weeks as I get it working then come across some outher character that causes it all to stop again. Please help. -- http://mail.python.org/mailman/listinfo/python-list
Re: question on input function
On Mon, 20 Jul 2009, Richel Satumbaga wrote: > I am just learning python then I encountered an certain point in terms of > using the input function of python. the source code: >eq = input("enter an equation:"); >print " the result is : "; > > > the output seen in the command window: > > enter an equation:[m*x+b for m in (0,10,1),for x in (1,11,1), for b in > (2,12,1)] > > Traceback (most recent call last): > File "C:/Python26/try", line 1, in > eq = input("enter an equation:"); > File "", line 1 > [m*x+b for m in (0,10,1),for x in (1,11,1), for b in (2,12,1)] >^ > SyntaxError: invalid syntax [...] It's the extra commas in your list comprehension.This should work: [m*x+b for m in (0,10,1) for x in (1,11,1) for b in (2,12,1)] HTH, John -- http://mail.python.org/mailman/listinfo/python-list
Re: question on input function
On Sun, Jul 19, 2009 at 7:07 PM, Richel Satumbaga wrote: > I am just learning python then I encountered an certain point in terms of > using the input function of python. > the source code: > eq = input("enter an equation:"); > print " the result is : "; > > > the output seen in the command window: > enter an equation:[m*x+b for m in (0,10,1),for x in (1,11,1), for b in > (2,12,1)] > > Traceback (most recent call last): > File "C:/Python26/try", line 1, in > eq = input("enter an equation:"); > File "", line 1 > [m*x+b for m in (0,10,1),for x in (1,11,1), for b in (2,12,1)] > ^ > SyntaxError: invalid syntax > > Is there any other way to enter those? or it must be coded > in the source code? > If in source code is it like in matlab where one can type: > > x = [0:1:10]; > > to define the range of x which is form 0 to 10 with the increment of 1. First, commas between the "for"s are not permitted, which gives us: [m*x+b for m in (0,10,1) for x in (1,11,1) for b in (2,12,1)] However, in Python, (i, j, k) is just a tuple (MATLAB: 1D matrix) of the items i, j, and k. What you want is a range, which is understandably created using the range() function. A step of 1 and a start of 0 are the defaults, and the stop value is always excluded, so the code becomes: [m*x+b for m in range(11) for x in range(1,12) for b in range(2,13)] Which should be what you want. For further explanation of the range() function: range(b) - the numbers from 0 to b-1 with a step of 1 range(a,b) - the numbers from a to b-1 with a step of 1 range(a,b,c) - the numbers from a to b-1 with a step of c Hope that helps. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
question on input function
I am just learning python then I encountered an certain point in terms of using the input function of python. the source code: eq = input("enter an equation:"); print " the result is : "; the output seen in the command window: >>> enter an equation:[m*x+b for m in (0,10,1),for x in (1,11,1), for b in (2,12,1)] Traceback (most recent call last): File "C:/Python26/try", line 1, in eq = input("enter an equation:"); File "", line 1 [m*x+b for m in (0,10,1),for x in (1,11,1), for b in (2,12,1)] ^ SyntaxError: invalid syntax Is there any other way to enter those? or it must be coded in the source code? If in source code is it like in matlab where one can type: x = [0:1:10]; to define the range of x which is form 0 to 10 with the increment of 1. Thanks Ann -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
In article <20090720025149.326f0...@halmanfloyd.lan.local>, Marek Kubica wrote: > > > there is one free unique implementation on the 3 major platforms > > > Linux, Windows and MacOS X > > > > Most people would still consider Solaris to be a "major platform". > > Depends on who you ask. On the desktop it doesn't matter at all > (fortunately, since everytime I work on Solaris I'm entering a world of > pain which is just slowly getting better with OpenSolaris), on the > server it (and other propietary Unices) is losing ground compared to > the free Unices. Clearly, there's not much (if any) Solaris on the desktop. But it's sure alive and kicking in the server world. One of the things I like about Python is not just how portable is it is, but how easy it is to build and deploy. We build our product on Windows, N different Linux distros, Solaris, HPUX, AIX, and OSX. I've built Python for all of those platforms. Then, I checked the install areas into Perforce. Deploying is as simple as checking out the right sandbox. We've gone through the same exercise for Perl. That was a lot more painful. -- http://mail.python.org/mailman/listinfo/python-list
Final Project
I'm looking for some ideas here. I think I've mentioned I am taking a course in Python and PHP. The professor wants each of us to pick a project to write in both languages. It has to be something fairly complex and I'd like for it to be something that would be useful on my Web site(s). I would be grateful for any and all suggestions. Regards, Fred -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
On Sun, 19 Jul 2009 11:22:30 -0700 (PDT) Elena wrote: > On Jul 19, 7:33 pm, fft1976 wrote: > > How do you explain that something as inferior as Python beat Lisp in > > the market place despite starting 40 years later. > > To be mainstream a language has to fit in most programmers' minds. Sometimes I wonder whether Python is not too complex for "most programmers", since "most programmers" use Java, which is heavily mainstream. Interesting whether it is in spite of the ridiculous limitations or because of these. Probably a mix of both. regards, Marek -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
On Sun, 19 Jul 2009 15:09:28 -0400 Roy Smith wrote: > In article <1cethsrrw8h6k$.9ty7j7u7zovn@40tude.net>, > Frank Buss wrote: > > > there is one free unique implementation on the 3 major platforms > > Linux, Windows and MacOS X > > Most people would still consider Solaris to be a "major platform". Depends on who you ask. On the desktop it doesn't matter at all (fortunately, since everytime I work on Solaris I'm entering a world of pain which is just slowly getting better with OpenSolaris), on the server it (and other propietary Unices) is losing ground compared to the free Unices. But ok, let's say 3 major platforms: Unix, Windows and Mac OS X. Mac OS X is formally a Unix but everything with GUI is non-Unix'y so it can be considered a separate platform. regards, Marek -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
On Jul 19, 4:29 pm, Tim Daneliuk wrote: > Carl Banks wrote: > > On Jul 19, 10:33 am, fft1976 wrote: > >> On Jul 19, 9:55 am, Frank Buss wrote: > > >>> E.g. the number system: In many Lisp > >>> implementations (/ 2 3) results in the fractional object 2/3. In Python > >>> 2.6 > >>> "2 / 3" results in "0". Looks like with Python 3.1 they have fixed it, now > >>> it returns "0.66", which will result in lots of fun for porting > >>> applications written for Python <= 2.6. > >> How do you explain that something as inferior as Python beat Lisp in > >> the market place despite starting 40 years later. > > > There was no reason to crosspost this here--looking at the original > > thread on comp.lang.lisp it seems they were doing a surprisingly good > > job discussing the issue. > > > I'm guessing it's because the fanboy Lispers like Ken Tifton were busy > > with a flamewar in another thread (LISP vs PROLOG vs HASKELL). > > > Carl Banks > > This is an incredibly important discussion It might be an important question but a discussion on Usenet about it is utterly useless. > and is much weaker because > it does not also include Pascal, BASIC, Ada, Oberon and Forth. In the same way that a movie is weaker because the director edited out the bad scenes. > In fact, > picking a computer language is the most important discussion in > Computer Science and eclipses even P=NP? in significance. I sure hope > we can keep this thread going for a few months. Please feel free to extend this flame-war along for a few months on comp.lang.lisp. Not here. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
Emile van Sebille writes: > >> Most people would still consider Solaris to be a "major platform". > > ?? I do not, but I have no idea what comes in 4th after the other > > three by whatever metric. > one metric calls fourth as the iPhone OS... > http://marketshare.hitslink.com/report.aspx?qprid=8... That metric is clearly wrong. The #1 platform OS platform in terms of number of units shipped is Javacard, which is in the SIM cards of billions of GSM phones. -- http://mail.python.org/mailman/listinfo/python-list
Re: any suggestions to synchronize typed text and speech ?
On 7/19/2009 4:15 PM, Stef Mientki wrote: hello, I'm using Scintilla as a wxPython widget with great pleasure. I now have an application where I want to make notes during a conversation, but also want to record the speech during that conversation. I'm using Scintilla as a wxPython widget for editing and PyAudio for the speech recording, until so far everything works fine. Here the problem part: I need to synchronize the typed text with the sound during playback. So if I click somewhere in the sound recording, the line of text, typed that moment should be highlighted. And vise versa, if the cursor in the text is moved and some special key is pressed, the sound starting 10 or 20seconds earlier should be playbacked. I though of adding bookmarks (because these are fixed in the text), and keep a list of bookmarks and sound pointers. This idea should work, but there are only 31 bookmarks. Any other suggestions ? thanks, Stef Mientki That sounds like a very specialized type of thing, which only the few people with experience with wxPython, PyAudio, and Scintilla could help you with... But you might try having a dictionary with notes and associated times, or just give each note a four-digit ID number at the beginning of it when it's entered and use that in the dictionary (to keep keys shorter). Or you could just do a little hack and increase the number of bookmarks allowed (seeing as source is available) :p Marcus -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
Carl Banks wrote: > On Jul 19, 10:33 am, fft1976 wrote: >> On Jul 19, 9:55 am, Frank Buss wrote: >> >>> E.g. the number system: In many Lisp >>> implementations (/ 2 3) results in the fractional object 2/3. In Python 2.6 >>> "2 / 3" results in "0". Looks like with Python 3.1 they have fixed it, now >>> it returns "0.66", which will result in lots of fun for porting >>> applications written for Python <= 2.6. >> How do you explain that something as inferior as Python beat Lisp in >> the market place despite starting 40 years later. > > There was no reason to crosspost this here--looking at the original > thread on comp.lang.lisp it seems they were doing a surprisingly good > job discussing the issue. > > I'm guessing it's because the fanboy Lispers like Ken Tifton were busy > with a flamewar in another thread (LISP vs PROLOG vs HASKELL). > > > Carl Banks This is an incredibly important discussion and is much weaker because it does not also include Pascal, BASIC, Ada, Oberon and Forth. In fact, picking a computer language is the most important discussion in Computer Science and eclipses even P=NP? in significance. I sure hope we can keep this thread going for a few months. For guidance, see: http://www.tundraware.com/Technology/How-To-Pick-A-Programming-Language/ -- Tim Daneliuk tun...@tundraware.com PGP Key: http://www.tundraware.com/PGP/ -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
On Jul 19, 9:31 pm, Frank Buss wrote: > fft1976 wrote: > > How do you explain that something as inferior as Python beat Lisp in > > the market place despite starting 40 years later. > But maybe the most important point: The syntax looks simple compared to > Common Lisp (much less parentheses) hahaha. -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: GMPY 1.10 alpha with support for Python 3
GMPY 1.10 beta is now available. This version fixes an issue where very large objects would be cached for reuse instead of being freed. Source code and Windows installers may be found at http://code.google.com/p/gmpy/downloads/list casevh -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
On Jul 19, 10:33 am, fft1976 wrote: > On Jul 19, 9:55 am, Frank Buss wrote: > > > E.g. the number system: In many Lisp > > implementations (/ 2 3) results in the fractional object 2/3. In Python 2.6 > > "2 / 3" results in "0". Looks like with Python 3.1 they have fixed it, now > > it returns "0.66", which will result in lots of fun for porting > > applications written for Python <= 2.6. > > How do you explain that something as inferior as Python beat Lisp in > the market place despite starting 40 years later. There was no reason to crosspost this here--looking at the original thread on comp.lang.lisp it seems they were doing a surprisingly good job discussing the issue. I'm guessing it's because the fanboy Lispers like Ken Tifton were busy with a flamewar in another thread (LISP vs PROLOG vs HASKELL). Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
On 7/19/2009 1:01 PM Terry Reedy said... Roy Smith wrote: In article <1cethsrrw8h6k$.9ty7j7u7zovn@40tude.net>, Frank Buss wrote: there is one free unique implementation on the 3 major platforms Linux, Windows and MacOS X Most people would still consider Solaris to be a "major platform". ?? I do not, but I have no idea what comes in 4th after the other three by whatever metric. one metric calls fourth as the iPhone OS... http://marketshare.hitslink.com/report.aspx?qprid=8&qptimeframe=Y&qpsp=2009&qpmr=100&qpdt=1&qpct=0&qpob=UV%20DESC Emile -- http://mail.python.org/mailman/listinfo/python-list
any suggestions to synchronize typed text and speech ?
hello, I'm using Scintilla as a wxPython widget with great pleasure. I now have an application where I want to make notes during a conversation, but also want to record the speech during that conversation. I'm using Scintilla as a wxPython widget for editing and PyAudio for the speech recording, until so far everything works fine. Here the problem part: I need to synchronize the typed text with the sound during playback. So if I click somewhere in the sound recording, the line of text, typed that moment should be highlighted. And vise versa, if the cursor in the text is moved and some special key is pressed, the sound starting 10 or 20seconds earlier should be playbacked. I though of adding bookmarks (because these are fixed in the text), and keep a list of bookmarks and sound pointers. This idea should work, but there are only 31 bookmarks. Any other suggestions ? thanks, Stef Mientki -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
Roy Smith wrote: In article <1cethsrrw8h6k$.9ty7j7u7zovn@40tude.net>, Frank Buss wrote: there is one free unique implementation on the 3 major platforms Linux, Windows and MacOS X Most people would still consider Solaris to be a "major platform". ?? I do not, but I have no idea what comes in 4th after the other three by whatever metric. -- http://mail.python.org/mailman/listinfo/python-list
Re: uniicode and executing a process with subprocess.call, or os.system
Thanks. I looked around for alternatives but didn't find this one. Rick Chris Rebert wrote: On Sat, Jul 18, 2009 at 3:30 PM, Rick King wrote: Hello, I want to copy files using subprocess.call or os.system where the file names are non-ascii, e.g. Serbian(latin), c's and s's with hacheks,etc. Windows stores all the file names in unicode so they are displayed ok in explorer, and I can read them into my program with listdir(u'.'), etc. and work with the names in the program. You should try one of the copying functions in the shutil module instead, it'll be much simpler than using subprocess: http://docs.python.org/library/shutil.html Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
In article <1cethsrrw8h6k$.9ty7j7u7zovn@40tude.net>, Frank Buss wrote: > there is one free unique implementation on the 3 major platforms Linux, > Windows and MacOS X Most people would still consider Solaris to be a "major platform". -- http://mail.python.org/mailman/listinfo/python-list
Re: tough-to-explain Python
Calroc writes: > I'm engaged presently in starting a school to teach programming from > the ground up, based roughly on the curriculum outlined in the article > I mentioned. ... > I'm excited about formal methods because one, I just heard about them, Formal methods are a big and complicated subject. Right after you heard about them is probably not the best time to start teaching them. Better get to understand them yourself first. -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
fft1976 wrote: > How do you explain that something as inferior as Python beat Lisp in > the market place despite starting 40 years later. Python is not that bad. Unlike Lisp, there is much less undefined behavior, there is one free unique implementation on the 3 major platforms Linux, Windows and MacOS X, which is stable, support multithreading and has a default GUI library binding, which is difficult to find for Lisp (e.g. I don't know of a free modern and stable Lisp implemenation with mulithreading support for Windows, with a licence with which you can use it in closed source commercial programs, like you can do with Python). Many problems in the Lispbuilder mailing list are related to problems due to different operating systems and Lisp implementations. But maybe the most important point: The syntax looks simple compared to Common Lisp (much less parentheses) and if you program in Python, it feels easier for programmer newbies. As Sussman says: "undergraduates initial experiences maximally productive". And this holds even for more experienced programmers. If you know already a bit of C, it is easy to use Python, but without the ability to do silly errors like writing out of array bounds (of course, you can do this in Lisp, too, if you remember to set the safe mode and if you use the right implementation). GC helps, too, to make the programming task easier than in C. Some more arguments, e.g. 5 times less program size than Java or C and more productive programmers: http://www.artima.com/intv/speedP.html (of course, an interview with Van Rossum might be a bit biased :-) -- Frank Buss, f...@frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de -- http://mail.python.org/mailman/listinfo/python-list
Trouble With a Form
Hi: When the form comes up the first time, there is the default value for num. When I fill in a number in the form and press send, even though the form sends to itself (same page name), I would think it would read the number sent. Here again is the code: from primeNumbers import primeNumbers try: lang = form.getfirst('lang', 'en') browser = form.getfirst('browser', 'all') site = form.getfirst('site', 'bridge') num = form.getfirst('num','') except: pass ourFile = string.split(__file__, "/") p = ourFile[len(ourFile) - 1] p = p[: - 9] site = ourFile[4][:-10] if site != '': site = site[:-1] print "Content-Type: text/html" print print """ http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd";> http://www.w3.org/1999/xhtml";> """ if num != '': num = round(float(num)) roots = primeNumbers(num) print roots if num == '': print """ http://13gems.com/test-Calculators_frame.py"; method="post"> http://13gems.com/images/search.jpg"; name="search" id="search" /> """ print '\n' -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
On Jul 19, 7:33 pm, fft1976 wrote: > How do you explain that something as inferior as Python beat Lisp in > the market place despite starting 40 years later. To be mainstream a language has to fit in most programmers' minds. -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a Form To Work
Victor Subervi wrote: When the form comes up the first time, there is the default value for num. When I fill in a number in the form and press send, even though the form sends to itself (same page name), I would think it would read the number sent. Here again is the code: from primeNumbers import primeNumbers try: lang = form.getfirst('lang', 'en') browser = form.getfirst('browser', 'all') site = form.getfirst('site', 'bridge') num = form.getfirst('num','') except: pass ourFile = string.split(__file__, "/") p = ourFile[len(ourFile) - 1] p = p[: - 9] site = ourFile[4][:-10] if site != '': site = site[:-1] print "Content-Type: text/html" print print """ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd";> http://www.w3.org/1999/xhtml";> """ if num != '': num = round(float(num)) roots = primeNumbers(num) print roots if num == '': print """ http://13gems.com/test-Calculators_frame.py"; method="post"> http://13gems.com/images/search.jpg"; name="search" id="search" /> """ print '\n' And why not use bare excepts? What is better? [snip] An exception could be raised for a number of reasons, including misspelling a name. You should catch only those exceptions you expect so that others you don't expect, caused by bugs, will still be shown; you'll then know there's a bug and can fix it. -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
fft1976 wrote: On Jul 19, 9:55 am, Frank Buss wrote: E.g. the number system: In many Lisp implementations (/ 2 3) results in the fractional object 2/3. In Python 2.6 "2 / 3" results in "0". Looks like with Python 3.1 they have fixed it, now it returns "0.66", which will result in lots of fun for porting applications written for Python <= 2.6. How do you explain that something as inferior as Python beat Lisp in the market place despite starting 40 years later. It's all part of a Dutch conspiracy to take over the world! :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
On Jul 19, 9:55 am, Frank Buss wrote: > E.g. the number system: In many Lisp > implementations (/ 2 3) results in the fractional object 2/3. In Python 2.6 > "2 / 3" results in "0". Looks like with Python 3.1 they have fixed it, now > it returns "0.66", which will result in lots of fun for porting > applications written for Python <= 2.6. How do you explain that something as inferior as Python beat Lisp in the market place despite starting 40 years later. -- http://mail.python.org/mailman/listinfo/python-list
Re: A little help with pexpect
> Piet van Oostrum (PvO) wrote: [snip] >PvO> You can also consider using paramiko instead of pexpect. [snip] > chan = t.open_session() > chan.exec_command('cat') > chan.send('abcdefghijklmn\n') In a real program it is better to use sendall here, as send may decide to send only part of its argument (the result will tell how many bytes have been sent). -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list
Re: How to receive a data file of unknown length using a python socket?
>> I am interested in seeing your code and would be grateful if you shared it >> with this list. > All right here it is. Hope it helps. Hendrik, Thank you very much!! (I'm not the OP, but found this thread interesting) Best regards, Malcolm -- http://mail.python.org/mailman/listinfo/python-list
Re: How to receive a data file of unknown length using a python socket?
On Sunday 19 July 2009 15:18:21 pyt...@bdurham.com wrote: > Hi Hendrik, > > If anybody is interested I will attach the code here. It is not a big > > module. > > I am interested in seeing your code and would be grateful if you shared > it with this list. All right here it is. Hope it helps - Hendrik netstring.py Description: application/python -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a Form To Work
Victor Subervi wrote: Hi; I have the following in a *.py page for the Web: from primeNumbers import primeNumbers try: num = form.getfirst('num') except: num = '' msg = "Oops" print "Content-Type: text/html" print print """ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd";> http://www.w3.org/1999/xhtml";> """ if num != '': try: num = round(float(num)) roots = primeNumbers(num) print roots except: msg += "We're sorry! You entered something that is not a number. Please try again.\n" num = '' if num == '': print msg print "Num:", num You get here if num == '', so you're printing out an empty string! BTW, try not to use bare excepts. print """ http://13gems.com/test-Calculators_frame.py"; method="post"> http://13gems.com/images/search.jpg"; name="search" id="search" /> """ print '\n' Now, "Oops" never gets printed, nor does the variable num (although a blank space appears to print). I am calling the very page to which the form sends its values. Assuming the imported module works, why don´t I get anything printed? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python code for testing well parenthesized expression
On Jul 14, 1:10 pm, Duncan Booth wrote: > John Machin wrote: > > Try an iterative version of checking that () [] and {} > > are balanced and nested appropriately. > > Here's how I might approach the more general case: > > def balanced(s, parens=("()",)): > ''' > Example: > >>> balanced('aAAA(b[bb(c]c))') > True > >>> balanced('aAAA(b[bb(c]c))', parens=("()", "[]")) > False > ''' > s = re.sub("[^%s]+" % re.escape("".join(parens)), "", s) > for i in range(len(s)/2): > for p in parens: > s = s.replace(p, "") > return not s > > For short strings this is obviously slower than your 'iterative' function, > but the run time mostly depends on the number of pairs of parentheses > rather than the total length of the string, so for example it starts > winning on a string with 2 pairs of parentheses about 75 characters long. def balanced(s, pairs=('()', '[]', '{}')): opening = {} closing = {} for open_, close in pairs: opening[open_] = closing[close] = object() stack = [] for char in s: marker = opening.get(char) if marker: stack.append(marker) continue marker = closing.get(char) if marker: try: if stack.pop() is not marker: return False except IndexError: return False # All markers should be popped. return not stack Can parse sequences other than strings. :] -- http://mail.python.org/mailman/listinfo/python-list
Re: On out-of-date Python Applications
On 20/07/2009 12:24 AM, Virgil Stokes wrote: John Machin wrote: On Jul 19, 6:04 pm, Virgil Stokes wrote: I am not a heavy user of Python; but, I do work with it and some of its application packages (e.g. PyODE), in an academic setting. Many of these applications packages have a Windows installer which usually works fine. However, I also try to keep up with the latest release of Python, and this is where I often have problems. That is, the latest Windows installer provided for some of these applications will not install on the latest version of Python. If the package was written for 2.x and "the latest version of Python" means 3.X, this is not surprising; your options are (1) wait until the package maintainer releases a 3.x-compatible version (2) port it to 3.x yourself (3) use 2.6 Actually John, My question was about the more general case --- how to help with upgrading applications; but, I will try to address your email. Otherwise: What does "will not install" mean? This means that when the Windows installer is executed it informs you that you do not have a match between the application and the Python that it finds on your Windows PC. You can easily find this out for yourself by trying to install PyODE on a Windows platform with a Python version later than 2.5.x. Are these pure Python packages or do they include C extensions (binary (pyd) or source?)? Obviously, this depends on the application. In the particular case that I mentioned (PyODE) I believe that there is a mix of C binaries and Python code. At what stage of the installation does the installation fail? In the initial stages. With what error message(s)? In one specific case, the message is (paraphrasing) "You do not have Python 2.5 installed" --- the installation is then aborted. With what versions of Python? I have only Python 2.6.2 on my home Windows Vista PC and PyODE does not have a Windows Installer for Python 2.6. I do understand that there can be a time lag between the release of Python applications and the latest Python. I also appreciate the work of the people that are responsible for these applications. My question is --- Is there anything I, as a user of an application package that is out-of-date with respect to the latest Python, can do to help in this process of bringing an application up-to-date? --V. Stokes Note, again John, my question was about how I might assist (help) with the updating of applications; Your answers have been very helpful in determining exactly what your problem is; thank you. but, thank you for your interest in this. Perhaps, only the owner/responsible programmer for the application can create a Windows installer, Given a source distribution, a suitable C++ compiler, and the suspension of Murphy's Law, anyone should be able to (a) install it on their own machine (b) make a Windows installer. or perhaps others could assist with this --- Perhaps indeed ... this is what my question was about. I would be glad to assist if possible :-) Suggestions: (1) contact the pyODE maintainer and ask, or check out the project's forums on sourceforge (2) if you have a C++ compiler on your Windows box: get the source distribution, unpack it, ensure that the ODE_BASE in the setup.py points to your (existing) ODE 0.7 installation, do \python26\python setup.py install and stand well back. I have just tried this and got a ton of warnings from the compile and 3 errors from the link: build\lib.win32-2.6\ode.pyd : fatal error LNK1120: 3 unresolved externals error: command '"C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\link.exe"' failed with exit status 1120 C++ is not my bag and it's way past bedtime here, so I'll just paste in the link output in the hope that someone can spot the problem: C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\ode\ode-0.7\lib\releaselib /LIBPATH:C:\python26\libs /LIBPATH:C:\python26\PCbuild ode.lib user32.lib /EXPORT:initode build\temp.win32-2.6\Release\ode_trimesh.obj /OUT:build\lib.win32-2.6\ode.pyd /IMPLIB:build\temp.win32-2.6\Release\ode.lib /MANIFESTFILE:build\temp.win32-2.6\Release\ode.pyd.manifest /NODEFAULTLIB:LIBCMT Creating library build\temp.win32-2.6\Release\ode.lib and object build\temp.win32-2.6\Release\ode.exp ode.lib(error.obj) : error LNK2019: unresolved external symbol __iob referenced in function "void __cdecl printMessage(int,char const *,char const *,char *)" (?printMessage@@yaxhpbd0...@z) ode.lib(convex.obj) : error LNK2001: unresolved external symbol __iob ode.lib(convex.obj) : error LNK2019: unresolved external symbol "public: void __thiscall std::_String_base::_Xran(void)const " (?_x...@_string_base@std@@QBEXXZ) referenced in function "public: class std::basic_string,class std::allocator > & __thiscall std::basic_stringstd::char_traits,class std::allocator >::erase(unsigned int,unsigned int)" (?er..
Re: are user defined classes hashable?
* Alan G Isaac [2009-07-19 14:46:12 +]: > Again, my question is about the class not its instances, > but still, checking as you suggest gives the same answer. That's what I get for answering before my coffee! Cheers, -- Nicolas Dandrimont "Linux poses a real challenge for those with a taste for late-night hacking (and/or conversations with God)." (By Matt Welsh) signature.asc Description: Digital signature -- http://mail.python.org/mailman/listinfo/python-list
Getting a Form To Work
Hi; I have the following in a *.py page for the Web: from primeNumbers import primeNumbers try: num = form.getfirst('num') except: num = '' msg = "Oops" print "Content-Type: text/html" print print """ http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd";> http://www.w3.org/1999/xhtml";> """ if num != '': try: num = round(float(num)) roots = primeNumbers(num) print roots except: msg += "We're sorry! You entered something that is not a number. Please try again.\n" num = '' if num == '': print msg print "Num:", num print """ http://13gems.com/test-Calculators_frame.py"; method="post"> http://13gems.com/images/search.jpg"; name="search" id="search" /> """ print '\n' Now, "Oops" never gets printed, nor does the variable num (although a blank space appears to print). I am calling the very page to which the form sends its values. Assuming the imported module works, why don´t I get anything printed? TIA, Victor -- http://mail.python.org/mailman/listinfo/python-list
Re: tough-to-explain Python
On Jul 9, 1:20 pm, Steven D'Aprano wrote: [...] > You'll excuse my skepticism about all these claims about how anyone can > program, how easy it is to teach the fundamentals of Turing Machines and > functional programming to anybody at all. Prove it. Where are your peer- > reviewed studies demonstrating such successes on randomly chosen people, > not self-selected motivated, higher-than-average intelligence students? I'm engaged presently in starting a school to teach programming from the ground up, based roughly on the curriculum outlined in the article I mentioned. I can't randomly select students but I do intend to gather data about who does how well from what starting conditions. I'm excited about formal methods because one, I just heard about them, and two, they provide me with a much more well-fleshed-out way to bridge rigorously from "raw" Turing machine models to higher order abstractions. I'm confident that anyone who can play Sudoku can learn programming and formal methods. > In the real world, human beings are prone to serious cognitive biases and > errors. Our brains are buggy. Take any list of reasoning fallacies, and > you'll find the majority of people have difficulty avoid them. The first > struggle is to get them to even accept that they *are* fallacies, but > even once they have intellectually accepted it, getting them to live up > to that knowledge in practice is much, much harder. > > In fact I'd go further and say that *every single person*, no matter how > intelligent and well-educated, will fall for cognitive biases and > fallacious reasoning on a regular basis. I agree completely. One of my chief goals is to "debug" human reasoning to whatever extent possible. This is precisely where I expect training in computer programming to come in handy. The machine symbol manipulator is not going to be fooled by reasoning fallacies. Fluency in rigorous symbol manipulation can only help us cope with the vagaries of our too-often sub-rational wetware. I think the real win starts when computers can be used as a communication medium, not for blogs and tweets and SMS txt and IM and VoIP, but for reasoned symbolically coded discussion. On Jul 9, 2:10 pm, Steven D'Aprano wrote: > On Wed, 08 Jul 2009 22:05:57 -0700, Simon Forman wrote: > >> persistent idea "out there" that programming is a very accessible > >> skill, like cooking or gardening, anyone can do it, and even profit > >> from it, monetarily or otherwise, etc., and to some extent I am > > > Programming is not like any other human activity. > > In practice? In principle? Programming in principle is not the same as it > is performed in practice. > > But in either case, programming requires both the logical reasoning of > mathematics and the creativity of the arts. Funnily enough, > mathematicians will tell you that mathematics requires the same, and so > will the best artists. I think mathematicians, engineers, artists, even > great chefs, will pour scorn on your claim that programming is not like > any other human activity. Well it's actually Dijkstra's claim, and I find it reasonable, that programming has two novel or unique aspects not present in other areas of human endeavor: vast scale and digital mechanism. http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1036.html > [...] > > > He talks about how "when all is said and done, the only thing computers > > can do for us is to manipulate symbols and produce results of such > > manipulations" and he emphasises the "uninterpreted" nature of > > mechanical symbol manipulation, i.e. that the machine is doing it > > mindlessly. > > "Manipulate symbols" is so abstract as to be pointless. By that That's the "koan form", longhand he means the Boolean domain {true, false}, the logical operations and their algebraic relationships, and the means of using same to deduce new formulae. > reasoning, I can build a "computer" consisting of a box open at the top. > I represent a symbol by an object (say, a helium-filled balloon, or a > stone), instead of a pattern of bits. I manipulate the symbol by holding > the object over the box and letting go. If it flies up into the sky, that > represents the symbol "Love is War", if it falls into the box, it > represents the symbol "Strength is Blue", and if it just floats there, it > represents "Cheddar Cheese". This is a deterministic, analog computer > which manipulates symbols. Great. > > And utterly, utterly useless. So what is my computer lacking that real > computers have? When you have answered that question, you'll see why > Dijkstra's claim is under-specified. Well, you said it yourself: your computer is lacking utility. [...] > > What is an uninterpreted formula? If you don't interpret it, how can you > distinguish it from random noise? Uninterpreted formula means that you manipulate the symbols without thinking about what they mean. You just use the rules on the formulae as such. To be useful, once you're "done" with t
Re: python, ctypes, callbacks -- access violation when calling callback
On 19 июл, 21:09, Christian Heimes wrote: > resurtm wrote: > > Can anybody explain my errors when trying to pass callback to DLL > > function? > > > Thanks for advices and solutions! > > You have to keep a reference to the callback alive yourself. ctypes > doesn't increase the refernece counter of the function when you define a > callback. As soon as the ref counter reaches 0, the function object is > collected and the pointer to the callback is invalid. > > You could assign it to a module global or instance variable. > > Christian Thanks for help Christian! It's working fine now! ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: python, ctypes, callbacks -- access violation when calling callback
resurtm wrote: > Can anybody explain my errors when trying to pass callback to DLL > function? > > Thanks for advices and solutions! You have to keep a reference to the callback alive yourself. ctypes doesn't increase the refernece counter of the function when you define a callback. As soon as the ref counter reaches 0, the function object is collected and the pointer to the callback is invalid. You could assign it to a module global or instance variable. Christian -- http://mail.python.org/mailman/listinfo/python-list
python, ctypes, callbacks -- access violation when calling callback
Hello. I'm trying to pass to the C function pointer to callback function from python. But when i'm trying to do this i get access violation within the DLL file when calling python callback. Here is the python side code: from ctypes import * # ... class NewtonBody(Structure): def __init__(self, pointer = 0): self.pointer = pointer # ... class Newton: def __init__(self): self._cdll = CDLL('newton.dll') self.world = NewtonWorld() # ... # NewtonBodySetForceAndTorqueCallback def bodySetForceAndTorqueCallback(self, body): CALLBACK = CFUNCTYPE(c_int, POINTER(NewtonBody), c_float, c_int) def callback(a, b, c): print '1' return 0 self._cdll.NewtonBodySetForceAndTorqueCallback(body.pointer, CALLBACK(callback)) return None Traceback: Traceback (most recent call last): File "Newton.py", line 119, in newton.update(10.5) File "Newton.py", line 42, in update self._cdll.NewtonUpdate(self.world.pointer, c_float(timestep)) WindowsError: exception: access violation reading 0x3C99 And finally prototype of function which i'm trying to call and callback function type declarations: typedef void (*NewtonApplyForceAndTorque) (const NewtonBody* body, dFloat timestep, int threadIndex); // ... NEWTON_API void NewtonBodySetForceAndTorqueCallback (const NewtonBody* body, NewtonApplyForceAndTorque callback); Can anybody explain my errors when trying to pass callback to DLL function? Thanks for advices and solutions! -- http://mail.python.org/mailman/listinfo/python-list
Re: A little help with pexpect
> Hussein B (HB) wrote: >HB> Hey, >HB> I'm trying to execute a command over a remore server using pexpect >HB> + >HB> url = 'ssh internalserver' >HB> res = pexpect.spawn(url) >HB> print '1' >HB> res.expect('.*ssword:') >HB> print '2' >HB> res.sendline('mypasswd') >HB> print '3' >HB> res.sendline('ls -aslh') >HB> + >HB> What I want to do is to send a couple of commands and get the >HB> response. >HB> How to do this? >HB> Thanks. You can read the output with res.readline() in a loop or similar. The problem is when to stop. You could look in the returned string for the prompt and hope the prompt doesn't accidentally occur in the output. You can also do res.expect(prompt) and get res.before() Same problem with accidentally occurrence of the prompt. Another way is to use a timeout, e.g. with read_nonblocking or specifying a timeout at the spawn call. You can also consider using paramiko instead of pexpect. It gives you considerably more control. For each command you van open a `channel' and that acts more or less similar to a socket, i.e. you get a decent EOF at the end of the command's output. This implies that you have to create a new channel for each command, but it stays within the same SSH connection (SSH allows subconnections). Example: >>> import paramiko ...Mumbles about deprecated modules... >>> hostname='server.example.net' >>> port = 22 >>> t = paramiko.Transport((hostname, port)) >>> username = 'user' >>> password = '' >>> t.connect(username=username, password=password) Open a channel for a command >>> chan = t.open_session() >>> chan.exec_command('ls -l') >>> chan.recv(99) 'total 0\ndrwxr-xr-x 2 user group 60 Apr 2 2009 Mail\ndrwx-- 2 user group 6 Dec 27 2008 tmp\n' >>> chan.recv(99) '' That was end of file. Open a new channel for a new command >>> chan = t.open_session() >>> chan.exec_command('cat') >>> chan.send('abcdefghijklmn\n') 15 >>> chan.recv(99) 'abcdefghijklmn\n' >>> -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list
Re: are user defined classes hashable?
> * Alan G Isaac [2009-07-19 13:48:16 +]: >> Are user defined classes hashable? >> (The classes; *not* the instances!) >> I'm inclined to guess it will be hashed by id and this is >> OK. On 7/19/2009 10:07 AM Nicolas Dandrimont apparently wrote: > You can check for yourself: > In [1]: class Foo(object): >...: pass >...: > In [2]: foo = Foo() > In [3]: hash(foo) > Out[3]: 15294992 > In [4]: id(foo) > Out[4]: 15294992 Again, my question is about the class not its instances, but still, checking as you suggest gives the same answer. Thanks, Alan -- http://mail.python.org/mailman/listinfo/python-list
ANN: Shed Skin 0.2, an experimental (restricted) Python-to-C++ compiler
Hi all, I have just released version 0.2 of Shed Skin, an experimental (restricted) Python-to-C++ compiler (http://shedskin.googlecode.com). It comes with 7 new example programs (for a total of 40 example programs, at over 12,000 lines) and several important improvements/bug fixes. See http://code.google.com/p/shedskin/wiki/ReleaseNotes for the full changelog. The new example programs consist of Disco, an elegant go player (see http://shed-skin.blogspot.com/2009/07/disco-elegant-python-go-player.html), a larger Voronoi implementation at 800 lines, a TSP algorithm simulating ant colonies, a nicer neural network algorithm and three compressors (Lempel-Ziv, huffman block, and arithmetic). Other than bug fixes for these programs, this release adds some important optimizations. First and foremost, inlining was greatly improved, resulting in potential speedups across the board. Second, loops such as 'for a, b in enumerate/zip(sequence[, sequence])' should now be dramatically faster (also inside list comprehensions), by avoiding allocation of intermediate tuples. Finally, basic list slicing should now be much faster. Please try it out! Mark Dufour. -- "One of my most productive days was throwing away 1000 lines of code" - Ken Thompson -- http://mail.python.org/mailman/listinfo/python-list
Re: are user defined classes hashable?
* Alan G Isaac [2009-07-19 13:48:16 +]: > Are user defined classes hashable? > (The classes; *not* the instances!) > > I want to use some classes as dictionary keys. > Python is not objecting, > but I'm not sure how to think about > whether this could be dangerous. > I'm inclined to guess it will be hashed by id > and this is OK. You can check for yourself: In [1]: class Foo(object): ...: pass ...: In [2]: foo = Foo() In [3]: hash hash In [3]: hash(foo) Out[3]: 15294992 In [4]: id(foo) Out[4]: 15294992 So yes, by default, user-defined classes are hashable, by id. You can override this behaviour by defining the __hash__ special method on your object. HTH, -- Nicolas Dandrimont signature.asc Description: Digital signature -- http://mail.python.org/mailman/listinfo/python-list
are user defined classes hashable?
Are user defined classes hashable? (The classes; *not* the instances!) I want to use some classes as dictionary keys. Python is not objecting, but I'm not sure how to think about whether this could be dangerous. I'm inclined to guess it will be hashed by id and this is OK. Thanks for any insights, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list
Re: invoke method on many instances
> Rainer Grimm (RG) a écrit: >RG> Hallo Alan, >>> def apply2(itr, methodname, *args, **kwargs): >>> f = operator.methodcaller(methodname, *args, **kwargs) >>> for item in itr: >>> f(item) >RG> you can do it in a functional way. > class A(object): >RG> ... def hello(self): return "hello: " + str >RG> ( self.__class__.__name__ ) >RG> ... > class B(A):pass >RG> ... > class C(A):pass >RG> ... > a=A() > b=B() > c=C() > a.hello() >RG> 'hello: A' > b.hello() >RG> 'hello: B' > c.hello() >RG> 'hello: C' > > map( (lambda obj : getattr(obj,"hello")()),(a,b,c)) >RG> ['hello: A', 'hello: B', 'hello: C'] > [ getattr(obj,"hello")() for obj in (a,b,c)] >RG> ['hello: A', 'hello: B', 'hello: C'] But that creates an unnecessary list. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Auto Send URL
Ah. How easy! Thank you. On Sat, Jul 18, 2009 at 7:32 PM, Chris Rebert wrote: > On Fri, Jul 17, 2009 at 6:02 AM, Victor Subervi > wrote: > > Hi; > > I am trying to script code that automatically sends a Web site visitor to > an > > URL. Specifically, when they enter a value in a search box, I have that > form > > sent to a script that writes an URL acceptable to Google, then I want to > > send the visitor off without him having to click another button. How do I > do > > this? > > Send back a webpage with a Refresh meta tag: > > > >http://YOUR-URL-HERE/";> > > > > Cheers, > Chris > -- > http://blog.rebertia.com > -- http://mail.python.org/mailman/listinfo/python-list
Re: How to receive a data file of unknown length using a python socket?
Hi Hendrik, > I have ended up writing a netstring thingy, that addresses the string > transfer problem by having a start sentinel, a four byte ASCII length (so you > can see it with a packet sniffer/displayer) and the rest of the data escaped > to take out the start sentinel and the escape character. It works, but the > four byte ASCII limits the size of what can be sent and received. It > guarantees to deliver either the whole string, or fail, or timeout. > If anybody is interested I will attach the code here. It is not a big module. I am interested in seeing your code and would be grateful if you shared it with this list. Thank you, Malcolm -- http://mail.python.org/mailman/listinfo/python-list
A little help with pexpect
Hey, I'm trying to execute a command over a remore server using pexpect + url = 'ssh internalserver' res = pexpect.spawn(url) print '1' res.expect('.*ssword:') print '2' res.sendline('mypasswd') print '3' res.sendline('ls -aslh') + What I want to do is to send a couple of commands and get the response. How to do this? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: invoke method on many instances
Hallo Alan, > def apply2(itr, methodname, *args, **kwargs): > f = operator.methodcaller(methodname, *args, **kwargs) > for item in itr: > f(item) you can do it in a functional way. >>> class A(object): ... def hello(self): return "hello: " + str ( self.__class__.__name__ ) ... >>> class B(A):pass ... >>> class C(A):pass ... >>> a=A() >>> b=B() >>> c=C() >>> a.hello() 'hello: A' >>> b.hello() 'hello: B' >>> c.hello() 'hello: C' >>> >>> map( (lambda obj : getattr(obj,"hello")()),(a,b,c)) ['hello: A', 'hello: B', 'hello: C'] >>> [ getattr(obj,"hello")() for obj in (a,b,c)] ['hello: A', 'hello: B', 'hello: C'] Greetings from Rottenburg, Rainer -- http://mail.python.org/mailman/listinfo/python-list
Re: On out-of-date Python Applications
On Jul 19, 6:04 pm, Virgil Stokes wrote: > I am not a heavy user of Python; but, I do work with it and some of its > application packages (e.g. PyODE), in an academic setting. > Many of these applications packages have a Windows installer which > usually works fine. However, I also try to keep up with the latest > release of Python, and this is where I often have problems. That is, the > latest Windows installer provided for some of these applications will > not install on the latest version of Python. If the package was written for 2.x and "the latest version of Python" means 3.X, this is not surprising; your options are (1) wait until the package maintainer releases a 3.x-compatible version (2) port it to 3.x yourself (3) use 2.6 Otherwise: What does "will not install" mean? Are these pure Python packages or do they include C extensions (binary (pyd) or source?)? At what stage of the installation does the installation fail? With what error message(s)? With what versions of Python? > > I do understand that there can be a time lag between the release of > Python applications and the latest Python. I also appreciate the work of > the people that are responsible for these applications. > > My question is --- Is there anything I, as a user of an application > package that is out-of-date with respect to the latest Python, can do to > help in this process of bringing an application up-to-date? > > --V. Stokes -- http://mail.python.org/mailman/listinfo/python-list
Re: How to receive a data file of unknown length using a python socket?
On Sunday 19 July 2009 02:12:32 John Machin wrote: > > Apologies in advance for my ignorance -- the last time I dipped my toe > in that kind of water, protocols like zmodem and Kermit were all the > rage -- but I would have thought there would have been an off-the- > shelf library for peer-to-peer file transfer over a socket > interface ... not so? *Grins at the references to Kermit and zmodem, and remembers Laplink and PC Anywhere* If there is such a transfer beast in Python, I have not found it. (There is an FTP module but that is not quite the same thing) I think it is because the network stuff is all done in the OS or NFS and SAMBA now - with drag and drop support and other nice goodies. I have ended up writing a netstring thingy, that addresses the string transfer problem by having a start sentinel, a four byte ASCII length (so you can see it with a packet sniffer/displayer) and the rest of the data escaped to take out the start sentinel and the escape character. It works, but the four byte ASCII limits the size of what can be sent and received. It guarantees to deliver either the whole string, or fail, or timeout. If anybody is interested I will attach the code here. It is not a big module. This question seems to come up periodically in different guises. To the OP: There are really very few valid ways of solving the string transfer problem, given a featureless stream of bytes like a socket. The first thing that must be addressed is to sync up - you have to somehow find the start of the thing as it comes past. And the second is to find the end of the slug of data that you are transferring. So the simplest way is to designate a byte as a start and end sentinel, and to make sure that such a byte does not occur in the data stream, other than as a start and end marker. This process is called escaping, and the reverse is called unescaping. (SDLC/HDLC does this at a bit pattern level) Another way is to use time, namely to rely on there being some minimum time between slugs of data. This does not work well on TCP/IP sockets, as retries at the lower protocol levels can give you false breaks in the stream. It works well on direct connections like RS-232 or RS-485/422 lines. Classic netstrings send length, then data. They rely on the lower level protocols and the length sent for demarcation of the slug, and work well if you connect, send a slug or two, and disconnect. They are not so hot for long running processes, where processors can drop out while sending - there is no reliable way for a stable receiver to sync up again if it is waiting for a slug that will not finish. Adapting the netstring by adding a sync character and time out is a compromise that I have found works well in practice. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: On out-of-date Python Applications
Virgil Stokes wrote: > some of these applications will not install on the latest version of Python. Which version of Python precisely? -- "The ability of the OSS process to collect and harness the collective IQ of thousands of individuals across the Internet is simply amazing." - Vinod Valloppillil http://www.catb.org/~esr/halloween/halloween4.html -- http://mail.python.org/mailman/listinfo/python-list
On out-of-date Python Applications
I am not a heavy user of Python; but, I do work with it and some of its application packages (e.g. PyODE), in an academic setting. Many of these applications packages have a Windows installer which usually works fine. However, I also try to keep up with the latest release of Python, and this is where I often have problems. That is, the latest Windows installer provided for some of these applications will not install on the latest version of Python. I do understand that there can be a time lag between the release of Python applications and the latest Python. I also appreciate the work of the people that are responsible for these applications. My question is --- Is there anything I, as a user of an application package that is out-of-date with respect to the latest Python, can do to help in this process of bringing an application up-to-date? --V. Stokes -- http://mail.python.org/mailman/listinfo/python-list
Re: how two join and arrange two files together
amr...@iisermohali.ac.in wrote: [please keep the correspondence on the mailing list/newsgroup] > It is working sir, but my datas are on file when i replaced StringIO("") > with open("filename.txt") then it is not printing the result properly, > like in one file i have data like:--- > 33 ALA H = 7.57 N = 121.52 CA = 55.58 HA = 3.89 C = 179.24 > 38 ALA H = 8.29 N = 120.62 CA = 54.33 HA = 4.04 C = 178.95 > 8 ALA H = 7.85 N = 123.95 CA = 54.67 HA = 2.98 C = 179.39 > 15 ALA H = 8.05 N = 119.31 CA = 52.18 HA = 4.52 C = 177.18 > 21 ALA H = 7.66 N = 123.58 CA = 54.33 HA = 4.05 C = 179.35 > 23 ALA H = 8.78 N = 120.16 CA = 55.84 HA = 4.14 C = 179.93 > in other:--- > 8 ALA helix (helix_alpha, helix1) > 21 ALA helix (helix_alpha, helix2) > 23 ALA helix (helix_alpha, helix2) > 33 ALA helix (helix_alpha, helix3) > 38 ALA helix (helix_alpha, helix3) > 49 ALA bend > and it is giving the result:- > 15 ALA H = 8.05 N = 119.31 CA = 52.18 HA = 4.52 C = 177.18| > 23 ALA H = 8.78 N = 120.16 CA = 55.84 HA = 4.14 C = 179.93|23 ALA helix > (helix_alpha, helix2) > 38 ALA H = 8.29 N = 120.62 CA = 54.33 HA = 4.04 C = 178.95|38 ALA helix > (helix_alpha, helix3) > |49 ALA bend > 8 ALA H = 7.85 N = 123.95 CA = 54.67 HA = 2.98 C = 179.39|8 ALA helix > (helix_alpha, helix1) > it is not printing the result for 33 and 21. Hint: you have to adapt the key() function from def key(line): return line[:1] to something that returns the same key for lines in the two files that belong together, and different keys for lines that don't. Peter -- http://mail.python.org/mailman/listinfo/python-list
Import hashlib fails, embedded
I'm working on an embeddded Python interpreter (using the c-api) where we are loading a custom, zipped copy of the standard Python library (./lib/python25.zip). Everything is working fine, but when I try to "import hashlib", i get the following error: Traceback (most recent call last): File "tryrun.py", line 2, in import hashlib File "~/workspace/pyboinc/lib/python25.zip/hashlib.py", line 133, in File "~/workspace/pyboinc/lib/python25.zip/hashlib.py", line 60, in __get_builtin_constructor ImportError: No module named _md5 I assume this is related to a builtin or dynamically loaded C module, but I'm not sure exactly what the problem is. Can anyone explain to me what is going wrong? Other modules (like sys, os) are working fine, which may be because they are pure-Python modules. Here is the main function: int main(int argc, const char* argv[]) { if (argc < 2) { cerr << "Module name missing\n"; cerr << "usage: " << argv[0] << " module" << endl; return 1; } // get the python library name char* libname = get_lib_name(); // try to copy the library from ./libname to ./lib/libname if (!copy_lib(libname)) { return 1; } Py_SetProgramName((char*)argv[0]); Py_SetPythonHome("./"); Py_Initialize(); if (argc > 0){ PySys_SetArgv(argc-1, (char**)(argv+1)); } { PyObject* syspath = PySys_GetObject("path"); if (!syspath) { cerr << "Couldn't get sys.path" << endl; return 1; } if (!PyList_Check(syspath)) { cerr << "sys.path not a list" << endl; return 1; } PyObject* str = PyString_FromString("."); PyList_Append(syspath, str); Py_DECREF(str); } Py_InitModule("boinc", BoincMethods); PyObject* name = PyString_FromString(argv[1]); PyObject* mod = PyImport_Import(name); Py_DECREF(name); if (!mod) { cerr << "Error loading module" << endl; PyErr_Print(); return 1; } Py_DECREF(mod); Py_Finalize(); } -- Jeremy -- http://mail.python.org/mailman/listinfo/python-list
Re: How to receive a data file of unknown length using a python socket?
> John Machin (JM) wrote: >JM> On Jul 19, 7:43 am, Irmen de Jong wrote: >>> twgray wrote: >>> > I am attempting to send a jpeg image file created on an embedded >>> > device over a wifi socket to a Python client running on a Linux pc >>> > (Ubuntu). All works well, except I don't know, on the pc client side, >>> > what the file size is? >>> >>> You don't. Sockets are just endless streams of bytes. You will have to >>> design some form >>> of 'wire protocol' that includes the length of the message that is to be >>> read. >JM> Apologies in advance for my ignorance -- the last time I dipped my toe >JM> in that kind of water, protocols like zmodem and Kermit were all the >JM> rage -- but I would have thought there would have been an off-the- >JM> shelf library for peer-to-peer file transfer over a socket >JM> interface ... not so? Yes, many of them, for example HTTP or FTP. But I suppose they are overkill in this situation. There are also remote procedure call protocols which can do much more, like XMLRPC. By the way if the image file is the only thing you send, the client should close the socket after sending and then the receiver will detect end of file which will be detected by your `if len(data) == 0:' -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list