Zope 3.2.0 beta 2 released!
The Zope 3 development team is proud to announce Zope 3.2.0 beta 2. Zope 3 is the next major Zope release and has been written from scratch based on the latest software design patterns and the experiences of Zope 2. It is our opinion that Zope 3 is more than ready for production use, which is why we decided to drop the 'X' for experimental from the name. We will also continue to work on making the transition between Zope 2 and Zope 3 as smooth as possible. As a first step, Zope 2.8 includes Zope 3 features in the form of Five. This is a long term effort. We're not there yet. **You can't run Zope 2 applications in Zope 3.** Downloads http://zope.org/Products/Zope3 Installation instructions for both Windows and Un*x/Linux are now available in the top level 'README.txt' file of the distribution. The binary installer is recommended for Windows. Zope 3.2 requires Python 2.4.2 to run. You must also have zlib installed on your system. Most Important Changes Since 3.2b1 New features - Added an option to mkzopeinstance to create instances that use ZServer, rather than Twisted. - Changed the way returning large results is handled. Applications can now simply return files to the publisher. Bug Fixes - Added input buffering to the twisted integration - Fixed the plumbing in ZServer so that attempts to return large output efficiently using iterators can actually succeed. For a complete list of changes see the 'CHANGES.txt' file. Resources - Zope 3 Development Web Site:http://dev.zope.org/Zope3 - Zope 3 Dev Mailing List:http://mail.zope.org/mailman/listinfo/zope3-dev - Zope 3 Users Mailing List:http://mail.zope.org/mailman/listinfo/zope3-users - IRC Channel: #zope3-dev at irc.freenode.net Acknowledgments Thanks goes to everyone that contributed. Enjoy! The Zope 3 Development Team -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: python coding contest
Simon Hengel wrote: Is it necessary to keep the input parameter as 'input'? Reducing that to a single character drops the length of a program by at least 8 characters. Technically it changes the interface of the function, so it's a little bogus, but test.py doesn't check. (Personally I prefer that if be illegal, but if it's legal I'll have to do it). You may change input to something more short, like x. Everything that passes the test, has a good chance to be accepted. How good is good for import test_vectors seven_seg = test_vectors.test_vectors.get or code using the test suite in general? Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: libxml2 and mindom
Hi Paul, Now I am fixed with libxml2 and libxml2dom. but can you tell me to what extent libxml2dom supports minidom. because I want minidom for traversing. Where I can find the documentation of libxml2dom. -- http://mail.python.org/mailman/listinfo/python-list
Beautiful Python
I've been reading a lot of python modules lately to see how they work and I've stumbled across something that's sort of annoying and wanted to find out of there was a good reason behind it. In a Perl program when you're calling other modules you'll add use statements at the beginning of your script like: use strict; use WWW::Mechanize; use CGI; This seems to be the de facto standard in the Perl community but in python it seems most of the code I look at has import statements everywhere in the code. Is there a sound reason for putting the imports there are are developers just loading modules in as they need them. I own Damian Conway's book of Perl Best Practices and it seems from a maintainability standpoint that having all the modules declared at the beginning would make it easier for someone coming behind you to see what other modules they need to use yours. Being new I didn't know if there was a performance reason for doing this or it is simply a common habit of developers. -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
taroso at gmail.com writes: Currently I'm on 149 characters in urgh one line - 128 without spaces/newlines. (it'd be three characters shorter if it didn't have to end with a \n) -T. unclean... unclean... are you importing zlib or bz2 ? -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
anonymous wrote: are you importing zlib or bz2 ? I don't think either of these would help in this case. While the length of the compressed string might be significantly shorter than your solution, the resulting string *literal* you decompress will contain a bunch of \-escaped characters, so it will end up being longer. -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
I don't think either of these would help in this case. While the length of the compressed string might be significantly shorter than your solution, the resulting string *literal* you decompress will contain a bunch of \-escaped characters, so it will end up being longer. PS: I'm at 155, damn you taroso... -- http://mail.python.org/mailman/listinfo/python-list
Re: Beautiful Python
Gekitsuu napisal(a): use strict; use WWW::Mechanize; use CGI; This seems to be the de facto standard in the Perl community but in python it seems most of the code I look at has import statements everywhere in the code. Is there a sound reason for putting the imports there are are developers just loading modules in as they need them. I own Damian Conway's book of Perl Best Practices and it seems from a maintainability standpoint that having all the modules declared at the beginning would make it easier for someone coming behind you to see what other modules they need to use yours. Being new I didn't know if there was a performance reason for doing this or it is simply a common habit of developers. Sometimes putting import statements at the beginning is not feasible (i.e. only when some condition has been met), as importing has some impact on program execution (importing executes code in imported module). This does not resemble Java imports (I don't know Perl). -- Jarek Zgoda http://jpa.berlios.de/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Indentation/whitespace
i think you can't call an editor python capable unless it shows you clearly hard (yuck)or soft tabs like View / Show Invisibles in textmate, View / view whitespace in komodo. Zeus for Windows has this View / View whitespace feature: http://www.zeusedit.com Note: Zeus is shareware (45 day trial) Jussi Jumppanen Author: Zeus for Windows -- http://mail.python.org/mailman/listinfo/python-list
Windows and python execution
What I would like to do it type something like myscript.py instead of python myscript.py on a Windows console. I know its possible because Ruby scripts manage to do this - I just don't know the registry settings that need to be tweaked to enable it. Any ideas (I'd prefer to know the registry settings rather than a graphical way to accomplish the goal)? -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows and python execution
Well, can't help with the registry, but I suppose you could search google for edit system variables path registry and find the hard way. The easy way is: You need to add the path of the directory where you keep myscript.py to your system path. You do this by going to Control Panel | System | Advanced | Environmental Variables. At the bottom under System Variables, edit the variable PATH and add the directory where you want to keep your Python scripts. rpd -- http://mail.python.org/mailman/listinfo/python-list
PyHtmlGUI Project is looking for developers
Hi all, the PyHtmlGUI Project (http://www.sourceforge.net/projects/pyhtmlgui) is looking for developers that want to join. The aim of the project is to create a web application framework. The API of PyHtmlGUI wants to be close to Trolltechs famous Qt API but incooperates the idea of a text based renderengine instead of the pixel based one. The obviouse target is html/css but through xml rendering process nearly every textual output could be generated. So far we finished a proof-of-concept prototype that is available via CVS from sourceforge. Now we would like to extend this prototype to a full useable framework. But therefore we would like to have more developer involved. On the one hand because of time issues on the other hand to get new ideas and comments for the project. What skills you should have to join ? Well, you should at least be able to program in python ;). But of course a very big plus is knowledge about Qt because the basic idea is to transfer Qt's API to PyHtmlGUI. But it is not necessary that you are a Qt guru. And if you don't have the slightest idea what Qt is you could still help us with bugfixing and unittesting. The bottom line is that we are looking for people that can help us to create a great web application framework. How can you join ? Just write me a email. Greetings, Ingo -- http://mail.python.org/mailman/listinfo/python-list
changing ethernet mac
Has anyone got a tip on how to control the source and destination ethernet macs using python?I am trying to test a bridge-like device. I have tried to use dnet and some of the other modules from Dugsong, but without success. I am using a win2000 os, so my options are more limited than in the *nix world. All help appreciated -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows and python execution
On 26/12/05, Mark Carter [EMAIL PROTECTED] wrote: What I would like to do it type something like myscript.pyinstead of python myscript.py Open an explorer window or open My Computer Click on TOOLS then FOLDER OPTIONS Select the FILE TYPES tab and click on NEW Enter PY as the file extension and click OK Select PY from the list and click CHANGE Select your Python.exe executable from the list or (using other) from your Python folder in your Python folder (c:\python24?) create a file called python.pth and add a line for any *subdir* that you have stored your python apps and scripts in eg: c:\pythonapps c:\pythonapps\data c:\pythontest c:\pythontest\archives c:\pythontest\archives\temp HTH :) -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
(Current status: 147 characters) Nope - no imports at all. The horrible thing is it's NOT the the most unpleasant piece of Python I've written. -T. A gentleman is someone who knows how to play the bagpipes but doesn't -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
* anonymous wrote: are you importing zlib or bz2 ? Haha, I've tried that myself. Funnily the bz2 result had exactly the same length as the original. Code with that entropy is... nasty ;) Still 179. It seems, I need to rethink the algorithm ;-) nd -- die (eval q-qq:Just Another Perl Hacker :-) # André Malo, http://www.perlig.de/ # -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows and python execution
Mark Carter [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: What I would like to do it type something like myscript.py instead of python myscript.py on a Windows console. I know its possible because Ruby scripts manage to do this - I just don't know the registry settings that need to be tweaked to enable it. Any ideas (I'd prefer to know the registry settings rather than a graphical way to accomplish the goal)? As another poster points out, be sure that your Python is on your path. And there is a PATHEXT environment variable, which contains extensions that signal that the program is executable. Add .PY and .PYW to this list and you will be good to go. -- rzed -- http://mail.python.org/mailman/listinfo/python-list
Re: Indentation/whitespace
No, it is that simple. You don't want it to be is all. Robert -- http://mail.python.org/mailman/listinfo/python-list
Re: Beautiful Python
On Mon, 26 Dec 2005 02:01:07 -0800, Gekitsuu wrote: Is there a sound reason for putting the imports there are are developers just loading modules in as they need them. I own Damian Conway's book of Perl Best Practices and it seems from a maintainability standpoint that having all the modules declared at the beginning would make it easier for someone coming behind you to see what other modules they need to use yours. Maintainability is a good reason for doing imports at the beginning of your module. But it isn't the only consideration: - if your module only imports modules which are part of the standard library, the maintainability argument is irrelevant (except possibly for very special cases like I want to back-port your module to Python 1.5, what modules do I need?). - Encapsulation: sometimes you want to import objects so they are local to a function or class. If you import them at the beginning of the module, they will be global to the module. - Cost: importing a module may not be cheap. Why pay that cost if you don't need to? Sometimes it makes sense to delay importing until you know you really need it. - Namespace pollution: when a module imports your module, it will see everything you have imported. By delaying imports to a local scope, you reduce the number of objects in your module namespace that get exported. These arguments are especially strong when using the from module import name form of import. Putting all your imports together at the beginning is recommended but not compulsory precisely because there can be good reasons for delaying imports. Think of always do your imports at the beginning as a guideline, not a law. If you are writing something like: import A ...code... import B ...code... import C ...code... then this should be re-written as: import A import B import C # or just import A, B, C ...code... But if you are writing: import A ...code... def foo(): import B # module B is only used in foo ...code... then I don't think there is anything necessarily wrong with that. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Fwd: oddness question for threading in pyw
I forward this letter from wxPython maillist, because it seems that no one answers my question, so I want to ask somebody for help in here. Thanks. -- Forwarded message -- From: limodou [EMAIL PROTECTED] Date: 2005-12-26 下午3:06 Subject: oddness question for threading in pyw To: [EMAIL PROTECTED] When I'm dealing theading program in wxPython, I find an oddness question. If the python filename is '.pyw' suffixed, and the thread is set as daemon, when I double clicked it to run, the thread object seems be blocked till I exit the program. But if the thread is not set as daemon, every thing is ok. But if the python filename is not '.pyw' suffixed, but '.py', the question is disappeared. Can anybody explain it for me, and how to resolved it? Need I change the deamon to false? There is a testing program, which I modified from the wxPython Threading Demo. import random import time import thread import threading import wx import wx.lib.newevent #-- # This creates a new Event class and a EVT binder function (UpdateBarEvent, EVT_UPDATE_BARGRAPH) = wx.lib.newevent.NewEvent() #-- class CalcBarThread(threading.Thread): def __init__(self, win, barNum, val): threading.Thread.__init__(self, name=CalcBarThread) self.win = win self.barNum = barNum self.val = val self.keepGoing = self.running = True def Start(self): self.keepGoing = self.running = True thread.start_new_thread(self.Run, ()) def Stop(self): self.keepGoing = False def IsRunning(self): return self.running def run(self): while self.keepGoing: evt = UpdateBarEvent(barNum = self.barNum, value = int(self.val)) wx.PostEvent(self.win, evt) sleeptime = (random.random() * 2) + 0.5 time.sleep(sleeptime/4) sleeptime = sleeptime * 5 if int(random.random() * 2): self.val = self.val + sleeptime else: self.val = self.val - sleeptime if self.val 0: self.val = 0 if self.val 300: self.val = 300 self.running = False #-- class GraphWindow(wx.Window): def __init__(self, parent, labels): wx.Window.__init__(self, parent, -1) self.values = [] for label in labels: self.values.append((label, 0)) font = wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD) self.SetFont(font) self.colors = [ wx.RED, wx.GREEN, wx.BLUE, wx.CYAN, Yellow, Navy ] self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) self.Bind(wx.EVT_PAINT, self.OnPaint) def SetValue(self, index, value): assert index len(self.values) cur = self.values[index] self.values[index:index+1] = [(cur[0], value)] def SetFont(self, font): wx.Window.SetFont(self, font) wmax = hmax = 0 for label, val in self.values: w,h = self.GetTextExtent(label) if w wmax: wmax = w if h hmax: hmax = h self.linePos = wmax + 10 self.barHeight = hmax def GetBestHeight(self): return 2 * (self.barHeight + 1) * len(self.values) def Draw(self, dc, size): dc.SetFont(self.GetFont()) dc.SetTextForeground(wx.BLUE) dc.SetBackground(wx.Brush(self.GetBackgroundColour())) dc.Clear() dc.SetPen(wx.Pen(wx.BLACK, 3, wx.SOLID)) dc.DrawLine(self.linePos, 0, self.linePos, size.height-10) bh = ypos = self.barHeight for x in range(len(self.values)): label, val = self.values[x] dc.DrawText(label, 5, ypos) if val: color = self.colors[ x % len(self.colors) ] dc.SetPen(wx.Pen(color)) dc.SetBrush(wx.Brush(color)) dc.DrawRectangle(self.linePos+3, ypos, val, bh) ypos = ypos + 2*bh if ypos size[1]-10: break def OnPaint(self, evt): width, height = size =self.GetSize() bmp = wx.EmptyBitmap(width, height) dc = wx.MemoryDC() dc.SelectObject(bmp) self.Draw(dc, size) wdc = wx.PaintDC(self) wdc.BeginDrawing() wdc.Blit(0,0, size[0], size[1], dc, 0,0) wdc.EndDrawing() dc.SelectObject(wx.NullBitmap) def OnEraseBackground(self, evt): pass #-- class TestFrame(wx.Frame): def __init__(self, parent, log): wx.Frame.__init__(self, parent, -1, Thread Test, size=(450,300)) self.log = log #self.CenterOnParent() panel = wx.Panel(self, -1) panel.SetFont(wx.Font(10,
Re: Windows and python execution
rzed wrote: Mark Carter [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: What I would like to do it type something like myscript.py instead of python myscript.py As another poster points out, be sure that your Python is on your path. And there is a PATHEXT environment variable, Aha. You'bve provided a significant clue. What you need to do is include the following line in autoexec.bat: set .py=c:\python24\python.exe This will achieve the desired result. I'm suprised more people don't use it. -- http://mail.python.org/mailman/listinfo/python-list
Re: build curiosities of svn head (on WinXP)
David Murmann wrote: hi all! i just built revision 41809 under winxp using a rather uncommon setup (at least i think so). since i have no visual studio here, i only used freely available tools: cygwin to get the source, the microsoft compiler/linker and NAnt (nant.sf.net) as the build tool to interpret the .vcproj-files (which may be the uncommon part). Excellent! as far as i understand this setup is not supported in any way, but i noticed two problems, that could be interesting for others as well. first, the ProjectGUID's in pythoncore.vcproj and pcbuild.sln mismatch, i fixed that locally by changing pythoncore.vcproj (maybe visual studio is ignoring/shadowing this problem?). That could be. I don't believe anyone who's doing any serious work on the Windows implementation is using anything other than Visual Studio (I seem to remember that a few copies were donated a while ago). second, the build order in pcbuild.sln for elementtree seems to be wrong, nant tried to build elementtree before pythoncore (which failed). i fixed this by building elementtree separately. Yes, the elementtree module is a new arrival for 3.5, so the build may not yet be perfectly specified. This is useful information. so my question is: will something like this be changed to support this setup (or at least to get the project files cleaner)? should i submit a patch and see if it gets accepted? I suspect that the patch's chances of being accepted are much higher if its author will commit to providing ongoing support for it. At present the developers seem to feel that this is the only reliable way to incorporate a new platform (someone recently announced they had a working DOS implementation of 2.4, but there was some resistance to including it as a standard part of the build because of doubts about ongoing support). apart from that everything went fine, and i could reproduce the expected failure (ATM) of the regression test suite: http://mail.python.org/pipermail/python-dev/2005-December/059033.html btw, if anyone is interested in the (rather small) build-script for nant, just ask, so long, David. This is terrific news. Just recently there have been indications that the Windows platform needs a larger base of developers, and this might be just the thing to promote that. It might be worth a quick post to python-dev to see what interest your new development gets. Well done! regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows and python execution
What you need to do is include the following line in autoexec.bat: set .py=c:\python24\python.exe Whatever works for you. I don't have that command in my autoexec.bat file and my python scripts execute from any location because the directory they are stored in is in my PATH variable. -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows and python execution
Mark Carter wrote: rzed wrote: Mark Carter [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: What I would like to do it type something like myscript.py instead of python myscript.py As another poster points out, be sure that your Python is on your path. And there is a PATHEXT environment variable, Aha. You'bve provided a significant clue. What you need to do is include the following line in autoexec.bat: set .py=c:\python24\python.exe This will achieve the desired result. I'm suprised more people don't use it. I'm surprised the installer doesn't do it :) -- http://mail.python.org/mailman/listinfo/python-list
Re: build curiosities of svn head (on WinXP)
Steve Holden wrote: David Murmann wrote [...] apart from that everything went fine, and i could reproduce the expected failure (ATM) of the regression test suite: http://mail.python.org/pipermail/python-dev/2005-December/059033.html btw, if anyone is interested in the (rather small) build-script for nant, just ask, so long, David. This is terrific news. Just recently there have been indications that the Windows platform needs a larger base of developers, and this might be just the thing to promote that. It might be worth a quick post to python-dev to see what interest your new development gets. Well done! David: Apparently Tim Peters has just tracked down the causes of the build errors with VC7, so the Subversion repository should now hold a valid project file for you to test against. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
On Sun, 25 Dec 2005 16:39:47 +0100, Simon Hengel [EMAIL PROTECTED] wrote: Hello, we are hosting a python coding contest an we even managed to provide a price for the winner... ^ How much are you going to sell him or her for? ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows and python execution
The installer can put python.exe in his PATH but if he's storing his scripts in some oddball place then he has to tell Windows where to find them. rpd -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
[EMAIL PROTECTED] wrote: Currently I'm on 149 characters in urgh one line - 128 without spaces/newlines. (it'd be three characters shorter if it didn't have to end with a \n) It'll be interesting to see what the short 1-line answers look like. I have a hard time seeing how that's done. It'll especially be interesting to see if we're all using similar tricks or if the multiline attemps take a distinctly different tack than the single line attempts. Currently, I'm down to 137 characters now in 6 lines. There's very little left to trim at this point, so I don't know that I'll be able to knock it down any further using my current approach. And since I don't have any other approaches in the wings, I may be about washed up. -tim -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows and python execution
BartlebyScrivener wrote: The installer can put python.exe in his PATH but if he's storing his scripts in some oddball place then he has to tell Windows where to find them. I think you're misunderstanding what I was after. python.exe is already in my PATH. What I was trying to do was execute a python script without having to type the word python explicitly. For that, you need the set command that I listed in a previous post. Anyway, I want to be able to put my scripts in oddball places, as they form part of separate projects rather than a generally-runnable script. It doesn't matter to me that Windows cannot find the script itself - because I just go to the directory where's it's at. The upshot is that my original problem has now been solved, and that discussing the matter further will only likely confuse the issue. -- http://mail.python.org/mailman/listinfo/python-list
Re: PyHtmlGUI Project is looking for developers
[EMAIL PROTECTED] enlightened us with: The aim of the project is to create a web application framework. The API of PyHtmlGUI wants to be close to Trolltechs famous Qt API but incooperates the idea of a text based renderengine instead of the pixel based one. The obviouse target is html/css but through xml rendering process nearly every textual output could be generated. Why is your project better than simply embedding a KHTML control in a GUI? Just write me a email. Just check this group for replies. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa -- http://mail.python.org/mailman/listinfo/python-list
Re: build curiosities of svn head (on WinXP)
[David Murmann] ... second, the build order in pcbuild.sln for elementtree seems to be wrong, nant tried to build elementtree before pythoncore (which failed). i fixed this by building elementtree separately. [Steve Holden] Yes, the elementtree module is a new arrival for 3.5, so the build may not yet be perfectly specified. This is useful information. I just checked in a fix for that. Thanks! ... ... and i could reproduce the expected failure (ATM) of the regression test suite: http://mail.python.org/pipermail/python-dev/2005-December/059033.html Note that all tests pass on Windows as of Sunday (in release and debug builds, with and without -O). -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
* Tim Hochberg wrote: Currently, I'm down to 137 characters now in 6 lines. There's very little left to trim at this point, so I don't know that I'll be able to knock it down any further using my current approach. And since I don't have any other approaches in the wings, I may be about washed up. grmpf. Just reached 143 chars / 2 lines ;-) There seems to be some more room for optimization... nd -- package Hacker::Perl::Another::Just;print [EMAIL PROTECTED] split/::/ =__PACKAGE__]}~; # André Malo # http://pub.perlig.de # -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows and python execution
What I was trying to do was execute a python script without having to type the word python explicitly. For that, you need the set command that I listed in a previous post. I'm not confused and I like to keep my scripts in oddball places too. Namely d:\python. All I'm saying is I don't use the set command. I don't have an autoexec.bat file. I simply place d:\python in the path variable and I can execute python scripts from the command line from any directory without typing python first. I just type myscript.py and it executes. Okay. You're welcome. rpd -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
You guys are pretty agressive! -- http://mail.python.org/mailman/listinfo/python-list
PyArg_ParseTuple exception catching
Hi, I'm getting an error when using PyArg_ParseTuple and I don't know why...In the documentation I've read that PyArg_ParseTuple raise an appropriate exception : on failure, it returns false and raises the appropriate exception. How can I get the exception in C ? because I've checked the arguments before calling the C python function and I don't know why I've got a problem when parsing the arguments list... Happy new year, PICA Frédéric -- http://mail.python.org/mailman/listinfo/python-list
Re: Beautiful Python
On 2005-12-26 05:01:07 -0500, Gekitsuu [EMAIL PROTECTED] said: I've been reading a lot of python modules lately to see how they work and I've stumbled across something that's sort of annoying and wanted to find out of there was a good reason behind it. In a Perl program when you're calling other modules you'll add use statements at the beginning of your script like: use strict; use WWW::Mechanize; use CGI; This seems to be the de facto standard in the Perl community but in python it seems most of the code I look at has import statements everywhere in the code. Is there a sound reason for putting the imports there are are developers just loading modules in as they need them. I own Damian Conway's book of Perl Best Practices and it seems from a maintainability standpoint that having all the modules declared at the beginning would make it easier for someone coming behind you to see what other modules they need to use yours. Being new I didn't know if there was a performance reason for doing this or it is simply a common habit of developers. There is a crucial difference between Perl's 'use' and Python's 'import' -- when they are executed. Glossing over some details, in Perl, a 'use' is evaulated when a .pl or .pm file is parsed, whereas in Python import is executed when the statement is encountered in normal program flow. One result of this is that, in Perl, this does not do what you expect: if ($some_condition) { use SomeWierdModule; } What happens is that at parse time, SomeWierdModule is loaded, ignoring completely the if statement. This, however, works fine in Python: if some_condition: import some_weird_module In this case, some_weird_module will only be imported if some_condition holds true when program flow hits the conditional. The net result is that in Perl, putting use statements all over the code has no real effect, because they all get evaluated at parse time -- you may as well toss them prettily at the top. In Python, though, there are occasional times where you *do* want to conditionally load a module, so it occasionally makes sense to put them in other places. Short of situations like the conditional importing above, though, I would be highly suspicious of code that gratuitously tosses imports in odd places; the namespace is global, after all; may as well be explicit upfront. You can really see this in action with the following: perl EOF if (0) { use SomeWeirdModule; } EOF vs python EOF if 0: import some_weird_module; EOF The perl snippet explodes on an invalid module, whereas the python behaves just fine. HTH, Chip -- Chip Turner [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: PyArg_ParseTuple exception catching
[EMAIL PROTECTED] wrote: I'm getting an error when using PyArg_ParseTuple and I don't know why...In the documentation I've read that PyArg_ParseTuple raise an appropriate exception : on failure, it returns false and raises the appropriate exception. How can I get the exception in C ? because I've checked the arguments before calling the C python function and I don't know why I've got a problem when parsing the arguments list... the easiest way to see the exception is to return NULL, and let Python take care of the rest. if (!PyArg_ParseTuple(...)): return NULL; /F -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
omg, how do you guys do it? after 4 hours, i'm stucked at 182 chars, 8 lines. hint please... :D André Malo wrote: * Tim Hochberg wrote: Currently, I'm down to 137 characters now in 6 lines. There's very little left to trim at this point, so I don't know that I'll be able to knock it down any further using my current approach. And since I don't have any other approaches in the wings, I may be about washed up. grmpf. Just reached 143 chars / 2 lines ;-) There seems to be some more room for optimization... nd -- http://mail.python.org/mailman/listinfo/python-list
Re: deal or no deal
[snip] What I would really like to know, is how they calculate the offer. Obviously, they set the upper limit at the average of the still standing offers, but I wonder if and how they take subsequent rounds into consideration. Is there a Monty Hall (http://en.wikipedia.org/wiki/Monty_Hall_problem) type consideration that needs to be taken into effect as cases are eliminated? I believe not; the Monty Hall problem is biased by the fact that the presenter knows where the prize is, and eliminates one box accordingly. Where boxes are eliminated at random, it's impossible for any given box to have a higher probability of containing any given amount of money than another. And for the contestants box to be worth more or less than the mean, it must have a higher probability of containing a certain amount. Like another member of the group, I've seen them offer more than the average on the UK version, which puzzled me quite a lot. James M -- http://mail.python.org/mailman/listinfo/python-list
Hypergeometric distribution
Hi to all, I need to calculate the hpergeometric distribution: choose(r, x) * choose(b, n-x) p(x; r,b,n) = - choose(r+b, n) choose(r,x) is the binomial coefficient I use the factorial to calculate the above formula but since I am using large numbers, the result of choose(a,b) (ie: the binomial coefficient) is too big even for large int. I've tried the scipy library, but this library calculates the hypergeometric using the factorials too, so the problem subsist. Is there any other libray or an algorithm to calculate the hypergeometric distribution? The statistical package R can handle such calculations but I don't want to use python R binding since I want a standalone app. Thanks a lot Ale -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
Peter Otten wrote: Simon Hengel wrote: Is it necessary to keep the input parameter as 'input'? Reducing that to a single character drops the length of a program by at least 8 characters. Technically it changes the interface of the function, so it's a little bogus, but test.py doesn't check. (Personally I prefer that if be illegal, but if it's legal I'll have to do it). You may change input to something more short, like x. Everything that passes the test, has a good chance to be accepted. How good is good for import test_vectors seven_seg = test_vectors.test_vectors.get or code using the test suite in general? Peter This started to remind myself about the story of the contest where the shortest program beeing able to output own source was the job to code. The jury had a big trouble to justify why not give the prize to the one who posted an empty file ... I am currently at 39 bytes following the requirements and the principle given above (my module passes the test). Anyone able to beat that? Claudio -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
Claudio Grondi wrote: Peter Otten wrote: [SNIP] How good is good for import test_vectors seven_seg = test_vectors.test_vectors.get or code using the test suite in general? Peter This started to remind myself about the story of the contest where the shortest program beeing able to output own source was the job to code. The jury had a big trouble to justify why not give the prize to the one who posted an empty file ... I am currently at 39 bytes following the requirements and the principle given above (my module passes the test). Anyone able to beat that? Wow! It'll be interesting to see how to do that. The obvious way gives 53 bytes. Hmmm, I'll have to see what can be done... However they do say We use a very *similar* test suite to either accept or reject pending submissions. (Emphasis mine) So, it's possible, even probable, that the file test.py either won't be available or won't be helpful. -tim -- http://mail.python.org/mailman/listinfo/python-list
PIL and ImageMagick scalability
Hi everyone! I have a question about image processing. We have a website which will process a lot of images a day.It will be running Apache(worker) with mod_python. My question is what should we use for processing. If we use PIL the processing will be done with the same process that handles other requests and that will probably slow them down when there will be a peak. If we use ImageMagick you create new process that does the image processing which probably uses multiple CPUs better and is more scalable, right? Thanks, Sebastjan -- http://mail.python.org/mailman/listinfo/python-list
Re: Beautiful Python
Gekitsuu wrote: I've been reading a lot of python modules lately to see how they work and I've stumbled across something that's sort of annoying and wanted to find out of there was a good reason behind it. In a Perl program when you're calling other modules you'll add use statements at the beginning of your script like: use strict; use WWW::Mechanize; use CGI; This seems to be the de facto standard in the Perl community but in python it seems most of the code I look at has import statements everywhere in the code. Is there a sound reason for putting the imports there are are developers just loading modules in as they need them. I own Damian Conway's book of Perl Best Practices and it seems from a maintainability standpoint that having all the modules declared at the beginning would make it easier for someone coming behind you to see what other modules they need to use yours. Being new I didn't know if there was a performance reason for doing this or it is simply a common habit of developers. Without taking anything away from other posts responding to your question, the first response perhaps should have been: Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants. Which is the official Python style guide, PEP 0008, at http://www.python.org/peps/pep-0008.html and basically a reflection of Guido's own recommendations. There are reasons to break almost any rule sometimes(*), but I think you were asking whether there IS a rule -- which is an insightful, worthy question if you've been looking at code which begs it. -Bill (*) PEP 0008 itself says, even before it lays out any rules, know when to be inconsistent. -- http://mail.python.org/mailman/listinfo/python-list
Re: Hypergeometric distribution
Raven wrote: Hi to all, I need to calculate the hpergeometric distribution: choose(r, x) * choose(b, n-x) p(x; r,b,n) = - choose(r+b, n) choose(r,x) is the binomial coefficient I use the factorial to calculate the above formula but since I am using large numbers, the result of choose(a,b) (ie: the binomial coefficient) is too big even for large int. I've tried the scipy library, but this library calculates the hypergeometric using the factorials too, so the problem subsist. Is there any other libray or an algorithm to calculate the hypergeometric distribution? Use logarithms. Specifically, from scipy import special def logchoose(n, k): lgn1 = special.gammaln(n+1) lgk1 = special.gammaln(k+1) lgnk1 = special.gammaln(n-k+1) return lgn1 - (lgnk1 + lgk1) def gauss_hypergeom(x, r, b, n): return exp(logchoose(r, x) + logchoose(b, n-x) - logchoose(r+b, n)) Or you could use gmpy if you need exact rational arithmetic rather than floating point. -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: build curiosities of svn head (on WinXP)
Tim Peters schrieb: [David Murmann] ... second, the build order in pcbuild.sln for elementtree seems to be wrong, nant tried to build elementtree before pythoncore (which failed). i fixed this by building elementtree separately. [Steve Holden] Yes, the elementtree module is a new arrival for 3.5, so the build may not yet be perfectly specified. This is useful information. I just checked in a fix for that. Thanks! this works for me, thanks for the quick patch! ... and i could reproduce the expected failure (ATM) of the regression test suite: http://mail.python.org/pipermail/python-dev/2005-December/059033.html Note that all tests pass on Windows as of Sunday (in release and debug builds, with and without -O). here i have problems. some tests fail more or less randomly. after some testing, i found that it seems to be related to the parsing of float literals in python code (wild guess). for example, test_pow failed giving me this traceback: Traceback (most recent call last): File D:\develop\cygwin\usr\local\src\python\python\trunk\lib\test\test_pow.py , line 109, in test_bug705231 eq(pow(a, 1.23e167), 1.0) AssertionError: -1.0 != 1.0 this seems very strange to me, as i get this on the interactive prompt: pow(-1.0, 1.23e167) 1.0 another example is test_colorsys. this test hangs, because it uses frange(0.0, 1.0, 0.2) (which does, what it looks like), but the 0.2 is somehow read as 0.0 resulting in an infinite loop. i have no clue whether these failures are related to my build environment or something in the python codebase (or the weather?). all tests passed when building with gcc from cygwin btw. i will try building 2.4.2 with nant later and see what that does... i am lost at the moment, David. PS: maybe i should note: i built python without _bsddb and without _tcl but i don't think this should be causing problems. -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
Tim Hochberg wrote: [EMAIL PROTECTED] wrote: Currently I'm on 149 characters in urgh one line - 128 without spaces/newlines. (it'd be three characters shorter if it didn't have to end with a \n) It'll be interesting to see what the short 1-line answers look like. I have a hard time seeing how that's done. It'll especially be interesting to see if we're all using similar tricks or if the multiline attemps take a distinctly different tack than the single line attempts. Currently, I'm down to 137 characters now in 6 lines. There's very little left to trim at this point, so I don't know that I'll be able to knock it down any further using my current approach. And since I don't have any other approaches in the wings, I may be about washed up. I think my main interest will be to see what different algorithms are successful. I suspect I may have chosen the wrong approach to start with since I stuck at 150 characters (1 line, no extraneous whitespace), but then I started again with a different algorithm and I'm down to one line of 137 characters but nowhere obvious to go from there... -- http://mail.python.org/mailman/listinfo/python-list
Re: deal or no deal
On 2005-12-26 15:05:21 -0500, [EMAIL PROTECTED] said: I believe not; the Monty Hall problem is biased by the fact that the presenter knows where the prize is, and eliminates one box accordingly. Where boxes are eliminated at random, it's impossible for any given box to have a higher probability of containing any given amount of money than another. And for the contestants box to be worth more or less than the mean, it must have a higher probability of containing a certain amount. Agreed -- unless the presenter takes away a case based on knowledge he has about the contents, then Monty Hall doesn't enter into it. Deal or No Deal seems to be a purely chance based game. However, that doesn't mean there aren't strategies beyond strictly expecting the average payout. Like another member of the group, I've seen them offer more than the average on the UK version, which puzzled me quite a lot. I imagine it is about risks. Many gameshows take out insurance policies against the larger payoffs to protect the show and network from big winners. I believe Who Wants to be a Millionaire actually had some difficulty with their insurance when they were paying out too often, or something. Perhaps the UK Deal or No Deal didn't want to risk increasing their premium :) But even the contestant has a reason to not just play the average, thereby bringing psychology into the game. It comes down to the odd phenomenon that the value of money isn't linear to the amount of money in question. If you're playing the game, and only two briefcases are left -- 1,000,000 and 0.01, and the house offers you 400,000... take it! On average you'll win around 500,000, but half the time, you'll get a penny. Averages break down when you try to apply them to a single instance. On the flip side, if you think about how much difference 500,000 will make in your life vs, say, 750,000, then taking a risk to get 750,000 is probably worth it; sure, you might lose 250,000 but on top of 500,000, the impact of the loss you would suffer is significantly lessened. In the end, it comes down to what the money on the table means to *you* and how willing you are to lose the guaranteed amount to take risks. It's similar to the old game of coin flipping to double your money. Put a dollar on the table. Flip a coin. Heads, you double your bet, tails you lose it all. You can stop any time you want. The expected outcome is infinite money (1 * 1/2 + 2 * 1/4 + 4 * 1/8 ...), but a human playing it would do well to stop before the inevitable tails comes along, even though mathematically the house pays out an expected infinite number of dollars over time. Exponential growth in winnings doesn't offset exponential risk in taking a loss because, once you hit a certain point, the money on the table is worth more than the 50% chance of having twice as much. Chip -- Chip Turner [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows and python execution
On Mon, 26 Dec 2005 14:53:28 +, Mark Carter [EMAIL PROTECTED] wrote: rzed wrote: Mark Carter [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: What I would like to do it type something like myscript.py instead of python myscript.py As another poster points out, be sure that your Python is on your path. And there is a PATHEXT environment variable, Aha. You'bve provided a significant clue. What you need to do is include the following line in autoexec.bat: set .py=c:\python24\python.exe This will achieve the desired result. I'm suprised more people don't use it. I wasn't aware of that syntax for set. What OS/platform/shell is that from? How did you go from the PATHEXT clue to the set command you specify and decide not to set pathext, e.g., by something like set PATHEXT=%PATHEXT%;.py Does your set do the pathext and assoc and ftype all in one swell foop? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: Hypergeometric distribution
Raven wrote: Hi to all, I need to calculate the hpergeometric distribution: choose(r, x) * choose(b, n-x) p(x; r,b,n) = - choose(r+b, n) choose(r,x) is the binomial coefficient I use the factorial to calculate the above formula but since I am using large numbers, the result of choose(a,b) (ie: the binomial coefficient) is too big even for large int. I've tried the scipy library, but this library calculates the hypergeometric using the factorials too, so the problem subsist. Is there any other libray or an algorithm to calculate the hypergeometric distribution? The statistical package R can handle such calculations but I don't want to use python R binding since I want a standalone app. Thanks a lot Ale Ale I had this code lying about if it helps. I don't know if it's even correct but it's non-recursive! def Binomial( n, k ): ret = 0 if k == 0: ret = 1 elif k 0: a = range( n+1 ) a[0] = 1 for i in a[1:]: a[i] = 1 for j in range(i-1,0,-1): a[j] = a[j] + a[j-1] ret = a[k] return ret Gerard -- http://mail.python.org/mailman/listinfo/python-list
help with lists and writing to file in correct order
hey folks, have a logic question for you. appreciate the help in advance. i am scraping 3 pieces of information from the html namely the food name , store name and price. and i am doing this for many different food items found ni the html including pizza, burgers, fries etc. what i want is to write out to a text file in the following order: pizza, pizza hut, 3.00 burgers, burger king, 4.00 noodles, panda inn, 2.00 html is below. does anyone have good recommendation for how to setup the code in such a manner where it writes to the text file in th order listed previously? any attempt i have made seems to write to the file like this noodles, panda inn, 3 noodles, panda inn, 4 noodles, panda inn, 2 HTML tr class=basetd class=talla name=D0L1 href=his/food target=_blank td class=desch2 id=foodNamepizza/h2 div class=storea name=D0L3 href=/xPopups/nojs target=_blankbpizza hutt/b/a/div td class=price3.00/td tr -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows and python execution
Bengt Richter wrote: And there is a PATHEXT environment variable, Aha. You'bve provided a significant clue. What you need to do is include the following line in autoexec.bat: set .py=c:\python24\python.exe This will achieve the desired result. I'm suprised more people don't use it. I wasn't aware of that syntax for set. What OS/platform/shell is that from? Windows XP, bog-standard default shell. UNIXers have it easy because they can use the normal shebang. How did you go from the PATHEXT clue to the set command you specify I can't remember. It was a bit of luck, I think. I happened upon: http://www.jpsoft.com/help/index.htm?exeext.htm probably as a result of Googling for PATHEXT. and decide not to set pathext, e.g., by something like set PATHEXT=%PATHEXT%;.py Does your set do the pathext and assoc and ftype all in one swell foop? Actually, I haven't figured out what PATHEXT is actually supposed to do. It seemed to me that Windows couldn't possibly know that a py file should be started by python.exe, whereas my set .py= ... would. I had installed python 2.4 in the standard way, so py files were already associated with python when you double-clicked them from Explorer. Using my set meant that if I wanted to use py files from the command line, I could just type out the script name (you have to be in the right directory, of course), and it works. Here's a snippit from my autoexec.bat files: set PATH=C:\python24;%PATH% set .py=c:\python24\python.exe -- http://mail.python.org/mailman/listinfo/python-list
__slots__ and copy again: why does it work?
I remember from painful experience that copy.copy() won't really copy __slots__ members. But I have trouble explaning why the following code works: --- START--- #!/usr/bin/env python import copy class Foo (object): __slots__ = 'i' def __init__ (self): self.i = 10 class Bar (Foo): __slots__ = 'j' def __init__ (self): self.j = 20 f1 = Foo() f2 = copy.copy(f1) print f2.i # why does it work? b1 = Bar() b2 = copy.copy(b1) print b2.j # why does it work? print b2.i # doesn't work, as expected --- END--- Any insight is welcome! -- http://mail.python.org/mailman/listinfo/python-list
Re: __slots__ and copy again: why does it work?
I should've mentioned this was tested on Python 2.4.2. fortepianissimo wrote: I remember from painful experience that copy.copy() won't really copy __slots__ members. But I have trouble explaning why the following code works: --- START--- #!/usr/bin/env python import copy class Foo (object): __slots__ = 'i' def __init__ (self): self.i = 10 class Bar (Foo): __slots__ = 'j' def __init__ (self): self.j = 20 f1 = Foo() f2 = copy.copy(f1) print f2.i # why does it work? b1 = Bar() b2 = copy.copy(b1) print b2.j # why does it work? print b2.i # doesn't work, as expected --- END--- Any insight is welcome! -- http://mail.python.org/mailman/listinfo/python-list
Re: build curiosities of svn head (on WinXP)
David Murmann wrote: here i have problems. some tests fail more or less randomly. after some testing, i found that it seems to be related to the parsing of float literals in python code (wild guess). for example, test_pow failed giving me this traceback: Traceback (most recent call last): File D:\develop\cygwin\usr\local\src\python\python\trunk\lib\test\test_pow.py , line 109, in test_bug705231 eq(pow(a, 1.23e167), 1.0) AssertionError: -1.0 != 1.0 this seems very strange to me, as i get this on the interactive prompt: pow(-1.0, 1.23e167) 1.0 sounds like some odd locale problem. consider pow(-1.0, 1) -1.0 another example is test_colorsys. this test hangs, because it uses frange(0.0, 1.0, 0.2) (which does, what it looks like), but the 0.2 is somehow read as 0.0 resulting in an infinite loop. and frange(0, 1, 0) try setting the locale (via the locale module) from the interactive prompt, and see if Python still handles floating point values correctly. /F -- http://mail.python.org/mailman/listinfo/python-list
closing stdin, stdout and stderr
I am writing a unix daemon in python, so I want to close stdin, stdout and stderr. My first attempt was to the standard file descriptors using their close() methods. After closing stdout, I could not print anymore, so this seemed to work. However, later I noticed that they were not really closed. When I close them using os.close(), it did work. What is the difference between these two methods and what is the reason behind it? It took me a day to find out why I could not log out after starting the daemon. Martijn -- http://mail.python.org/mailman/listinfo/python-list
Re: closing stdin, stdout and stderr
Martijn Brouwer wrote: I am writing a unix daemon in python, so I want to close stdin, stdout and stderr. My first attempt was to the standard file descriptors using their close() methods. After closing stdout, I could not print anymore, so this seemed to work. However, later I noticed that they were not really closed. When I close them using os.close(), it did work. What is the difference between these two methods and what is the reason behind it? It took me a day to find out why I could not log out after starting the daemon. Martijn I've had excellent results with variants of the cookbook entry at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731 -- Robin Becker -- http://mail.python.org/mailman/listinfo/python-list
Re: closing stdin, stdout and stderr
Robin Becker wrote: Martijn Brouwer wrote: I am writing a unix daemon in python, so I want to close stdin, stdout and stderr. My first attempt was to the standard file descriptors using their close() methods. After closing stdout, I could not print anymore, so this seemed to work. However, later I noticed that they were not really closed. When I close them using os.close(), it did work. What is the difference between these two methods and what is the reason behind it? It took me a day to find out why I could not log out after starting the daemon. Martijn I've had excellent results with variants of the cookbook entry at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731 but perhaps you're using a non unix OS, which will make that recipe wrong. -- Robin Becker -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows and python execution
Mark Carter [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: Bengt Richter wrote: And there is a PATHEXT environment variable, Aha. You'bve provided a significant clue. What you need to do is include the following line in autoexec.bat: set .py=c:\python24\python.exe This will achieve the desired result. I'm suprised more people don't use it. I wasn't aware of that syntax for set. What OS/platform/shell is that from? Windows XP, bog-standard default shell. UNIXers have it easy because they can use the normal shebang. How did you go from the PATHEXT clue to the set command you specify I can't remember. It was a bit of luck, I think. I happened upon: http://www.jpsoft.com/help/index.htm?exeext.htm probably as a result of Googling for PATHEXT. and decide not to set pathext, e.g., by something like set PATHEXT=%PATHEXT%;.py Does your set do the pathext and assoc and ftype all in one swell foop? Actually, I haven't figured out what PATHEXT is actually supposed to do. It seemed to me that Windows couldn't possibly know that a py file should be started by python.exe, whereas my set .py= ... would. I had installed python 2.4 in the standard way, so py files were already associated with python when you double-clicked them from Explorer. Using my set meant that if I wanted to use py files from the command line, I could just type out the script name (you have to be in the right directory, of course), and it works. Here's a snippit from my autoexec.bat files: set PATH=C:\python24;%PATH% set .py=c:\python24\python.exe I should have asked which Windows version you had. My bad. On Win2k or XP, adding .py (for instance) to the PATHEXT variable means that you can execute myNeatProgram.py with this command-line: promptmyNeatProgram Since .py appears in the PATHEXT variable, the system knows that .py files are executable, so it's not necessary even to specify them. What must happen, I suppose, is that the system looks for myNeatProgram.bat, myNeatProgram.com, myNeatProgram.exe, etc., until it hits upon myNeatProgram.py and proceeds to run it. So if you have a myNeatProgram.bat that appears earlier in your path than myNeatProgram.py does, the bat file is what gets run. -- rzed -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows and python execution
rzed wrote: I should have asked which Windows version you had. XP Pro My bad. On Win2k or XP, adding .py (for instance) to the PATHEXT variable means that you can execute myNeatProgram.py with this command-line: promptmyNeatProgram Oh, now I see! It's beginning to make sense to me. I'll have to try that out. Thanks for the tip. -- http://mail.python.org/mailman/listinfo/python-list
XPath-like filtering for ElementTree
Pseudo-XPath support for ElementTree with the emphasis on 'Pseudo'. http://gflanagan.net/site/python/pagliacci/ElementFilter.html It's an approach suggested by the Specification Pattern eg. http://www.martinfowler.com/apsupp/spec.pdf Not tested beyond what follows (no time for more at the minute). Criticisms and suggestions are welcome. (one possibly obvious 'feature' is that '[EMAIL PROTECTED]'[EMAIL PROTECTED]']' won't work, ie. if the name of an attribute is contained within a query string, and is preceded by an '@' character) Gerard xml_test =''' mail:Mail xmlns:mail=xmlns1 mail:Date10/10/05/mail:Date mail:From address='[EMAIL PROTECTED]' name='Mr. Jones'/ mail:Subjectjust a note/mail:Subject mail:To mail:mailto address='[EMAIL PROTECTED]' name='Mrs Jones' test='3' / mail:mailto address='[EMAIL PROTECTED]' name='Mr Smith' test='1'/ /mail:To mail:To mail:mailto address='[EMAIL PROTECTED]' name='Mrs Jones' test='2'/ /mail:To mail:Cc/mail:Cc mail:Bodyhi there, just a note to say hi there!/mail:Body mail:Attachments/mail:Attachments /mail:Mail ''' if __name__ == '__main__': print '##' from elementtree import ElementTree from elementtree.ElementTree import dump root = ElementTree.fromstring( xml_test ) ns = xmlns1 path = r{%s}To/[EMAIL PROTECTED]'Mrs Jones' and @test==3] % (ns,ns) filter = ElementFilter(path) print filter.path nodeset1 = filter.findall( root ) for node in nodeset1: dump(node) print '-'*30 filter.path = r{%s}To/[EMAIL PROTECTED]3] % (ns,ns) print filter.path nodeset2 = filter.findall( root ) for node in nodeset2: dump(node) print '-'*30 assert nodeset1 != nodeset2 assert filter.findall( root ) != [] filter.removeall( root ) assert filter.findall( root ) == [] dump(root) -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
Tim Hochberg wrote: Claudio Grondi wrote: Peter Otten wrote: [SNIP] How good is good for import test_vectors seven_seg = test_vectors.test_vectors.get or code using the test suite in general? Peter This started to remind myself about the story of the contest where the shortest program beeing able to output own source was the job to code. The jury had a big trouble to justify why not give the prize to the one who posted an empty file ... I am currently at 39 bytes following the requirements and the principle given above (my module passes the test). Anyone able to beat that? Wow! It'll be interesting to see how to do that. The obvious way gives 53 bytes. Hmmm, I'll have to see what can be done... However they do say We use a very *similar* test suite to either accept or reject pending submissions. (Emphasis mine) So, it's possible, even probable, that the file test.py either won't be available or won't be helpful. -tim Wouldn't using test_vectors.py somehow be lame? -- http://mail.python.org/mailman/listinfo/python-list
Re: Indentation/whitespace
On 26 Dec 2005 04:10:11 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: i think you can't call an editor python capable unless it shows you clearly hard (yuck)or soft tabs like View / Show Invisibles in textmate, View / view whitespace in komodo. Zeus for Windows has this View / View whitespace feature: I personally don't care to see it, I'd rather it just did the soft - hard conversion for me so I don't have to worry about it. Thats assuming hard tabs is defined as actual spaces rather then a tab character. If I'm getting those mixed up, switch 'em around or whatever. I find true tabs to be very annoying since different editors/programs seem to translate them differently, just give me spaces :P. Their are plenty of freeware and proprietary programs that do both and everything in between, don't feel like you have to be pushed into buying something. -- James Tanis [EMAIL PROTECTED] http://pycoder.org -- http://mail.python.org/mailman/listinfo/python-list
Re: closing stdin, stdout and stderr
On Mon, 2005-12-26 at 23:13 +, Robin Becker wrote: Martijn Brouwer wrote: I am writing a unix daemon in python, so I want to close stdin, stdout and stderr. My first attempt was to the standard file descriptors using their close() methods. After closing stdout, I could not print anymore, so this seemed to work. However, later I noticed that they were not really closed. When I close them using os.close(), it did work. What is the difference between these two methods and what is the reason behind it? It took me a day to find out why I could not log out after starting the daemon. Martijn I've had excellent results with variants of the cookbook entry at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731 I read this one, which was the reason that I tried os.close instead of sys.stdXXX.close(). But I would like to know why it does not close a file discriptor is I call its close method(). Martijn -- Martijn Brouwer [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: closing stdin, stdout and stderr
On Mon, 2005-12-26 at 23:15 +, Robin Becker wrote: Robin Becker wrote: Martijn Brouwer wrote: I am writing a unix daemon in python, so I want to close stdin, stdout and stderr. My first attempt was to the standard file descriptors using their close() methods. After closing stdout, I could not print anymore, so this seemed to work. However, later I noticed that they were not really closed. When I close them using os.close(), it did work. What is the difference between these two methods and what is the reason behind it? It took me a day to find out why I could not log out after starting the daemon. Martijn I've had excellent results with variants of the cookbook entry at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731 but perhaps you're using a non unix OS, which will make that recipe wrong. Well, I am writing a unix daemon ;) Martijn -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
On Mon, 26 Dec 2005 13:33:42 -0700, Tim Hochberg wrote: Claudio Grondi wrote: I am currently at 39 bytes following the requirements and the principle given above (my module passes the test). Anyone able to beat that? Wow! It'll be interesting to see how to do that. The obvious way gives 53 bytes. Hmmm, I'll have to see what can be done... OBVIOUS??? The only algorithm obvious to me came to two lines and about 300 characters with all the pruning I could come up with. Changing algorithms made it longer. I am finding it hard enough to credit that half a dozen people are claiming lengths of around 130-180 characters -- 39 or 53 bytes just seems physically impossible to me, especially given that nine of those bytes are the name of the function! The identity function seven_seg=lambda s:s takes 20 bytes and does nothing. That leaves NINETEEN bytes to implement the functionality. In the immortal words of Bill and Ted: No way dude! You excellent dudes are righteously bodacious! -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Beautiful Python
[EMAIL PROTECTED] wrote: Gekitsuu wrote: I've been reading a lot of python modules lately to see how they work and I've stumbled across something that's sort of annoying and wanted to find out of there was a good reason behind it. In a Perl program when you're calling other modules you'll add use statements at the beginning of your script like: use strict; use WWW::Mechanize; use CGI; This seems to be the de facto standard in the Perl community but in python it seems most of the code I look at has import statements everywhere in the code. Is there a sound reason for putting the imports there are are developers just loading modules in as they need them. I own Damian Conway's book of Perl Best Practices and it seems from a maintainability standpoint that having all the modules declared at the beginning would make it easier for someone coming behind you to see what other modules they need to use yours. Being new I didn't know if there was a performance reason for doing this or it is simply a common habit of developers. Without taking anything away from other posts responding to your question, the first response perhaps should have been: Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants. Which is the official Python style guide, PEP 0008, at http://www.python.org/peps/pep-0008.html and basically a reflection of Guido's own recommendations. I've always done it this way (import at the top in alphabetical order with standard modules before add-in modules). The one exception is that at times I use imports to make sure that certain modules are indeed installed. For example, when I must have win32 modules I import like this: import os import sys import time try: import win32api except ImportError: print The win32 extensions must be installed! sys.exit() There are reasons to break almost any rule sometimes(*), but I think you were asking whether there IS a rule -- which is an insightful, worthy question if you've been looking at code which begs it. -Bill (*) PEP 0008 itself says, even before it lays out any rules, know when to be inconsistent. -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
Steven D'Aprano wrote: On Mon, 26 Dec 2005 13:33:42 -0700, Tim Hochberg wrote: Claudio Grondi wrote: I am currently at 39 bytes following the requirements and the principle given above (my module passes the test). Anyone able to beat that? Wow! It'll be interesting to see how to do that. The obvious way gives 53 bytes. Hmmm, I'll have to see what can be done... OBVIOUS??? The obvious way seems to be to import the test_vectors.py file, which gives me import test_vectors as x;seven_seg=x.test_vectors.get as one possible obvious solution with 53 chars. But from test_vectors import*;seven_seg=test_vectors.get has only 52. And if you observe that their test.py file already does all the imports we want, you can get to from test import*;seven_seg=test_vectors.get with 44 chars. But I simply cant see how to get below that. And I think this is not the wanted solution at all, which is why I have no problem posting it here :-) ciao - chris -- Christian Tismer :^) mailto:[EMAIL PROTECTED] tismerysoft GmbH : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9A :*Starship* http://starship.python.net/ 14109 Berlin : PGP key - http://wwwkeys.pgp.net/ work +49 30 802 86 56 mobile +49 173 24 18 776 fax +49 30 80 90 57 05 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
Steven D'Aprano wrote: On Mon, 26 Dec 2005 13:33:42 -0700, Tim Hochberg wrote: Claudio Grondi wrote: I am currently at 39 bytes following the requirements and the principle given above (my module passes the test). Anyone able to beat that? Wow! It'll be interesting to see how to do that. The obvious way gives 53 bytes. Hmmm, I'll have to see what can be done... OBVIOUS??? Your misinterpreting me here. I meant the obvious way to cheat as Claudio describes above. I don't actually think that kind of cheating will work, since it relies on test_vectors.py being present and it assumes that the test vectors used for checking the program are the same as those in test_vectors.py. The documentation suggests that the later at least is not likely. I still haven't figured out how he manages to get his cheating one so short though, the smallest I can get is 43 characters and it looks like this: import test;seven_seg=test.test_vectors.get This works if you run test. It fails if you try to run it standalone since the import order is wrong. The only algorithm obvious to me came to two lines and about 300 characters with all the pruning I could come up with. Changing algorithms made it longer. I am finding it hard enough to credit that half a dozen people are claiming lengths of around 130-180 characters -- 39 or 53 bytes just seems physically impossible to me, especially given that nine of those bytes are the name of the function! In the 130's is definately possible, but I haven't heard of anyone doing better than that. The identity function seven_seg=lambda s:s takes 20 bytes and does nothing. That leaves NINETEEN bytes to implement the functionality. In the immortal words of Bill and Ted: No way dude! You excellent dudes are righteously bodacious! Nah. -tim -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
Tim Hochberg wrote: import test;seven_seg=test.test_vectors.get Oupps, good (being blinded after all the other from imports and __import__(...) ) -- Christian Tismer :^) mailto:[EMAIL PROTECTED] tismerysoft GmbH : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9A :*Starship* http://starship.python.net/ 14109 Berlin : PGP key - http://wwwkeys.pgp.net/ work +49 30 802 86 56 mobile +49 173 24 18 776 fax +49 30 80 90 57 05 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
Tim Hochberg wrote: [CHOP] import test;seven_seg=test.test_vectors.get This works if you run test. It fails if you try to run it standalone since the import order is wrong. [CHOP] Or maybe not. An earlier version did, but this one seems OK. -tim -- http://mail.python.org/mailman/listinfo/python-list
Re: Hypergeometric distribution
On Mon, 26 Dec 2005 12:18:55 -0800, Raven wrote: Hi to all, I need to calculate the hpergeometric distribution: choose(r, x) * choose(b, n-x) p(x; r,b,n) = - choose(r+b, n) choose(r,x) is the binomial coefficient I use the factorial to calculate the above formula but since I am using large numbers, the result of choose(a,b) (ie: the binomial coefficient) is too big even for large int. Are you sure about that? Python long ints can be as big as you have enough memory for. My Python can print 10L**1 to the console with a barely detectable pause, and 10L**10 with about a ten second delay. (Most of that delay is printing it, not calculating it.) 25206 is the first integer whose factorial exceeds 10L**10, so even if you are calculating the binomial coefficient using the most naive algorithm, calculating the factorials and dividing, you should easily be able to generate it for a,b up to 20,000 unless you have a severe shortage of memory. I've tried the scipy library, but this library calculates the hypergeometric using the factorials too, so the problem subsist. What exactly is your problem? What values of hypergeometric(x; r,b,n) fail for you? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: help with lists and writing to file in correct order
On Mon, 26 Dec 2005 13:54:37 -0800, homepricemaps wrote: hey folks, have a logic question for you. appreciate the help in advance. i am scraping 3 pieces of information from the html namely the food name , store name and price. and i am doing this for many different food items found ni the html including pizza, burgers, fries etc. what i want is to write out to a text file in the following order: pizza, pizza hut, 3.00 burgers, burger king, 4.00 noodles, panda inn, 2.00 html is below. does anyone have good recommendation for how to setup the code in such a manner where it writes to the text file in th order listed previously? any attempt i have made seems to write to the file like this noodles, panda inn, 3 noodles, panda inn, 4 noodles, panda inn, 2 Instead of posting the HTML, how about if you post your code? Unless we see your code, how do you expect us to find the bug in it? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: help with lists and writing to file in correct order
sorry guys, here is the code for incident in bs('a', {'class' : 'price'}): price = for oText in incident.fetchText( oRE): price += oText.strip() + ',' for incident in bs('div', {'class' : 'store'}): store = for oText in incident.fetchText( oRE): store += oText.strip() + ',' for incident in bs('h2', {'id' : 'food'}): food = for oText in incident.fetchText( oRE): food += oText.strip() + ',' -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
Tim Hochberg wrote: In the 130's is definately possible, but I haven't heard of anyone doing better than that. I have a version that is 127, but only if you strip extra whitespace :-( -- - Justin -- http://mail.python.org/mailman/listinfo/python-list
Re: help with lists and writing to file in correct order
On Mon, 26 Dec 2005 17:44:43 -0800, homepricemaps wrote: sorry guys, here is the code for incident in bs('a', {'class' : 'price'}): price = for oText in incident.fetchText( oRE): price += oText.strip() + ',' for incident in bs('div', {'class' : 'store'}): store = for oText in incident.fetchText( oRE): store += oText.strip() + ',' for incident in bs('h2', {'id' : 'food'}): food = for oText in incident.fetchText( oRE): food += oText.strip() + ',' This is hardly all your code -- where is the part where you actually *write* something to the file? The problem is you are writing the same store and food to the file over and over again. After you have collected one line of store/food, you must write it to the file immediately, or at least save it in a list so you can write the lot at the end. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
Tim Hochberg wrote: I am currently at 39 bytes following the requirements and the principle given above (my module passes the test). Anyone able to beat that? Wow! It'll be interesting to see how to do that. The obvious way gives 53 bytes. Hmmm, I'll have to see what can be done... 39 bytes... 53 bytes... It gives me the impression to follow a jet plane with a bike with my 179 bytes! There isn't a single superfluous byte. My code is so compressed that the syntactic colorizer can't cope any more. I definitively need a new algorythm. g -- == Remi Villatel [EMAIL PROTECTED] == -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
Remi Villatel wrote: 39 bytes... 53 bytes... It gives me the impression to follow a jet plane with a bike with my 179 bytes! There isn't a single superfluous byte. My code is so compressed that the syntactic colorizer can't cope any more. I definitively need a new algorythm. g You need a more careful reading algorithm. We were talking about cheating by imports :-) -- Christian Tismer :^) mailto:[EMAIL PROTECTED] tismerysoft GmbH : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9A :*Starship* http://starship.python.net/ 14109 Berlin : PGP key - http://wwwkeys.pgp.net/ work +49 30 802 86 56 mobile +49 173 24 18 776 fax +49 30 80 90 57 05 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ -- http://mail.python.org/mailman/listinfo/python-list
how-to POST form data to ASP pages?
I need to post form data to an ASP page that looks like this on the page itself... form method='POST'input src=\icons\devices\coffee-on.gif type='image' align='absmiddle' width=16 height=16 title='Off'input type='hidden' value='Image' name='Action'input type='hidden' value='hs.ExecX10ByName Kitchen Espresso Machine, Off, 100'/form I've been trying this but I get a syntax error... params = urllib.urlencode({'hidden': 'hs.ExecX10ByName Kitchen Espresso Machine, On, 100'}) urllib.urlopen(http://192.168.1.11:80/hact/kitchen.asp;, params) Can someone help out and validate I'm on the right/wrong track and help with the syntax? thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: __slots__ and copy again: why does it work?
More weird observations: the following code does not work until you change the name of the member 'longer' to a one-char name, for example, 'j': --- START --- #!/usr/bin/env python import copy class Foo (object): __slots__ = 'i' class Bar (Foo): __slots__ = 'longer' #__slots__ = 'j' b1 = Bar() b1.longer = 22 #b1.j = 22 b2 = copy.copy(b1) # doesn't work in Python 2.4.2 # BUT if 'longer' is changed to 'j' in the entire file, then it works! print b2.longer #print b2.j --- END --- I've tried different names and concluded that as long as I used one character the code works. Anything longer than one character bombs. Why? -- http://mail.python.org/mailman/listinfo/python-list
Re: help with lists and writing to file in correct order
here is the write part: out = open(test.txt, 'a') out.write (store+ food+ price + \n) out.close() Steven D'Aprano wrote: On Mon, 26 Dec 2005 17:44:43 -0800, homepricemaps wrote: sorry guys, here is the code for incident in bs('a', {'class' : 'price'}): price = for oText in incident.fetchText( oRE): price += oText.strip() + ',' for incident in bs('div', {'class' : 'store'}): store = for oText in incident.fetchText( oRE): store += oText.strip() + ',' for incident in bs('h2', {'id' : 'food'}): food = for oText in incident.fetchText( oRE): food += oText.strip() + ',' This is hardly all your code -- where is the part where you actually *write* something to the file? The problem is you are writing the same store and food to the file over and over again. After you have collected one line of store/food, you must write it to the file immediately, or at least save it in a list so you can write the lot at the end. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: XPath-like filtering for ElementTree
On 26 Dec 2005 15:42:56 -0800, Gerard Flanagan [EMAIL PROTECTED] wrote: Pseudo-XPath support for ElementTree with the emphasis on 'Pseudo'. http://gflanagan.net/site/python/pagliacci/ElementFilter.html [snip] ns = xmlns1 path = r{%s}To/[EMAIL PROTECTED]'Mrs Jones' and @test==3] % (ns,ns) How about promoting the query to a set of Python objects? eg, path = Query( ns.xmlns1.To / ns.xmlns1.mailto['name': 'Mrs Jones', 'test': '3']) That's just off the top of my head as an example of the kind of thing I mean. There is probably a better (more consistent, flexible, easier to read, etc) spelling possible. The advantages of this over strings is that you can break the query up into multiple pieces, pass parts of it around as real, live objects with introspectable APIs, allow for mutation of portions of the query, re-arrange it, etc. All this is possible with strings too, just way harder :) Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
Remi Villatel wrote: Tim Hochberg wrote: I am currently at 39 bytes following the requirements and the principle given above (my module passes the test). Anyone able to beat that? Wow! It'll be interesting to see how to do that. The obvious way gives 53 bytes. Hmmm, I'll have to see what can be done... 39 bytes... 53 bytes... It gives me the impression to follow a jet plane with a bike with my 179 bytes! There isn't a single superfluous byte. My code is so compressed that the syntactic colorizer can't cope any more. I definitively need a new algorythm. g And I am sadly stuck at 169. Not even spitting distance from 149 (which sounds like a non-cheat version). --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: build curiosities of svn head (on WinXP)
Fredrik Lundh schrieb: try setting the locale (via the locale module) from the interactive prompt, and see if Python still handles floating point values correctly. well, it does not: import locale locale.setlocale(locale.LC_ALL, '') 'German_Germany.1252' 3.141592 3.0 so this is where the problem has to be, but i am still not sure what to do about this. is this a problem with my configuration, with my build or with python? i tried changing my windows configuration to use '.' as the decimal point, after which the above worked as expected, but the test suite still fails on some tests (audioop, binop, bisect, difflib, doctest, xdrlib fail and colorsys still hangs). surely my workaround is no general solution and it doesn't even work, so there has to be a problem somewhere else. also note that some of these tests (all except difflib and doctest) pass, if i change them in any way (like adding insignificant whitespace) and run them alone. thanks for the help, David. -- http://mail.python.org/mailman/listinfo/python-list
Re: help with lists and writing to file in correct order
the problem with writing to teh file immidiately is that it ends up writing all food items together, and then all store items and then all prices i want food, store, price food, store, price -- http://mail.python.org/mailman/listinfo/python-list
Re: build curiosities of svn head (on WinXP)
David Murmann schrieb: i will try building 2.4.2 with nant later and see what that does... FYI i did this now and it worked fine, all tests passed. -- http://mail.python.org/mailman/listinfo/python-list
Re: Hypergeometric distribution
Raven [EMAIL PROTECTED] wrote: Hi to all, I need to calculate the hpergeometric distribution: choose(r, x) * choose(b, n-x) p(x; r,b,n) = - choose(r+b, n) choose(r,x) is the binomial coefficient I use the factorial to calculate the above formula but since I am using large numbers, the result of choose(a,b) (ie: the binomial coefficient) is too big even for large int. I've tried the scipy library, but this library calculates the hypergeometric using the factorials too, so the problem subsist. Is there any other libray or an algorithm to calculate the hypergeometric distribution? The statistical package R can handle such calculations but I don't want to use python R binding since I want a standalone app. Have you tried with gmpy? Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: help with lists and writing to file in correct order
[EMAIL PROTECTED] wrote: the problem with writing to teh file immidiately is that it ends up writing all food items together, and then all store items and then all prices i want food, store, price food, store, price Well, if it all fits in memory, append each to its own list, and then either finally if you can or periodically if you must: for food, store, price in zip(foods, stores, prices): do some writing. -- -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: __slots__ and copy again: why does it work?
Mystery solved - when there's only one slot I should've used __slots__ = ('i', ). Duh! So in short, __slots__ and copy.copy() work fine in Python 2.4.2. -- http://mail.python.org/mailman/listinfo/python-list
Re: __slots__ and copy again: why does it work?
26 Dec 2005 20:33:35 -0800, fortepianissimo [EMAIL PROTECTED]: Mystery solved - when there's only one slot I should've used __slots__ = ('i', ). Duh! So in short, __slots__ and copy.copy() work fine in Python 2.4.2. Hard works, but very useful :) -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit -- http://mail.python.org/mailman/listinfo/python-list
Re: __slots__ and copy again: why does it work?
To be complete, the first code snippet, when modified as follows, works fine in Python 2.4.2: --- START --- #!/usr/bin/env python import copy class Foo (object): __slots__ = ('i', ) def __init__ (self): self.i = 10 class Bar (Foo): __slots__ = ('j', ) def __init__ (self): super(Bar, self).__init__() self.j = 20 f1 = Foo() f2 = copy.copy(f1) print f2.i # works b1 = Bar() b2 = copy.copy(b1) print b2.j # works print b2.i # works --- END --- The last line didn't work last time because b2.i was never initialized. -- http://mail.python.org/mailman/listinfo/python-list
Re: help with lists and writing to file in correct order
sorry for asking such beginner questions but i tried this and nothing wrote to my text file for food, price, store in bs(food, price, store): out = open(test.txt, 'a') out.write (food + price + store) out.close() while if i write the following without the for i at least get something? out = open(test.txt, 'a') out.write (food + price + store) out.close() Scott David Daniels wrote: [EMAIL PROTECTED] wrote: the problem with writing to teh file immidiately is that it ends up writing all food items together, and then all store items and then all prices i want food, store, price food, store, price Well, if it all fits in memory, append each to its own list, and then either finally if you can or periodically if you must: for food, store, price in zip(foods, stores, prices): do some writing. -- -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: how-to POST form data to ASP pages?
livin livin@@cox.net writes: I need to post form data to an ASP page that looks like this on the page itself... form method='POST'input src=\icons\devices\coffee-on.gif type='image' align='absmiddle' width=16 height=16 title='Off'input type='hidden' value='Image' name='Action'input type='hidden' value='hs.ExecX10ByName Kitchen Espresso Machine, Off, 100'/form I've been trying this but I get a syntax error... params = urllib.urlencode({'hidden': 'hs.ExecX10ByName Kitchen Espresso Machine, On, 100'}) urllib.urlopen(http://192.168.1.11:80/hact/kitchen.asp;, params) urlencode doesn't care about the type of the input element (or that the page is ASP), just the name/value pairs. You want: params = urllib.urlencode({'Action': 'Image', ...}) The provided HTML doesn't say what the name of the second hidden input field is. It's not at all clear what should be passed to the server in this case. It looks like you tried to break a string across a line boundary, but that may be your posting software. If you did, then that's what's generating a syntax error, and a good indication that you should try reading the tutorial. mike -- Mike Meyer [EMAIL PROTECTED] http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: email package and line ending
Manlio Perillo [EMAIL PROTECTED] wrote: The problem is this code: import email.Message msg = email.Message.Message() msg[subject] = email bug msg[from] = Manlio Perillo print repr(msg.as_string()) 'subject: email bug\nfrom: Manlio Perillo\n\n' Why line ending is '\n' and not '\r\n' ? RFC 2822 says that the delimiter must(?) be '\r\n'. Because all you have there is a string. It doesn't have anything to do with RFC 2822. \n is probably the safest cross-platform way to represent a newline in a Python string. Note that smtplib, which DOES have to worry abouot RFC 2822 compliance, will replace all standalone \r and \n characters with \r\n. email.Header has a bug: this code causes an infinite recursion: from email.Header import Header h = Header('multiline header', 'iso-8859-1', maxlinelen=4) e.encode() I'm not sure I would call that a bug. I'd call that a usage error; you've asked it to accomplish something that cannot be done. However, it is true that _split has enough information to diagnose this. -- - Tim Roberts, [EMAIL PROTECTED] Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: help with lists and writing to file in correct order
[EMAIL PROTECTED] wrote: sorry for asking such beginner questions but i tried this and nothing wrote to my text file for food, price, store in bs(food, price, store): out = open(test.txt, 'a') out.write (food + price + store) out.close() while if i write the following without the for i at least get something? out = open(test.txt, 'a') out.write (food + price + store) out.close() pull the open() and close() call out of the loop. And use some other name for the variables as they are very confusing and could be error prone to. -- http://mail.python.org/mailman/listinfo/python-list
Plone Setup on Https
Hi Gays, I have setup plone , its workingon port 8080 , now i need to plone work on secure layer, ie on https, my apache is configure ssl and localhost is also working on https , but plone is not working Any ideas how to setup on https plone Madhu -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows and python execution
Mark Carter [EMAIL PROTECTED] wrote: rzed wrote: Mark Carter [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: What I would like to do it type something like myscript.py instead of python myscript.py As another poster points out, be sure that your Python is on your path. And there is a PATHEXT environment variable, Aha. You'bve provided a significant clue. What you need to do is include the following line in autoexec.bat: set .py=c:\python24\python.exe This will achieve the desired result. I'm suprised more people don't use it. They don't use it, because it doesn't do anything. I'd be interested to know where you read that. What the OP needs is this: assoc .py=Python.File ftype Python.File=c:\Apps\Python24\python.exe %1 %* assoc .pyw=Python.NoConFile ftype Python.NoConFile=c:\Apps\Python24\pythonw.exe %1 %* Substitute your own Python path. The Python .msi installer DOES do this, if you let it do its default thing. You should check whether these are already set up, by doing this: assoc .py -- - Tim Roberts, [EMAIL PROTECTED] Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
MySQLdb Python API: Unable to connect
Hi, I am using MySQL 5.0 beta and Active Python 2.4. I have the correct version of MySQLdb installed. The problem is that I can't connect to MySQL through the Active Python interactive window. Here is a sample error: c=MySQLdb.Connect(host='localhost',user='root',passwd='',db='shop',port=3306) Traceback (most recent call last): File interactive input, line 1, in ? File C:\Python24\Lib\site-packages\MySQLdb\__init__.py, line 66, in Connect return Connection(*args, **kwargs) File C:\Python24\Lib\site-packages\MySQLdb\connections.py, line 134, in __init__ super(Connection, self).__init__(*args, **kwargs2) OperationalError: (2003, Can't connect to MySQL server on 'localhost' (10061)) Please look at the penultimate line again. Here the self argument is placed second to Connection argument. So I reversed their position. But the problem persists. Here is a sample: c=MySQLdb.Connect(host='localhost',user='root',passwd='',db='shop',port=3306) Traceback (most recent call last): File interactive input, line 1, in ? File C:\Python24\Lib\site-packages\MySQLdb\__init__.py, line 66, in Connect return Connection(*args, **kwargs) File C:\Python24\Lib\site-packages\MySQLdb\connections.py, line 134, in __init__MyM super(self,Connection).__init__(*args, **kwargs2) OperationalError: (2003, Can't connect to MySQL server on 'localhost' (10061)) What is happening? Thanks in advance for any help Regards Mondal -- http://mail.python.org/mailman/listinfo/python-list
problem with libxml2dom
Hi I am using libxml2dom package for DOM support in libxml2. There are some test programs in the package when I try to run that samples it give me following error: Traceback (most recent call last): File prettyprint.py, line 7, in ? d = libxml2dom.parse(sys.argv[1]) File /usr/lib/python2.2/site-packages/libxml2dom/__init__.py, line 472, in parse return parseFile(stream_or_string, html) File /usr/lib/python2.2/site-packages/libxml2dom/__init__.py, line 484, in parseFile return Document(Node_parseFile(filename, html)) File /usr/lib/python2.2/site-packages/libxml2dom/macrolib/macrolib.py, line 431, in parseFile libxml2mod.xmlCtxtUseOptions(context, XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NONET) AttributeError: 'module' object has no attribute 'xmlCtxtUseOptions' This error comes to all that examples where libxml2dom.parse() is called. Please help me and let me know how to solve this. -- http://mail.python.org/mailman/listinfo/python-list
problems with libxml2dom
Hi, I am working with libxml2dom package for having DOM support with libxml2. There are some test examples are given along with the package but when I try to run that, it gives me following error: Traceback (most recent call last): File namespaces.py, line 23, in ? document = libxml2dom.parse(test_ns.xml) File /usr/lib/python2.2/site-packages/libxml2dom/__init__.py, line 472, in parse return parseFile(stream_or_string, html) File /usr/lib/python2.2/site-packages/libxml2dom/__init__.py, line 484, in parseFile return Document(Node_parseFile(filename, html)) File /usr/lib/python2.2/site-packages/libxml2dom/macrolib/macrolib.py, line 431, in parseFile libxml2mod.xmlCtxtUseOptions(context, XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NONET) AttributeError: 'module' object has no attribute 'xmlCtxtUseOptions' This error comes to all that examples where libxml2dom.parse() is get called. Is there something wrong with the package OR I am wrong somewhere . please let me know. -- http://mail.python.org/mailman/listinfo/python-list