From tjreedy at udel.edu Tue Jun 1 00:51:05 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 01 Jun 2010 00:51:05 -0400 Subject: Vote to Add Python Package "pubsub" to the Python Standard Library In-Reply-To: References: <6b9d2898-4166-40b4-9016-dc55dee77d00@q33g2000vbt.googlegroups.com> Message-ID: On 5/31/2010 5:37 PM, Aahz wrote: > In article<6b9d2898-4166-40b4-9016-dc55dee77d00 at q33g2000vbt.googlegroups.com>, > Tom wrote: >> >> I vote for adding the Python package "pubsub" to the Python standard >> library. It has recently been added to wxpython (replacing the old >> wx.lib.pubsub package), but it has application to non-gui programs as >> well. > > You should create a ticket on bugs.python.org But only if the author of pubsub has agreed to contribute and continue maintaining the package in the strdlib. From nagle at animats.com Tue Jun 1 01:54:52 2010 From: nagle at animats.com (John Nagle) Date: Mon, 31 May 2010 22:54:52 -0700 Subject: What timeouts are required when reading SSL certificates with Python 2.6.4? Message-ID: <4c049aca$0$1586$742ec2ed@news.sonic.net> I'm converting some M2Crypto code to use the new "ssl" module, and I'm concerned about protection against hung machines at the remote end. With M2Crypto, getting timeout to work properly required much tweaking. Here's the code. I've tried it on about fifteen domains, some of which support SSL and some which don't. So far, it hasn't hung. Is there any further protection I need? port = httplib.HTTPS_PORT sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock = ssl.wrap_socket(sk, ca_certs=certfile, cert_reqs=ssl.CERT_REQUIRED) sock.connect((domain,port)) cert = sock.getpeercert() # ... process certificate data del sock del sk Note that this doesn't send or receive any data on the SSL connection once the handshake has been completed. It's just reading the remote certificate as part of a host identity check. Then it drops the connection. John Nagle From nagle at animats.com Tue Jun 1 01:57:47 2010 From: nagle at animats.com (John Nagle) Date: Mon, 31 May 2010 22:57:47 -0700 Subject: What timeouts are required when reading SSL certificates with Python 2.6.4? In-Reply-To: <4c049aca$0$1586$742ec2ed@news.sonic.net> References: <4c049aca$0$1586$742ec2ed@news.sonic.net> Message-ID: <4c049b79$0$1586$742ec2ed@news.sonic.net> Is bug #5103 relevant here? The one about the 30-minute connection hang? http://bugs.python.org/issue5103 John Nagle John Nagle wrote: > I'm converting some M2Crypto code to use the new "ssl" module, and > I'm concerned about protection against hung machines at the remote end. > With M2Crypto, getting timeout to work properly required much tweaking. > > Here's the code. I've tried it on about fifteen domains, some of which > support SSL and some which don't. So far, it hasn't hung. Is there any > further > protection I need? > > > port = httplib.HTTPS_PORT > sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > sock = ssl.wrap_socket(sk, ca_certs=certfile, cert_reqs=ssl.CERT_REQUIRED) > sock.connect((domain,port)) > cert = sock.getpeercert() # ... process > certificate data > del sock > del sk > > > Note that this doesn't send or receive any data on the SSL connection > once the handshake has been completed. It's just reading the remote > certificate as part of a host identity check. Then it drops the > connection. > > John Nagle From electronixtar at gmail.com Tue Jun 1 02:09:43 2010 From: electronixtar at gmail.com (est) Date: Mon, 31 May 2010 23:09:43 -0700 (PDT) Subject: What's the largest python/django powered website in the world? References: <3798c49c-6350-4766-81e5-1206a77c5786@42g2000prb.googlegroups.com> Message-ID: <1eaf82c6-44b3-4e8d-9f8d-c9af8671ca96@v29g2000prb.googlegroups.com> On May 31, 8:14?am, Benjamin Kaplan wrote: > On Sun, May 30, 2010 at 4:27 PM, est wrote: > > > > I'm afraid you'll need to define what you mean by "python powered". > > > Except database, presentation layer, major business logic is done by > > python. > > > Except Google/youtube, what's next? > > -- > >http://mail.python.org/mailman/listinfo/python-list > > http://www.reddit.comhttp://github.com/reddit/reddit > > I believe they recently said that they're at 7.5 million users and 270 > million page views per month. And the repo is 71% Python with most of > the rest as Javascript. http://www.alexa.com/siteinfo/douban.com is written in quixote, python 2.6 From __peter__ at web.de Tue Jun 1 02:16:52 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 01 Jun 2010 08:16:52 +0200 Subject: problem with Descriptors References: Message-ID: Steven W. Orr wrote: > I just discovered descriptors but what I want to do isn't working right. > That's the part that works. I'm trying to use the above construct to > implement a new kind of dict(). > > The idea is that I want to create a dict that knows about certain values > that can have dependencies on other values. If you change a value that is > a dependency of another value within the dict, then the target value will > automatically recompute itself. In the example below, the value of the key > "range" is dependent on the value of the key "stop". > > When I run the code, the function recalc_range seems to be successfully > saved as a bound method. (The save happens in AddDep) But then when I try > to invoke the saved bound method, it yells at me that the arg to > __getitem__ is of the wrong type. > > Does anyone see what I did wrong? > self.recalc_f[idx] = jj[2].__get__(BalancedDict, self) The __get__() method's signature is __get__(self, obj, type=None) not the other way round. But the real problem is that you are not heeding Kernighan's warning that debugging is twice as hard as writing the code in the first place... Peter From payal-python at scriptkitchen.com Tue Jun 1 02:43:25 2010 From: payal-python at scriptkitchen.com (Payal) Date: Mon, 31 May 2010 23:43:25 -0700 Subject: reading help() - newbie question In-Reply-To: References: <20100531101946.GA13241@scriptkitchen.com> Message-ID: <20100601064325.GA28424@scriptkitchen.com> On Mon, May 31, 2010 at 08:41:54PM +1000, Xavier Ho wrote: > Welcome (back) to the Python-List! Thanks a lot to all who replied. Special thanks to Xavier Ho for sample examples on iterators. That cleared the doubt. With warm regards, -Payal -- From madhuri.vio at gmail.com Tue Jun 1 03:16:15 2010 From: madhuri.vio at gmail.com (madhuri vio) Date: Tue, 1 Jun 2010 12:46:15 +0530 Subject: hii Message-ID: i wanted to know the difference between copy composed objects and independent objects composed objects >>> firstserie = all_2_digests([?EcoRI?, ?HindIII?, ?BamHI?]) >>> firstserie [[?EcoRI?, ?HindIII?], [?EcoRI?, ?BamHI?], [?HindIII?, ?BamHI?]] >>> newserie = firstserie[1:] >>> newserie [[?EcoRI?, ?BamHI?], [?HindIII?, ?BamHI?]] >>> newserie[1][0]=?SarI? >>> newserie [[?EcoRI?, ?BamHI?], [?SarI?, ?BamHI?]] >>> firstserie [[?EcoRI?, ?HindIII?], [?EcoRI?, ?BamHI?], [?SarI?, ?BamHI?]] independent objects >>> firstserie = all_2_digests([?EcoRI?, ?HindIII?, ?BamHI?]) >>> firstserie [[?EcoRI?, ?HindIII?], [?EcoRI?, ?BamHI?], [?HindIII?, ?BamHI?]] >>> import copy >>> newserie = copy.deepcopy(firstserie)[1:] >>> newserie [[?EcoRI?, ?BamHI?], [?HindIII?, ?BamHI?]] >>> newserie[1][0]=?SarI? >>> newserie [[?EcoRI?, ?BamHI?], [?SarI?, ?BamHI?]] >>> firstserie [[?EcoRI?, ?HindIII?], [?EcoRI?, ?BamHI?], [?HindIII?, ?BamHI?]] i want to know the difference in the context of this program -- madhuri :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From holmes86 at gmail.com Tue Jun 1 03:27:10 2010 From: holmes86 at gmail.com (holmes86) Date: Tue, 1 Jun 2010 00:27:10 -0700 (PDT) Subject: how to generate a csr in python? References: Message-ID: <28e0376b-c612-4944-b383-4064e193bafc@v18g2000vbc.googlegroups.com> On May 31, 7:37?pm, holmes86 wrote: > hi,everyone > > I want generate a Certificate signing request in python,but I don't > how to realize this function.I don't find any method after read the > python-openssl manual.Any help will appreciate. nobody? From __peter__ at web.de Tue Jun 1 03:46:58 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 01 Jun 2010 09:46:58 +0200 Subject: how to generate a csr in python? References: <28e0376b-c612-4944-b383-4064e193bafc@v18g2000vbc.googlegroups.com> Message-ID: holmes86 wrote: > On May 31, 7:37 pm, holmes86 wrote: >> hi,everyone >> >> I want generate a Certificate signing request in python,but I don't >> how to realize this function.I don't find any method after read the >> python-openssl manual.Any help will appreciate. > > nobody? Is the createCertRequest() function at http://bazaar.launchpad.net/~exarkun/pyopenssl/trunk/annotate/head:/examples/certgen.py what you're looking for? Peter From jeanmichel at sequans.com Tue Jun 1 05:39:06 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 01 Jun 2010 11:39:06 +0200 Subject: Problems with relative imports and pep 366 In-Reply-To: <1275331679.3204.1.camel@eulero-desktop> References: <1275331679.3204.1.camel@eulero-desktop> Message-ID: <4C04D53A.8070106@sequans.com> Gabriele Lanaro wrote: > I've yet asked this question on SO, I'll copy the contents: > > I have a "canonical file structure" like that (I'm giving sensible names > to ease the reading): > > mainpack/ > > __main__.py > __init__.py > > - helpers/ > __init__.py > path.py > > - network/ > __init__.py > clientlib.py > server.py > > - gui/ > __init__.py > mainwindow.py > controllers.py > > In this structure, for example modules contained in each package may > want to access the helpers utilities through relative imports in > something like: > > # network/clientlib.py > from ..helpers.path import create_dir > > The program is runned "as a script" using the __main__.py file in this > way: > > python mainpack/ > > Trying to follow the PEP 366 I've put in __main__.py these lines: > > ___package___ = "mainpack" > from .network.clientlib import helloclient > > But when running: > > $ python mainpack > Traceback (most recent call last): > File "/usr/lib/python2.6/runpy.py", line 122, in _run_module_as_main > "__main__", fname, loader, pkg_name) > File "/usr/lib/python2.6/runpy.py", line 34, in _run_code > exec code in run_globals > File "path/mainpack/__main__.py", line 2, in > from .network.clientlib import helloclient > SystemError: Parent module 'mainpack' not loaded, cannot perform relative import > > What's wrong? What is the correct way to handle and effectively use > relative imports? > > I've tried also to add the current directory to the PYTHONPATH, nothing > changes. > > link: > http://stackoverflow.com/questions/2943847/nightmare-with-relative-imports-how-does-pep-366-work > > > I'm not using relative imports at all, so I can't help you on that point, however, did you consider using absolute imports ? The world becomes so simple with these :) . BTW, ___package___ = "mainpack" looks weird to me, are you sure it would not be better with __package__ = "mainpack" # only 2 leading/traling underscore JM From pradeepbpin at gmail.com Tue Jun 1 06:56:29 2010 From: pradeepbpin at gmail.com (pradeepbpin) Date: Tue, 1 Jun 2010 03:56:29 -0700 (PDT) Subject: Hashbang error Message-ID: <7c7f86a0-2522-4958-b6e0-b1e4f4ea16cf@u3g2000prl.googlegroups.com> I use gVim as an editor to create python scripts on a windows machine. To run the same script on my ubuntu machine, I added a hashbang line to the script. Now when I run this script from command line of ubuntu, I get a bad interpreter error, like below /usr/bin/python^M: bad interpreter: No such file or directory This, I understand, is due to the interpretation of newline character at the end of the hashbang. I have checked and found out that this does not happen if I create the script in Ubuntu with gVim. Now, how can I avoid this error when I create the script on a windows machine? From awilliam at whitemice.org Tue Jun 1 07:01:36 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 01 Jun 2010 07:01:36 -0400 Subject: Python vs. Fedora and CentOS In-Reply-To: <4c015aa9$0$1617$742ec2ed@news.sonic.net> References: <4c015aa9$0$1617$742ec2ed@news.sonic.net> Message-ID: <1275390096.10495.8.camel@linux-yu4c.site> On Sat, 2010-05-29 at 11:43 -0700, John Nagle wrote: > The major Red Hat based Linux distros are still shipping with Python 2.4. > As a result, almost all hosting providers are running obsolete versions of > Python. > The big problem seems to be that "cPanel" and "yum" still use older versions > of Python, and those programs are more important to distro builders than Python > itself. > Is anybody trying to do something about this? Yes, we install Python 2.6 on CentOS and run a production app on it - no problems. rpm -Uvh http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/i386/ius-release-1-4.ius.el5.noarch.rpm yum -y install python26 python26-setuptools -- Adam Tauno Williams LPIC-1, Novell CLA OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba From cs at zip.com.au Tue Jun 1 07:08:29 2010 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 1 Jun 2010 21:08:29 +1000 Subject: Hashbang error In-Reply-To: <7c7f86a0-2522-4958-b6e0-b1e4f4ea16cf@u3g2000prl.googlegroups.com> References: <7c7f86a0-2522-4958-b6e0-b1e4f4ea16cf@u3g2000prl.googlegroups.com> Message-ID: <20100601110829.GA9697@cskk.homeip.net> On 01Jun2010 03:56, pradeepbpin wrote: | I use gVim as an editor to create python scripts on a windows machine. | To run the same script on my ubuntu machine, I added a hashbang line | to the script. Now when I run this script from command line of ubuntu, | I get a bad interpreter error, like below | | /usr/bin/python^M: bad interpreter: No such file or directory | | This, I understand, is due to the interpretation of newline character | at the end of the hashbang. | | I have checked and found out that this does not happen if I create the | script in Ubuntu with gVim. | | Now, how can I avoid this error when I create the script on a windows | machine? The standard approach is to copy the file to the unix machine and use the dos2unix command. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ A pessimist is an optimist in full possession of the facts. From puntabluda at gmail.com Tue Jun 1 07:19:37 2010 From: puntabluda at gmail.com (Rebelo) Date: Tue, 01 Jun 2010 13:19:37 +0200 Subject: Hashbang error In-Reply-To: <7c7f86a0-2522-4958-b6e0-b1e4f4ea16cf@u3g2000prl.googlegroups.com> References: <7c7f86a0-2522-4958-b6e0-b1e4f4ea16cf@u3g2000prl.googlegroups.com> Message-ID: On 06/01/2010 12:56 PM, pradeepbpin wrote: > I use gVim as an editor to create python scripts on a windows machine. > To run the same script on my ubuntu machine, I added a hashbang line > to the script. Now when I run this script from command line of ubuntu, > I get a bad interpreter error, like below > > /usr/bin/python^M: bad interpreter: No such file or directory > > This, I understand, is due to the interpretation of newline character > at the end of the hashbang. > > I have checked and found out that this does not happen if I create the > script in Ubuntu with gVim. > > Now, how can I avoid this error when I create the script on a windows > machine? check if there is an option like in Geany to select encoding and line endings From leo at lspace.org Tue Jun 1 07:48:38 2010 From: leo at lspace.org (Leo Breebaart) Date: 1 Jun 2010 11:48:38 GMT Subject: What does this PyChecker warning mean? Message-ID: <86kacmF106U1@mid.individual.net> When fed the following code: def Foo(): class A(object): def __init__(self): pass class B(object): def __init__(self): pass PyChecker 0.8.18 warns: foo.py:9: Redefining attribute (__init__) original line (5) I do not understand what is meant by this warning. In fact, it simply seems wrong -- but I have learned not to jump to that conclusion too quickly, so I was hoping someone here could perhaps enlighten me... Many thanks in advance, -- Leo Breebaart From contact at xavierho.com Tue Jun 1 07:53:13 2010 From: contact at xavierho.com (Xavier Ho) Date: Tue, 1 Jun 2010 21:53:13 +1000 Subject: What does this PyChecker warning mean? In-Reply-To: <86kacmF106U1@mid.individual.net> References: <86kacmF106U1@mid.individual.net> Message-ID: On 1 June 2010 21:48, Leo Breebaart wrote: > > When fed the following code: > > def Foo(): > > class A(object): > def __init__(self): > pass > > class B(object): > def __init__(self): > pass > > PyChecker 0.8.18 warns: > > foo.py:9: Redefining attribute (__init__) original line (5) > Out of curiosity, why are you defining two classes inside a function? -Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris.gonnerman at newcenturycomputers.net Tue Jun 1 07:59:59 2010 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Tue, 01 Jun 2010 06:59:59 -0500 Subject: [Python] Hashbang error In-Reply-To: <7c7f86a0-2522-4958-b6e0-b1e4f4ea16cf@u3g2000prl.googlegroups.com> References: <7c7f86a0-2522-4958-b6e0-b1e4f4ea16cf@u3g2000prl.googlegroups.com> Message-ID: <4C04F63F.7040301@newcenturycomputers.net> pradeepbpin wrote: > I use gVim as an editor to create python scripts on a windows machine. > To run the same script on my ubuntu machine, I added a hashbang line > to the script. Now when I run this script from command line of ubuntu, > I get a bad interpreter error, like below > > /usr/bin/python^M: bad interpreter: No such file or directory > > This, I understand, is due to the interpretation of newline character > at the end of the hashbang. > > I have checked and found out that this does not happen if I create the > script in Ubuntu with gVim. > > Now, how can I avoid this error when I create the script on a windows > machine? > In gvim, type: :se ff=unix then resave the file. Once it's in unix format, gvim won't change it back to dos unless you tell it to. -- Chris. From kaklis at gmail.com Tue Jun 1 08:15:45 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Tue, 1 Jun 2010 05:15:45 -0700 (PDT) Subject: expat parsing error Message-ID: <5bbcadff-449d-465f-b7ff-44790e757c4a@y12g2000vbr.googlegroups.com> Hi i'm doing the following: def start_element(name, attrs): print 'Start element:', name, attrs def end_element(name): print 'End element:', name def char_data(data): print 'Character data:', repr(data) class SimpleServer(LineReceiver): # Using Twisted def connectionMade(self): print 'Connection from: ', self.transport.client def connectionLost(self, reason): print self.transport.client, 'Disconnected' def dataReceived(self, line): """Here the XML Parser""" p = xml.parsers.expat.ParserCreate() p.StartElementHandler = start_element p.EndElementHandler = end_element p.CharacterDataHandler = char_data p.Parse(line, 1) I got the following error --- --- File "/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux- x86_64.egg/twisted/internet/selectreactor.py", line 146, in _doReadOrWrite why = getattr(selectable, method)() File "/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux- x86_64.egg/twisted/internet/tcp.py", line 460, in doRead return self.protocol.dataReceived(data) File "stdiodemo.py", line 419, in dataReceived p.Parse(line, 1) xml.parsers.expat.ExpatError: syntax error: line 1, column 0 The XML Message is coming in the form of: POST /test/pcp/Listener HTTP/1.1 user-agent:hjahsjdhaskd asdja d Host:127.0.0.1 Content-Length: 547 200 OK, found 5 session entries 06d4d59bf8f1abf57cadfe10139dd874 82 android Please give me some hints From __peter__ at web.de Tue Jun 1 08:23:23 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 01 Jun 2010 14:23:23 +0200 Subject: What does this PyChecker warning mean? References: <86kacmF106U1@mid.individual.net> Message-ID: Leo Breebaart wrote: > > When fed the following code: > > def Foo(): > > class A(object): > def __init__(self): > pass > > class B(object): > def __init__(self): > pass > > PyChecker 0.8.18 warns: > > foo.py:9: Redefining attribute (__init__) original line (5) > > I do not understand what is meant by this warning. In fact, it > simply seems wrong -- but I have learned not to jump to that > conclusion too quickly, so I was hoping someone here could > perhaps enlighten me... You are right, that's a false positive. pychecker seems to confuse the namespaces. Peter From kaklis at gmail.com Tue Jun 1 08:59:29 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Tue, 1 Jun 2010 05:59:29 -0700 (PDT) Subject: expat parsing error Message-ID: <1217d1c2-0337-4852-958e-0d1c57a38c11@e21g2000vbl.googlegroups.com> Hi i'm doing the following: def start_element(name, attrs): print 'Start element:', name, attrs def end_element(name): print 'End element:', name def char_data(data): print 'Character data:', repr(data) class SimpleServer(LineReceiver): # Using Twisted def connectionMade(self): print 'Connection from: ', self.transport.client def connectionLost(self, reason): print self.transport.client, 'Disconnected' def dataReceived(self, line): """Here the XML Parser""" p = xml.parsers.expat.ParserCreate() p.StartElementHandler = start_element p.EndElementHandler = end_element p.CharacterDataHandler = char_data p.Parse(line, 1) I got the following error --- --- File "/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux- x86_64.egg/twisted/internet/selectreactor.py", line 146, in _doReadOrWrite why = getattr(selectable, method)() File "/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux- x86_64.egg/twisted/internet/tcp.py", line 460, in doRead return self.protocol.dataReceived(data) File "stdiodemo.py", line 419, in dataReceived p.Parse(line, 1) xml.parsers.expat.ExpatError: syntax error: line 1, column 0 The XML Message is coming in the form of: POST /test/pcp/Listener HTTP/1.1 user-agent:hjahs Host:127.0.0.1 Content-Length: 547 200 OK, found 5 session entries 06d4d59bfdfe10139dd874 82 and Please give me some hints From icanbob at gmail.com Tue Jun 1 09:07:56 2010 From: icanbob at gmail.com (bobicanprogram) Date: Tue, 1 Jun 2010 06:07:56 -0700 (PDT) Subject: Returning value from home made unit - how to? References: Message-ID: On May 30, 6:22 pm, Mel wrote: > Martin Hvidberg wrote: > > I have a Python program, which has until now, been running in command line > > mode only. I wish to add a GUI. > > > I would like to develop (and maintain) the GUI part in a separate module, > > i.e. in its own .py file, and then ?import? that into the old main > > program. > > > I jumped into wxPython, as it seems to be the right GUI for me, and > > downloaded some examples that I took apart and joined. Now the basic GUI > > is running, though neither beautiful nor complete. > > > The main task for my GUI is to allow the user to point to an input file. > > It can now obtain a filename from a file selection dialog, but I can?t > > figure out how to get the filename, i.e. the string variable containing > > the file name, send back to the main program? > > > I attach the two .py files hereunder. > > > My question is: > > How do I get the information from variable strSequenceFile, back to the > > main module in file jacxl.py ? > > AFAIK, typically, you don't -- the way it is here. Returning a value from a > Button handler, or any event handler generally, won't have any effect. The > event handlers are called from deep in wx code by routines that don't deal > with anything specific to the data-processing side of the program. > > What I think you might do is to make strSequenceFile an attribute of your > Frame, so that OnFindFile button does ``self.strSequenceFile = > dialog.GetPath()'' rather than returning that value. > > Then your main level can do ``jacXlgui.app.GetTopWindow().strSequenceFile'' > . > > There are probably refinements to be added to this, but I think it's a good > beginning strategy. The first new place I would take the whole program > would be to remove the command-line controls from the command line program, > so you're left with a sort of "business model" that contains only the data > processing. Then you can write a new GUI program based on jacXlgui that > imports the data processing module and calls computations and reports > results from the model. > > Mel. Another way to encapsulate functionality like a GUI is to "hide" it behind a nice clean messaging interface. The SIMPL toolkit (http:// www.icanprogram.com/06py/lesson1/lesson1.html) promotes this kind of design. SIMPL allows Python to Python messaging as well as Python to C, C++, JAVA or Tcl/Tk so what you ultimately choose for the GUI has only minimal impact on what you choose for your "processing engine". Happy coding. bob From schwarz.ben at gmail.com Tue Jun 1 09:18:54 2010 From: schwarz.ben at gmail.com (meow) Date: Tue, 1 Jun 2010 06:18:54 -0700 (PDT) Subject: labels legibility in matplotlib pie charts and bar plots Message-ID: <823bf8bf-bddc-49b3-bc60-f61512743f26@b21g2000vbh.googlegroups.com> Hi, As a beginner in python and matplotlib I come here with a possibly na?ve question. I need to write code for automation of bar-plots and pie-charts creation. I chose to use matplotlib which is well adapted for this purpose. Nevertheless, some of my charts are not very legible due to interferences between to many or to long labels. Sometimes my labels spread over the edge of the picture, and therefore are simply cut out; sometimes the different labels superpose, resulting in an illegible pie-chart. Do you know an easy way to control the labels size and repartition ? Is it possible to prohibit the label cutting, for instance a way to set the picture size so that no label is cut anymore ? Does matplotlib provide an easy way to spread labels or pie chunks so that the labels do not interfere with each other ? You will find my two code samples here after Any hint or recommendation appreciated --Ben # pie chart code # def savePie(populationGO,filepath,figtitle): """ saves Pie Charts of a population to a file """ plt.figure(figsize=(8,8)) labels=[k+"\n"+str(v) for k,v in populationGO.iteritems()] plt.clf(); plt.pie (populationGO.values(),labels=labels,labeldistance=1.1,autopct='%1.1f% %',pctdistance=.8) plt.title(figtitle) plt.savefig(filepath) # bar plot code # barPlotWidth=.25 plt.clf() barPlotOffsets = np.arange(len(labels)) r1 = plt.bar(barPlotOffsets ,popGO ,color="r",width=barPlotWidth) r2 = plt.bar(barPlotOffsets +barPlotWidth ,popGOall ,color="g",width=barPlotWidth) r3 = plt.bar(barPlotOffsets +(2*barPlotWidth) ,popGOlowr ,color="b",width=barPlotWidth) plt.ylabel('Population (number of protein chains)') plt.title('GO Population by simplified GO and dataset') plt.xticks(barPlotOffsets+barPlotWidth, labels,rotation = 17 ) plt.legend( (r1[0],r2[0],r3[0]), ("all SIFTS annotated","all PDB protein chains","all PDB p.chains R<=2.1") ) print "\nSave comparative bar plot file" fileName = "GO-population--comparative-bar-plot.png" print "...",fileName filepath=os.path.join(pc.resDir,fileName) plt.savefig(filepath) From john at castleamber.com Tue Jun 1 09:51:30 2010 From: john at castleamber.com (John Bokma) Date: Tue, 01 Jun 2010 08:51:30 -0500 Subject: expat parsing error References: <5bbcadff-449d-465f-b7ff-44790e757c4a@y12g2000vbr.googlegroups.com> Message-ID: <87vda2vp25.fsf@castleamber.com> "kaklis at gmail.com" writes: > I got the following error > --- --- > File "/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux- > x86_64.egg/twisted/internet/selectreactor.py", line 146, in > _doReadOrWrite > why = getattr(selectable, method)() > File "/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux- > x86_64.egg/twisted/internet/tcp.py", line 460, in doRead > return self.protocol.dataReceived(data) > File "stdiodemo.py", line 419, in dataReceived > p.Parse(line, 1) > xml.parsers.expat.ExpatError: syntax error: line 1, column 0 > > > The XML Message is coming in the form of: > > POST /test/pcp/Listener HTTP/1.1 Does Expat get this line as well? If so, that's the reason why you get an error at line 1, column 0. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From kaklis at gmail.com Tue Jun 1 10:00:46 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Tue, 1 Jun 2010 07:00:46 -0700 (PDT) Subject: expat parsing error References: <5bbcadff-449d-465f-b7ff-44790e757c4a@y12g2000vbr.googlegroups.com> <87vda2vp25.fsf@castleamber.com> Message-ID: On Jun 1, 9:51?am, John Bokma wrote: > "kak... at gmail.com" writes: > > I got the following error > > --- --- > > ? File "/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux- > > x86_64.egg/twisted/internet/selectreactor.py", line 146, in > > _doReadOrWrite > > ? ? why = getattr(selectable, method)() > > ? File "/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux- > > x86_64.egg/twisted/internet/tcp.py", line 460, in doRead > > ? ? return self.protocol.dataReceived(data) > > ? File "stdiodemo.py", line 419, in dataReceived > > ? ? p.Parse(line, 1) > > xml.parsers.expat.ExpatError: syntax error: line 1, column 0 > > > The XML Message is coming in the form of: > > > POST /test/pcp/Listener HTTP/1.1 > > Does Expat get this line as well? If so, that's the reason why you get > an error at line 1, column 0. > > -- > John Bokma ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? j3b > > Hacking & Hiking in Mexico - ?http://johnbokma.com/http://castleamber.com/- Perl & Python Development Yes but how can i fix it, how to "ignore" the headers and parse only the XML? Thanks From steveo at syslang.net Tue Jun 1 10:27:13 2010 From: steveo at syslang.net (Steven W. Orr) Date: Tue, 01 Jun 2010 10:27:13 -0400 Subject: What does this PyChecker warning mean? In-Reply-To: References: <86kacmF106U1@mid.individual.net> Message-ID: <4C0518C1.3000704@syslang.net> On 6/1/2010 7:53 AM, Xavier Ho wrote: > On 1 June 2010 21:48, Leo Breebaart > wrote: > > > When fed the following code: > > def Foo(): > > class A(object): > def __init__(self): > pass > > class B(object): > def __init__(self): > pass > > PyChecker 0.8.18 warns: > > foo.py:9: Redefining attribute (__init__) original line (5) > > > Out of curiosity, why are you defining two classes inside a function? > > -Xav > In terms of constructing a minimal example, Foo might be fodder for a closure that either returns A or B. Just s stab in the dark... -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net From john at castleamber.com Tue Jun 1 10:29:13 2010 From: john at castleamber.com (John Bokma) Date: Tue, 01 Jun 2010 09:29:13 -0500 Subject: expat parsing error References: <5bbcadff-449d-465f-b7ff-44790e757c4a@y12g2000vbr.googlegroups.com> <87vda2vp25.fsf@castleamber.com> Message-ID: <87r5kqvnba.fsf@castleamber.com> "kaklis at gmail.com" writes: > On Jun 1, 9:51?am, John Bokma wrote: >> "kak... at gmail.com" writes: >> > I got the following error >> > --- --- >> > ? File "/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux- >> > x86_64.egg/twisted/internet/selectreactor.py", line 146, in >> > _doReadOrWrite >> > ? ? why = getattr(selectable, method)() >> > ? File "/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux- >> > x86_64.egg/twisted/internet/tcp.py", line 460, in doRead >> > ? ? return self.protocol.dataReceived(data) >> > ? File "stdiodemo.py", line 419, in dataReceived >> > ? ? p.Parse(line, 1) >> > xml.parsers.expat.ExpatError: syntax error: line 1, column 0 >> >> > The XML Message is coming in the form of: >> >> > POST /test/pcp/Listener HTTP/1.1 >> >> Does Expat get this line as well? If so, that's the reason why you get >> an error at line 1, column 0. > > Yes but how can i fix it, how to "ignore" the headers and parse only > the XML? The headers are followed by exactly one empty line, so you you simply could remove lines up until including this empty line and then hand over the data to the parser. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From stefan_ml at behnel.de Tue Jun 1 10:34:58 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 01 Jun 2010 16:34:58 +0200 Subject: expat parsing error In-Reply-To: References: <5bbcadff-449d-465f-b7ff-44790e757c4a@y12g2000vbr.googlegroups.com> <87vda2vp25.fsf@castleamber.com> Message-ID: kaklis at gmail.com, 01.06.2010 16:00: > how can i fix it, how to "ignore" the headers and parse only > the XML? Consider reading the answers you got in the last thread that you opened with exactly this question. Stefan From kaklis at gmail.com Tue Jun 1 11:01:44 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Tue, 1 Jun 2010 08:01:44 -0700 (PDT) Subject: expat parsing error References: <5bbcadff-449d-465f-b7ff-44790e757c4a@y12g2000vbr.googlegroups.com> <87vda2vp25.fsf@castleamber.com> Message-ID: <47733fad-dc1c-4147-bd91-af9390338e48@o1g2000vbe.googlegroups.com> On Jun 1, 10:34?am, Stefan Behnel wrote: > kak... at gmail.com, 01.06.2010 16:00: > > > how can i fix it, how to "ignore" the headers and parse only > > the XML? > > Consider reading the answers you got in the last thread that you opened > with exactly this question. > > Stefan That's exactly, what i did but something seems to not working with the solutions i had, when i changed my implementation from pure Python's sockets to twisted library! That's the reason i have created a new post! Any ideas why this happened? Thanks Stefan From john at castleamber.com Tue Jun 1 11:09:03 2010 From: john at castleamber.com (John Bokma) Date: Tue, 01 Jun 2010 10:09:03 -0500 Subject: expat parsing error References: <5bbcadff-449d-465f-b7ff-44790e757c4a@y12g2000vbr.googlegroups.com> <87vda2vp25.fsf@castleamber.com> <47733fad-dc1c-4147-bd91-af9390338e48@o1g2000vbe.googlegroups.com> Message-ID: <87mxvevlgw.fsf@castleamber.com> "kaklis at gmail.com" writes: > On Jun 1, 10:34?am, Stefan Behnel wrote: >> kak... at gmail.com, 01.06.2010 16:00: >> >> > how can i fix it, how to "ignore" the headers and parse only >> > the XML? >> >> Consider reading the answers you got in the last thread that you opened >> with exactly this question. >> >> Stefan > > That's exactly, what i did but something seems to not working with the > solutions i had, when i changed my implementation from pure Python's > sockets to twisted library! > That's the reason i have created a new post! > Any ideas why this happened? As I already explained: if you send your headers as well to any XML parser it will choke on those, because the headers are /not/ valid / well-formed XML. The solution is to remove the headers from your data. As I explained before: headers are followed by one empty line. Just remove lines up and until including the empty line, and pass the data to any XML parser. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From kaklis at gmail.com Tue Jun 1 11:12:35 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Tue, 1 Jun 2010 08:12:35 -0700 (PDT) Subject: expat parsing error References: <5bbcadff-449d-465f-b7ff-44790e757c4a@y12g2000vbr.googlegroups.com> <87vda2vp25.fsf@castleamber.com> <47733fad-dc1c-4147-bd91-af9390338e48@o1g2000vbe.googlegroups.com> <87mxvevlgw.fsf@castleamber.com> Message-ID: <5930ecdf-99b2-49d3-b168-db5cb5472411@f13g2000vbm.googlegroups.com> On Jun 1, 11:09?am, John Bokma wrote: > "kak... at gmail.com" writes: > > On Jun 1, 10:34?am, Stefan Behnel wrote: > >> kak... at gmail.com, 01.06.2010 16:00: > > >> > how can i fix it, how to "ignore" the headers and parse only > >> > the XML? > > >> Consider reading the answers you got in the last thread that you opened > >> with exactly this question. > > >> Stefan > > > That's exactly, what i did but something seems to not working with the > > solutions i had, when i changed my implementation from pure Python's > > sockets to twisted library! > > That's the reason i have created a new post! > > Any ideas why this happened? > > As I already explained: if you send your headers as well to any XML > parser it will choke on those, because the headers are /not/ valid / > well-formed XML. The solution is to remove the headers from your > data. As I explained before: headers are followed by one empty > line. Just remove lines up and until including the empty line, and pass > the data to any XML parser. > > -- > John Bokma ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? j3b > > Hacking & Hiking in Mexico - ?http://johnbokma.com/http://castleamber.com/- Perl & Python Development Thank you so much i'll try it! Antonis From mbnoimi at gmx.com Tue Jun 1 11:22:19 2010 From: mbnoimi at gmx.com (M. Bashir Al-Noimi) Date: Tue, 01 Jun 2010 17:22:19 +0200 Subject: Path issue (TemplateDoesNotExist) Message-ID: <4C0525AB.6090503@gmx.com> Hi folks, I'm trying to build my first blog by python/django but during writing it I faced a path problem so django couldn't recognize template path. For that the debugger gave me the following log (you can see full log and the whole project in the attachment), although I added the absolute template path to TEMPLATE_DIRS tuple. Could you please tell me what's wrong? PS I still newbie guys ;-) --log-- TemplateDoesNotExist at / posts/post_list.html Request Method: GET Request URL: http://127.0.0.1:8000/ Exception Type: TemplateDoesNotExist Exception Value: posts/post_list.html Exception Location: C:\Python26\lib\site-packages\django\template\loader.py in find_template_source, line 74 Python Executable: C:\Python26\python.exe Python Version: 2.6.3 Python Path: ['Q:\\Apps\\Common\\eclipse-py\\workspace\\MyBlog\\src\\MyBlog', 'Q:\\Apps\\Common\\eclipse-py\\workspace\\MyBlog\\src', 'Q:\\Apps\\Common\\eclipse-py\\workspace\\MyBlog\\templates', 'C:\\Python26', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26\\lib\\plat-win', 'C:\\Python26\\lib\\site-packages', 'C:\\WINDOWS\\system32\\python26.zip'] Server time: Mon, 31 May 2010 15:45:49 +0200 -- Best Regards Muhammad Bashir Al-Noimi My Blog:http://mbnoimi.net -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: MyBlogProject.zip Type: application/x-zip-compressed Size: 15115 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: debugger_log.zip Type: application/x-zip-compressed Size: 8405 bytes Desc: not available URL: From leo at lspace.org Tue Jun 1 11:25:11 2010 From: leo at lspace.org (Leo Breebaart) Date: 1 Jun 2010 15:25:11 GMT Subject: What does this PyChecker warning mean? References: <86kacmF106U1@mid.individual.net> Message-ID: <86kn2nFgvgU1@mid.individual.net> On 6/1/2010 7:53 AM, Xavier Ho wrote: > > Out of curiosity, why are you defining two classes inside a > > function? Not my code! Not my code! :-) This code was contributed by someone else, and I merely took my default action (in such cases) of running pyflakes, pychecker, and pylint on it before doing anything else, just to see what comes up. As far as I can tell the sole reason for that code being structured the way it is, is to provide a kind of module-within-a-module and not clutter up the outer module with these helper classes needed only by the foo() function. -- Leo Breebaart From a_jtim at bellsouth.net Tue Jun 1 11:35:25 2010 From: a_jtim at bellsouth.net (Tim Arnold) Date: Tue, 1 Jun 2010 08:35:25 -0700 (PDT) Subject: multiprocessing and accessing server's stdout References: <0c6dd70f-ec1b-4fe7-9e1d-82dbeab2f390@z33g2000vbb.googlegroups.com> Message-ID: <6ddb97ae-9a2c-4dbc-ac5c-dc411015a78e@o12g2000vba.googlegroups.com> On May 28, 7:47?pm, "Martin P. Hellwig" wrote: > On 05/28/10 21:44, Adam Tauno Williams wrote: > > > On Fri, 2010-05-28 at 15:41 +0100, Martin P. Hellwig wrote: > >> On 05/28/10 13:17, Adam Tauno Williams wrote: > >> > >>> You should be able to point it any any file-like object. ?But, again, > >>> why? > >>> If you have the data in the process why send it tostdoutand redirect > >>> it. ?Why not just send the data to the client directly? > >> Well you might want to multiplex it to more then one client, not saying > >> that this is the case here, just something I imagine possible. > > > That still doesn't make sense. ?Why 'multiplexstdout'? ?Why not just > > multiplex the data into proper IPC channels in the first place? > > I am going on a stretch here, I mostly agree with you, just trying to > illustrate that there could be corner cases where this is sensible. > The current situation could be that there is a client/server program > (binary only perhaps) which is not multi-user safe. > > Python can be used as a wrapper around the server to make it > multi-client, by emulating the exact behavior towards the client, the > client program does not have to be changed. > > -- > mph Hi, This is the setup I was asking about. I've got users using a python-written command line client. They're requesting services from a remote server that fires a LaTeX process. I want them to see the stdout from the LaTeX process. I was using multiprocessing to handle the requests, but the stdout shows up on the server's terminal window where I started the server.serve_forever process. I started using RPyC and now the stdout appears on the client terminal making the request. I was trying to minimize the number of packages I use, hoping I could get the same capability from multiprocessing that I get with RPyC. thanks for the comments. I'm still processing what's been written here. --Tim From tjreedy at udel.edu Tue Jun 1 11:38:17 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 01 Jun 2010 11:38:17 -0400 Subject: What does this PyChecker warning mean? In-Reply-To: References: <86kacmF106U1@mid.individual.net> Message-ID: On 6/1/2010 8:23 AM, Peter Otten wrote: > Leo Breebaart wrote: > >> >> When fed the following code: >> >> def Foo(): >> >> class A(object): >> def __init__(self): >> pass >> >> class B(object): >> def __init__(self): >> pass >> >> PyChecker 0.8.18 warns: >> >> foo.py:9: Redefining attribute (__init__) original line (5) >> >> I do not understand what is meant by this warning. In fact, it >> simply seems wrong -- but I have learned not to jump to that >> conclusion too quickly, so I was hoping someone here could >> perhaps enlighten me... > > You are right, that's a false positive. pychecker seems to confuse the > namespaces. Consider sending this example back to the pychecker author. The program does not seem to be interpreting the nested class statements properly. From kaklis at gmail.com Tue Jun 1 11:57:39 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Tue, 1 Jun 2010 08:57:39 -0700 (PDT) Subject: expat parsing error References: <5bbcadff-449d-465f-b7ff-44790e757c4a@y12g2000vbr.googlegroups.com> <87vda2vp25.fsf@castleamber.com> <47733fad-dc1c-4147-bd91-af9390338e48@o1g2000vbe.googlegroups.com> <87mxvevlgw.fsf@castleamber.com> <5930ecdf-99b2-49d3-b168-db5cb5472411@f13g2000vbm.googlegroups.com> Message-ID: On Jun 1, 11:12?am, "kak... at gmail.com" wrote: > On Jun 1, 11:09?am, John Bokma wrote: > > > > > "kak... at gmail.com" writes: > > > On Jun 1, 10:34?am, Stefan Behnel wrote: > > >> kak... at gmail.com, 01.06.2010 16:00: > > > >> > how can i fix it, how to "ignore" the headers and parse only > > >> > the XML? > > > >> Consider reading the answers you got in the last thread that you opened > > >> with exactly this question. > > > >> Stefan > > > > That's exactly, what i did but something seems to not working with the > > > solutions i had, when i changed my implementation from pure Python's > > > sockets to twisted library! > > > That's the reason i have created a new post! > > > Any ideas why this happened? > > > As I already explained: if you send your headers as well to any XML > > parser it will choke on those, because the headers are /not/ valid / > > well-formed XML. The solution is to remove the headers from your > > data. As I explained before: headers are followed by one empty > > line. Just remove lines up and until including the empty line, and pass > > the data to any XML parser. > > > -- > > John Bokma ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? j3b > > > Hacking & Hiking in Mexico - ?http://johnbokma.com/http://castleamber.com/-Perl & Python Development > > Thank you so much i'll try it! > Antonis Dear John can you provide me a simple working solution? I don't seem to get it From nima.irt at gmail.com Tue Jun 1 12:42:02 2010 From: nima.irt at gmail.com (Nima) Date: Tue, 1 Jun 2010 21:12:02 +0430 Subject: Drawing Multigraphs Message-ID: Hi there, Is it possible to draw an (undirected) multigraph using a python library? I need to write a program that finds an Eulerian circuit in a graph (which might obviously be a multigraph). As the output of the program, I should draw the graph and print out the solution. I asked my question at NetworkX discussion group. They told me that matplotlib, which provides drawing routines for NetworkX, doesn't show multiple edges and I have to pass the graph to another graph drawing package (if there is one!). * I've used the Fleury's algorithm to solve the problem. -- Yours sincerely, Nima Mohammadi From torriem at gmail.com Tue Jun 1 12:43:40 2010 From: torriem at gmail.com (Michael Torrie) Date: Tue, 01 Jun 2010 10:43:40 -0600 Subject: Python vs. Fedora and CentOS In-Reply-To: <3RMMn.125235$y07.3938@news.usenetserver.com> References: <4c015aa9$0$1617$742ec2ed@news.sonic.net> <3RMMn.125235$y07.3938@news.usenetserver.com> Message-ID: <4C0538BC.4010809@gmail.com> On 05/31/2010 05:13 AM, Jason D wrote: > There is however never been an issue to locate different version of python > in your system as you deem fit without problems. > So I dont understand why your concern. Actually, replacing python on RHEL is a major endeavor. Almost all Red Hat utilities are written in python and depend on the specific system version of python that they shipped. Thus if you want to upgrade python you're going to break 80% of the system. Sure you can install Python from source alongside the system python, but that's a maintenance nightmare for system administrators. I administer some 30 RHEL instances, and compiling from source just isn't a good option here. As for third-party RPMs, that's all fine and well as long as you don't need any support from Red Hat. RH can only support software they ship and certify. As for me, I don't need RH to support my custom RPMs, so I think that's probably a fair compromise. It would be nice to have a source (that's kept up to date security-wise) of python packages that can be installed alongside RH system ones. Maybe call it python26 or python28 or python31 and stick it in the EPEL repository. I am supposing that if anyone wanted to do this, the EPEL folks would be happy to let that person be the package maintainer. From torriem at gmail.com Tue Jun 1 12:55:14 2010 From: torriem at gmail.com (Michael Torrie) Date: Tue, 01 Jun 2010 10:55:14 -0600 Subject: Python vs. Fedora and CentOS In-Reply-To: <1275390096.10495.8.camel@linux-yu4c.site> References: <4c015aa9$0$1617$742ec2ed@news.sonic.net> <1275390096.10495.8.camel@linux-yu4c.site> Message-ID: <4C053B72.60302@gmail.com> On 06/01/2010 05:01 AM, Adam Tauno Williams wrote: > Yes, we install Python 2.6 on CentOS and run a production app on it - no > problems. > > rpm -Uvh > http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/i386/ius-release-1-4.ius.el5.noarch.rpm > > yum -y install python26 python26-setuptools Thanks for posting this link. Very useful and interesting. The only problem I have is how do I tell what third-party repositories are to be trusted in my production systems? And even more important, which repositories are actually going to keep up to date on security updates in the long run? It's hard to know. From awilliam at whitemice.org Tue Jun 1 13:23:22 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 01 Jun 2010 13:23:22 -0400 Subject: Python vs. Fedora and CentOS In-Reply-To: <4C0538BC.4010809@gmail.com> References: <4c015aa9$0$1617$742ec2ed@news.sonic.net> <3RMMn.125235$y07.3938@news.usenetserver.com> <4C0538BC.4010809@gmail.com> Message-ID: <1275413002.4121.2.camel@linux-yu4c.site> On Tue, 2010-06-01 at 10:43 -0600, Michael Torrie wrote: > On 05/31/2010 05:13 AM, Jason D wrote: > > There is however never been an issue to locate different version of python > > in your system as you deem fit without problems. > > So I dont understand why your concern. > > Actually, replacing python on RHEL is a major endeavor. Then don't do it. Just install Python 2.6. Who cares what version of Python the system utilities use? > Almost all Red > Hat utilities are written in python and depend on the specific system > version of python that they shipped. Thus if you want to upgrade python > you're going to break 80% of the system. > > Sure you can install Python from source alongside the system python, but > that's a maintenance nightmare for system administrators. No, it is not. It is trivial. The packages don't overlap at all. You run python2.6, easy_install-2.6, etc... and the app merrily runs. > I administer > some 30 RHEL instances, and compiling from source just isn't a good > option here. As for third-party RPMs, that's all fine and well as long > as you don't need any support from Red Hat. RH can only support > software they ship and certify. In my experience RedHat supports their system - *not* the software you run on it. So they don't care either way. > As for me, I don't need RH to support > my custom RPMs, so I think that's probably a fair compromise. It would > be nice to have a source (that's kept up to date security-wise) of > python packages that can be installed alongside RH system ones. Maybe > call it python26 or python28 or python31 and stick it in the EPEL > repository. I am supposing that if anyone wanted to do this, the EPEL > folks would be happy to let that person be the package maintainer. rpm -Uvh http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/i386/ius-release-1-4.ius.el5.noarch.rpm yum -y install python26 python26-setuptools -- Adam Tauno Williams LPIC-1, Novell CLA OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba From awilliam at whitemice.org Tue Jun 1 13:25:49 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Tue, 01 Jun 2010 13:25:49 -0400 Subject: Python vs. Fedora and CentOS In-Reply-To: <4C053B72.60302@gmail.com> References: <4c015aa9$0$1617$742ec2ed@news.sonic.net> <1275390096.10495.8.camel@linux-yu4c.site> <4C053B72.60302@gmail.com> Message-ID: <1275413149.4121.4.camel@linux-yu4c.site> On Tue, 2010-06-01 at 10:55 -0600, Michael Torrie wrote: > On 06/01/2010 05:01 AM, Adam Tauno Williams wrote: > > Yes, we install Python 2.6 on CentOS and run a production app on it - no > > problems. > > rpm -Uvh > > http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/i386/ius-release-1-4.ius.el5.noarch.rpm > > yum -y install python26 python26-setuptools > Thanks for posting this link. Very useful and interesting. > The only problem I have is how do I tell what third-party repositories > are to be trusted in my production systems? And even more important, > which repositories are actually going to keep up to date on security > updates in the long run? It's hard to know. I don't know about "third-party repositories", but IUS is solid. They've been around since 2006. -- Adam Tauno Williams LPIC-1, Novell CLA OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba From m.1ahesh at gmail.com Tue Jun 1 13:29:41 2010 From: m.1ahesh at gmail.com (manoj kumar) Date: Tue, 1 Jun 2010 10:29:41 -0700 (PDT) Subject: See Hot sexy star aishwarya nude bathing videos in all angles. Message-ID: See Hot sexy star aishwarya nude bathing videos in all angles at http://dailyupdatesonly.tk Due to high sex content,i have hidden the videos in an image.in that website on left side below below search box click on image and watch videos in all angles.please dont tell to anyone. From debatem1 at gmail.com Tue Jun 1 13:43:56 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 1 Jun 2010 10:43:56 -0700 Subject: Drawing Multigraphs In-Reply-To: References: Message-ID: On Tue, Jun 1, 2010 at 9:42 AM, Nima wrote: > Hi there, > Is it possible to draw an (undirected) multigraph using a python library? > I need to write a program that finds an Eulerian circuit in a graph > (which might obviously be a multigraph). As the output of the program, > I should draw the graph and print out the solution. We use Dot in Graphine, and it works well. It's also very easy to output to. Geremy Condra (sent to the list this time) From durumdara at gmail.com Tue Jun 1 13:49:15 2010 From: durumdara at gmail.com (durumdara) Date: Tue, 1 Jun 2010 10:49:15 -0700 (PDT) Subject: MySQLDB - server has gone on blob insertion... References: Message-ID: Hi! > > drop table blobs > create table blobs (whatever definition it had originally) It was a test. In PGSQL, PYSQLite that was: delete from blobs where (file_id in (select file_id from pics where dir_id=?)) So I need to delete only all blobs that processed. > > > > > When I tried to start this, I got error: > > > _mysql_exceptions.OperationalError: (2006, 'MySQL server has gone away') > > > I read that server have some parameter, that limit the Query length. > > > Then I decreased the blob size to 1M, and then it is working. > > ? ? ? ? What is the table definition? In MySQL 4 (and likely not changed in > v5 -- I've got the old brown tree book handy, hence the mention of v4) > field type BLOB is limited to a length of 2^16 (64kB), MEDIUMBLOB is > 2^24, and LONGBLOB is 2^32 (if the system is using unsigned integers > internally, that should support 4GB... I used the latest community server. I tried LONGBLOB also, and I got also this error... :-( >But do you have enough memory to > pass such an argument? I have enough memory (4 GB), I want to insert only 1-8 MB size pictures, that is working under PYSQLITE/PGSQL. I saw that packet size need to configure - may mysqldb don't handle this with right error message, replace with "gone" error. I set these packet, and other parameters in my.ini, and I restarted the mysql, but this don't solve the problem. May I need to set this from client, but I don't know, how to do it... Thanks for every help: dd From mrjean1 at gmail.com Tue Jun 1 14:08:49 2010 From: mrjean1 at gmail.com (MrJean1) Date: Tue, 1 Jun 2010 11:08:49 -0700 (PDT) Subject: What does this PyChecker warning mean? References: <86kacmF106U1@mid.individual.net> Message-ID: <6f6cf299-2f0c-43de-a997-e85c2deb9ed2@s1g2000prf.googlegroups.com> Although PyChecker 0.8.18 is quite an improvement over previous releases, it does have quirks. The PyChecker postprocessor might be helpful, see /Jean On Jun 1, 4:48?am, Leo Breebaart wrote: > When fed the following code: > > ?def Foo(): > > ? ? class A(object): > ? ? ? ? def __init__(self): > ? ? ? ? ? ? pass > > ? ? class B(object): > ? ? ? ? def __init__(self): > ? ? ? ? ? ? pass > > PyChecker 0.8.18 warns: > > ? foo.py:9: Redefining attribute (__init__) original line (5) > > I do not understand what is meant by this warning. In fact, it > simply seems wrong -- but I have learned not to jump to that > conclusion too quickly, so I was hoping someone here could > perhaps enlighten me... > > Many thanks in advance, > > -- > Leo Breebaart ? From rbrt.somerville at gmail.com Tue Jun 1 14:18:21 2010 From: rbrt.somerville at gmail.com (robert somerville) Date: Tue, 1 Jun 2010 11:18:21 -0700 Subject: python and filter design: calculating "s" optimal transform Message-ID: Hi; this is an airy question. does anybody have some code or ideas on how to calculate the optimal "S" transform of user specified order (wanting the coefficients) for a published filter response curve, ie. f(s) = 1.0/(a1*S^2 + a2*S + a3) -------------- next part -------------- An HTML attachment was scrubbed... URL: From nima.irt at gmail.com Tue Jun 1 14:24:28 2010 From: nima.irt at gmail.com (Nima) Date: Tue, 1 Jun 2010 22:54:28 +0430 Subject: Drawing Multigraphs In-Reply-To: References: Message-ID: 2010/6/1 geremy condra > > We use Dot in Graphine, and it works well. It's also very easy to > output to. > Graphine is a flexible, easy-to-use graph library for Python 3. I always knew a day would come when I'd need to use Python 3. And I've been so stupid thinking I could run away from this everlasting misery! Can you give me an example of drawing a simple graph by Graphine? I'm gonna use PyQt as GUI. Doesn't Qt provide any facility for drawing a graph? BTW, I just found this page: http://nodebox.net/code/index.php/Graphing Has anyone tried it out? -- Yours sincerely, Nima Mohammadi From ronyekr at gmail.com Tue Jun 1 14:47:56 2010 From: ronyekr at gmail.com (ekr3d) Date: Tue, 1 Jun 2010 11:47:56 -0700 (PDT) Subject: Fashion serious in 2010 Message-ID: <75912079-0fa1-432e-ad22-e1fb370369b1@e28g2000vbd.googlegroups.com> Man Fashion Week: Z Zegna Spring 2010 Collection fashion-ekramy.blogspot.com/2010/04/man-fashion-week-z-zegna- spring-2010.html From debatem1 at gmail.com Tue Jun 1 14:56:02 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 1 Jun 2010 11:56:02 -0700 Subject: Drawing Multigraphs In-Reply-To: References: Message-ID: On Tue, Jun 1, 2010 at 11:24 AM, Nima wrote: > 2010/6/1 geremy condra >> >> We use Dot in Graphine, and it works well. It's also very easy to >> output to. > > >> Graphine is a flexible, easy-to-use graph library for Python 3. > > I always knew a day would come when I'd need to use Python 3. And I've > been so stupid thinking I could run away from this everlasting misery! > Can you give me an example of drawing a simple graph by Graphine? from graph.base import Graph from graph.extras import dot from subprocess import getstatusoutput # build a circular graph g = Graph(edges=['ab', 'bc', 'cd', 'da']) # build the drawing tool drawer = dot.DotGenerator() # populate the output file with open('graph.dot', 'w') as f: output = drawer.draw(g, "my_graph") f.write(output) # call circo, which will produce the best results here status, output = getstatusoutput("circo -Tgif -o graph.gif -v graph.dot") Geremy Condra From nagle at animats.com Tue Jun 1 15:46:40 2010 From: nagle at animats.com (John Nagle) Date: Tue, 01 Jun 2010 12:46:40 -0700 Subject: MySQLDB - server has gone on blob insertion... In-Reply-To: References: Message-ID: <4c055dbe$0$1634$742ec2ed@news.sonic.net> durumdara wrote: >>> When I tried to start this, I got error: >>> _mysql_exceptions.OperationalError: (2006, 'MySQL server has gone away') Are you by any chance trying to do this on a HostGator account? HostGator servers run a program which kills long MySQL transactions by executing MySQL "KILL" transactions. This is reported to the user as 'MySQL server has gone away' John Nagle From tjreedy at udel.edu Tue Jun 1 17:58:49 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 01 Jun 2010 17:58:49 -0400 Subject: python and filter design: calculating "s" optimal transform In-Reply-To: References: Message-ID: On 6/1/2010 2:18 PM, robert somerville wrote: > Hi; > this is an airy question. > > does anybody have some code or ideas on how to calculate the optimal "S" > transform of user specified order (wanting the coefficients) for a > published filter response curve, ie. > > f(s) = 1.0/(a1*S^2 + a2*S + a3) If you do not get an answer here, try the scipy list. From tjreedy at udel.edu Tue Jun 1 18:06:57 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 01 Jun 2010 18:06:57 -0400 Subject: TypeError: list indices must be integers Message-ID: I got this error twice today while creating lists of lists of complicated stuff. The first time I was puzzled, but the second time I knew that I had just forgotten a comma. If you google this, you will too. Reduced example >>> [[1,2,3] # forgot comma [4,5,6]] Traceback (most recent call last): File "", line 2, in [4,5,6]] TypeError: list indices must be integers, not tuple Terry Jan Reedy From joncle at googlemail.com Tue Jun 1 18:30:50 2010 From: joncle at googlemail.com (Jon Clements) Date: Tue, 1 Jun 2010 15:30:50 -0700 (PDT) Subject: TypeError: list indices must be integers References: Message-ID: On 1 June, 23:06, Terry Reedy wrote: > I got this error twice today > while creating lists of lists > of complicated stuff. > The first time I was puzzled, > but the second time I knew > that I had just forgotten a comma. > If you google this, you will too. > > Reduced example > ?>>> [[1,2,3] # forgot comma > ? ? ? [4,5,6]] > Traceback (most recent call last): > ? ?File "", line 2, in > ? ? ?[4,5,6]] > TypeError: list indices must be integers, not tuple > > Terry Jan Reedy Umm... +1 for poetic effort? Jon. From suganthi.metabyte at gmail.com Tue Jun 1 20:21:08 2010 From: suganthi.metabyte at gmail.com (Suganthi Vincent) Date: Tue, 1 Jun 2010 17:21:08 -0700 (PDT) Subject: Challenging Job Opportunity for a C# Architect/ Developer Message-ID: <0cf8179c-0b8d-4fe0-aace-45f772793b43@11g2000prv.googlegroups.com> Hi My name is Suganthi Vincent and I?m with Metabyte, Inc. I have a challenging Job Opportunity for a C# Architect/ Developer, a 4 months contract to hire opportunity located in Wheeling, IL. Please find the job details. Title: C# Architect/ Developer Location: Wheeling, IL Rates: Market Rate Please find the job description from the Hiring managers desk: 1. Real C# Experience a. I am looking for someone that has actually released a commercial software product that was developed and successfully released into the market. We are developing desktop applications that will run on both Windows XP (Windows 7) and SuSE Linux Enterprise Edition 11. b. I am not looking for someone who merely knows of C# and has read a book or two. c. I am also not interested in anyone that has done web development. If they have, great, but they better have solid desktop application development experience first. 2. Mono Experience a. I really need someone that has experience in writing C# applications for Mono. Just so you know, C# runs on .Net and Mono is an open source software framework that emulates a subset(or part) of .Net, which in turn will allow applications written in C# targeted for Mono to run on many systems that Mono has been ported to, such as: Windows XP and SuSE Linux Enterprise Edition 11. b. Just because someone has written an application in C# and in theory C# applications should run on Mono simply is not true. Mono is a rather small subset of the entire .Net framework and I?ve already gone way beyond the theory stage. I have personally already written applications that run on Mono that in turn run on both Windows XP and SuSE Linux Enterprise Edition 11, so I don?t want to explain how this works during the interview process if you know what I mean. c. There is a very specific area of development that I am looking for and I think these people can be filtered out by using the following criteria: i. If Mono experience is the first hurdle, then someone that has experience with the ?Mono Tools for Visual Studio? is the next hurdle. FM is a Microsoft house. Meaning, the vast majority of software development is done within Microsoft Visual Studio, which in turn is why FM has chosen to use this plug-in for Visual Studio. ii. If you can find someone that has used the plug-in, that is great. The reason why is because we really want someone that has used the ?Debug Remotely on Linux? feature of the ?Mono Tools for Visual Studio? because this is vital for our SuSE Linux development. If interested, please send across your most updated resume along with your expected hourly pay rate at your earliest convenience. Please feel free to contact me. Thanks & Regards, Suganthi Vincent 510 405-1134 (Direct Line) suganthiv at metabyte.com www.metabyte.com Join me at http://www.linkedin.com/in/suganthivincent From sjmachin at lexicon.net Tue Jun 1 20:47:25 2010 From: sjmachin at lexicon.net (John Machin) Date: Tue, 1 Jun 2010 17:47:25 -0700 (PDT) Subject: expat parsing error References: <5bbcadff-449d-465f-b7ff-44790e757c4a@y12g2000vbr.googlegroups.com> <87vda2vp25.fsf@castleamber.com> <47733fad-dc1c-4147-bd91-af9390338e48@o1g2000vbe.googlegroups.com> <87mxvevlgw.fsf@castleamber.com> <5930ecdf-99b2-49d3-b168-db5cb5472411@f13g2000vbm.googlegroups.com> Message-ID: On Jun 2, 1:57?am, "kak... at gmail.com" wrote: > On Jun 1, 11:12?am, "kak... at gmail.com" wrote: > > > > > On Jun 1, 11:09?am, John Bokma wrote: > > > > "kak... at gmail.com" writes: > > > > On Jun 1, 10:34?am, Stefan Behnel wrote: > > > >> kak... at gmail.com, 01.06.2010 16:00: > > > > >> > how can i fix it, how to "ignore" the headers and parse only > > > >> > the XML? > > > > >> Consider reading the answers you got in the last thread that you opened > > > >> with exactly this question. > > > > >> Stefan > > > > > That's exactly, what i did but something seems to not working with the > > > > solutions i had, when i changed my implementation from pure Python's > > > > sockets to twisted library! > > > > That's the reason i have created a new post! > > > > Any ideas why this happened? > > > > As I already explained: if you send your headers as well to any XML > > > parser it will choke on those, because the headers are /not/ valid / > > > well-formed XML. The solution is to remove the headers from your > > > data. As I explained before: headers are followed by one empty > > > line. Just remove lines up and until including the empty line, and pass > > > the data to any XML parser. > > > > -- > > > John Bokma ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? j3b > > > > Hacking & Hiking in Mexico - ?http://johnbokma.com/http://castleamber.com/-Perl& Python Development > > > Thank you so much i'll try it! > > Antonis > > Dear John can you provide me a simple working solution? > I don't seem to get it You're not wrong. Trysomething like this: rubbish1, rubbish2, xml = your_guff.partition('\n\n') From holmes86 at gmail.com Tue Jun 1 21:56:58 2010 From: holmes86 at gmail.com (holmes86) Date: Tue, 1 Jun 2010 18:56:58 -0700 (PDT) Subject: how to generate a csr in python? References: <28e0376b-c612-4944-b383-4064e193bafc@v18g2000vbc.googlegroups.com> Message-ID: <6fef4251-46fb-4401-b836-924032ed7d9b@e6g2000vbm.googlegroups.com> On Jun 1, 3:46?pm, Peter Otten <__pete... at web.de> wrote: > holmes86 wrote: > > On May 31, 7:37 pm, holmes86 wrote: > >> hi,everyone > > >> I want generate a Certificate signing request in python,but I don't > >> how to realize this function.I don't find any method after read the > >> python-openssl manual.Any help will appreciate. > > > nobody? > > Is the createCertRequest() function at > > http://bazaar.launchpad.net/~exarkun/pyopenssl/trunk/annotate/head:/e... > > what you're looking for? > > Peter thanks Peter From rzzzwilson at gmail.com Tue Jun 1 22:44:12 2010 From: rzzzwilson at gmail.com (rzzzwilson) Date: Tue, 1 Jun 2010 19:44:12 -0700 (PDT) Subject: Challenging Job Opportunity for a C# Architect/ Developer References: <0cf8179c-0b8d-4fe0-aace-45f772793b43@11g2000prv.googlegroups.com> Message-ID: <1f968b6b-0c6d-49b3-829a-e9ae3c8746a6@n37g2000prc.googlegroups.com> http://www.catb.org/~esr/faqs/smart-questions.html#forum From pavlovevidence at gmail.com Tue Jun 1 23:09:15 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 1 Jun 2010 20:09:15 -0700 (PDT) Subject: Vote to Add Python Package "pubsub" to the Python Standard Library References: <6b9d2898-4166-40b4-9016-dc55dee77d00@q33g2000vbt.googlegroups.com> Message-ID: On May 26, 4:26?am, Tom wrote: > I vote for adding the Python package "pubsub" to the Python standard > library. ?It has recently been added to wxpython (replacing the old > wx.lib.pubsub package), but it has application to non-gui programs as > well. Well, I can definitely see a case for adding something like this to the standard library. If there is a standard publish-subscribe implementation, then different third-party packages can use it in a consistent way together. It can open whole paradigms of package integration. However, I'm not sure this particular library is the one to use, and I would not be in favor of throwing the first publish-subscribe implentation that comes by into the standard library, at least not without a whole lot of vetting first. (They did that with optparse and the Python community has been paying for it ever since.) I think it has a pretty good chance of being accepted, too. The publish-subscribe pattern, if you will, seems to have been implemented separately in many places. The logging module in the standard library uses something like this. Qt's signal/slot mechanism is another variation. I'm sure there's lots more. I've noticed that pointing out lots of independetnly crafted examples in the wild, and especially in the standard library, works quite well. Carl Banks From marduk at letterboxes.org Tue Jun 1 23:10:01 2010 From: marduk at letterboxes.org (Albert Hopkins) Date: Wed, 02 Jun 2010 03:10:01 +0000 Subject: Challenging Job Opportunity for a C# Architect/ Developer In-Reply-To: <1f968b6b-0c6d-49b3-829a-e9ae3c8746a6@n37g2000prc.googlegroups.com> References: <0cf8179c-0b8d-4fe0-aace-45f772793b43@11g2000prv.googlegroups.com> <1f968b6b-0c6d-49b3-829a-e9ae3c8746a6@n37g2000prc.googlegroups.com> Message-ID: <1275448201.8024.0.camel@paska> On Tue, 2010-06-01 at 19:44 -0700, rzzzwilson wrote: > http://www.catb.org/~esr/faqs/smart-questions.html#forum werd. From psdasilva.nospam at netcabonospam.pt Tue Jun 1 23:48:15 2010 From: psdasilva.nospam at netcabonospam.pt (Paulo da Silva) Date: Wed, 02 Jun 2010 04:48:15 +0100 Subject: Converting a pickle to python3 Message-ID: <4c05d47e$0$31524$a729d347@news.telepac.pt> Hi! I have a big data structure cpickled into a datafile, by python2. I tried to unpickle it using python3 but got the followin message: File "/usr/lib64/python3.1/pickle.py", line 1372, in loads encoding=encoding, errors=errors).load() _pickle.UnpicklingError: invalid load key, 'x'. Is there a way to "stream" a class in python2 and then get it back in python3? Thanks for any help/comments. From fetchinson at googlemail.com Wed Jun 2 00:29:44 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 2 Jun 2010 06:29:44 +0200 Subject: Vote to Add Python Package "pubsub" to the Python Standard Library In-Reply-To: <6b9d2898-4166-40b4-9016-dc55dee77d00@q33g2000vbt.googlegroups.com> References: <6b9d2898-4166-40b4-9016-dc55dee77d00@q33g2000vbt.googlegroups.com> Message-ID: > I vote for adding the Python package "pubsub" to the Python standard > library. It has recently been added to wxpython (replacing the old > wx.lib.pubsub package), but it has application to non-gui programs as > well. > > For more information see: . If you are really interested in this the minimum would be following these steps: 1. discuss various publish-subscribe API variants on python-list (aka c.l.p) 2. when you got tons of feedback summarize the discussion on python-dev 3. tons of feedback will follow and try to converge on a consensus concerning the API 4. write a PEP 5. produce an implementation (or get someone to do it) 6. add the implementation to the PEP 7. lobby for acceptance of the PEP A good example for the first couple of stages of this process is PEP 3143 concerning adding a daemon package to the stdlib: http://www.python.org/dev/peps/pep-3143/ I haven't found the beginning of the thread discussing this but you can start for example here: http://mail.python.org/pipermail/python-list/2009-March/1197808.html Good luck, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From michele.simionato at gmail.com Wed Jun 2 00:37:13 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Tue, 1 Jun 2010 21:37:13 -0700 (PDT) Subject: plac, the easiest command line arguments parser in the world Message-ID: <1d09462d-3de1-4e40-8cc7-c45e18cf0ffd@m4g2000vbl.googlegroups.com> I would like to announce to the world the first public release of plac: http://pypi.python.org/pypi/plac Plac is a wrapper over argparse and works in all versions of Python starting from Python 2.3 up to Python 3.1. With blatant immodesty, plac claims to be the easiest to use command line arguments parser module in the Python world. Its goal is to reduce the learning curve of argparse from hours to minutes. It does so by removing the need to build a command line arguments parser by hand: actually it is smart enough to infer the parser from function annotations. Here is a simple example (in Python 3) to wet your appetite: $ cat example.py def main(arg: "required argument"): "do something with arg" print('Got %s' % arg) if __name__ == '__main__': import plac; plac.call(main) # passes sys.argv[1:] to main $ python example.py -h usage: example.py [-h] arg do something with arg positional arguments: arg required argument optional arguments: -h, --help show this help message and exit $ python example.py usage: example.py [-h] arg example.py: error: too few arguments $ python example.py arg Got arg $ python example.py arg1 arg2 usage: example.py [-h] arg example.py: error: unrecognized arguments: arg2 You can find in the documentation a lot of other simple and not so simple examples: http://micheles.googlecode.com/hg/plac/doc/plac.html Enjoy! Michele Simionato P.S. answering an unspoken question: yes, we really needed yet another command line arguments parser! ;) From nagle at animats.com Wed Jun 2 01:40:52 2010 From: nagle at animats.com (John Nagle) Date: Tue, 01 Jun 2010 22:40:52 -0700 Subject: Python vs. Fedora and CentOS In-Reply-To: References: <4c015aa9$0$1617$742ec2ed@news.sonic.net> <3RMMn.125235$y07.3938@news.usenetserver.com> Message-ID: <4c05e903$0$1655$742ec2ed@news.sonic.net> Michael Torrie wrote: > On 05/31/2010 05:13 AM, Jason D wrote: >> There is however never been an issue to locate different version of python >> in your system as you deem fit without problems. >> So I dont understand why your concern. > > Actually, replacing python on RHEL is a major endeavor. Almost all Red > Hat utilities are written in python and depend on the specific system > version of python that they shipped. Thus if you want to upgrade python > you're going to break 80% of the system. > > Sure you can install Python from source alongside the system python, but > that's a maintenance nightmare for system administrators. There's something to be said for having all versions of Python installed as "python2.4", "python2.6", "python3.1", etc., with the name "python" simply being a link to the favored version. Maybe that should be the default. The Python Windows installers already work that way; they create "\python26", etc. directories. The Linux installers, by default, want to install as "python". Add-on RPMs should be set up for versioned install. Then you can safely install alternate versions. I gather that "iuscommunity.org" distributions do something like this. John Nagle From johntywang at gmail.com Wed Jun 2 02:43:33 2010 From: johntywang at gmail.com (johnty) Date: Tue, 1 Jun 2010 23:43:33 -0700 (PDT) Subject: signed vs unsigned int Message-ID: i'm reading bytes from a serial port, and storing it into an array. each byte represents a signed 8-bit int. currently, the code i'm looking at converts them to an unsigned int by doing ord(array[i]). however, what i'd like is to get the _signed_ integer value. whats the easiest way to do this? thanks in advance. johnty From kaklis at gmail.com Wed Jun 2 03:00:59 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Wed, 2 Jun 2010 00:00:59 -0700 (PDT) Subject: expat parsing error References: <5bbcadff-449d-465f-b7ff-44790e757c4a@y12g2000vbr.googlegroups.com> <87vda2vp25.fsf@castleamber.com> <47733fad-dc1c-4147-bd91-af9390338e48@o1g2000vbe.googlegroups.com> <87mxvevlgw.fsf@castleamber.com> <5930ecdf-99b2-49d3-b168-db5cb5472411@f13g2000vbm.googlegroups.com> Message-ID: <7b1ff3f1-0559-4550-bcb2-15e4a964f1cd@a20g2000vbc.googlegroups.com> On 2 ????, 03:47, John Machin wrote: > On Jun 2, 1:57?am, "kak... at gmail.com" wrote: > > > > > > > On Jun 1, 11:12?am, "kak... at gmail.com" wrote: > > > > On Jun 1, 11:09?am, John Bokma wrote: > > > > > "kak... at gmail.com" writes: > > > > > On Jun 1, 10:34?am, Stefan Behnel wrote: > > > > >> kak... at gmail.com, 01.06.2010 16:00: > > > > > >> > how can i fix it, how to "ignore" the headers and parse only > > > > >> > the XML? > > > > > >> Consider reading the answers you got in the last thread that you opened > > > > >> with exactly this question. > > > > > >> Stefan > > > > > > That's exactly, what i did but something seems to not working with the > > > > > solutions i had, when i changed my implementation from pure Python's > > > > > sockets to twisted library! > > > > > That's the reason i have created a new post! > > > > > Any ideas why this happened? > > > > > As I already explained: if you send your headers as well to any XML > > > > parser it will choke on those, because the headers are /not/ valid / > > > > well-formed XML. The solution is to remove the headers from your > > > > data. As I explained before: headers are followed by one empty > > > > line. Just remove lines up and until including the empty line, and pass > > > > the data to any XML parser. > > > > > -- > > > > John Bokma ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? j3b > > > > > Hacking & Hiking in Mexico - ?http://johnbokma.com/http://castleamber.com/-Perl&Python Development > > > > Thank you so much i'll try it! > > > Antonis > > > Dear John can you provide me a simple working solution? > > I don't seem to get it > > You're not wrong. Trysomething like this: > > rubbish1, rubbish2, xml = your_guff.partition('\n\n') Ok thanks a lot! Antonis From stefan_ml at behnel.de Wed Jun 2 03:01:55 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 02 Jun 2010 09:01:55 +0200 Subject: signed vs unsigned int In-Reply-To: References: Message-ID: johnty, 02.06.2010 08:43: > i'm reading bytes from a serial port, and storing it into an array. > > each byte represents a signed 8-bit int. > > currently, the code i'm looking at converts them to an unsigned int by > doing ord(array[i]). however, what i'd like is to get the _signed_ > integer value. whats the easiest way to do this? See the struct module, it supports various different C types. Stefan From steve-REMOVE-THIS at cybersource.com.au Wed Jun 2 03:03:27 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 02 Jun 2010 07:03:27 GMT Subject: signed vs unsigned int References: Message-ID: <4c06023e$0$14133$c3e8da3@news.astraweb.com> On Tue, 01 Jun 2010 23:43:33 -0700, johnty wrote: > i'm reading bytes from a serial port, and storing it into an array. An array or a list? > each byte represents a signed 8-bit int. > > currently, the code i'm looking at converts them to an unsigned int by > doing ord(array[i]). however, what i'd like is to get the _signed_ > integer value. whats the easiest way to do this? >>> import array >>> s = 'Some unsigned bytes \xc3\x80\xc3\xa0\xc3\xa6\xc3\x9f\xc2\xb5' >>> array.array('b', s) array('b', [83, 111, 109, 101, 32, 117, 110, 115, 105, 103, 110, 101, 100, 32, 98, 121, 116, 101, 115, 32, -61, -128, -61, -96, -61, -90, -61, -97, -62, -75]) See also the fromstring method of array objects. -- Steven From lists at cheimes.de Wed Jun 2 03:04:59 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 02 Jun 2010 09:04:59 +0200 Subject: signed vs unsigned int In-Reply-To: References: Message-ID: > i'm reading bytes from a serial port, and storing it into an array. > > each byte represents a signed 8-bit int. > > currently, the code i'm looking at converts them to an unsigned int by > doing ord(array[i]). however, what i'd like is to get the _signed_ > integer value. whats the easiest way to do this? http://docs.python.org/library/struct.html From johntywang at gmail.com Wed Jun 2 03:32:55 2010 From: johntywang at gmail.com (johnty) Date: Wed, 2 Jun 2010 00:32:55 -0700 (PDT) Subject: signed vs unsigned int References: Message-ID: <68c95dfd-6652-474b-861a-15cac6b11cf9@g1g2000pro.googlegroups.com> On Jun 2, 12:04?am, Christian Heimes wrote: > > i'm reading bytes from a serial port, and storing it into an array. > > > each byte represents a signed 8-bit int. > > > currently, the code i'm looking at converts them to an unsigned int by > > doing ord(array[i]). however, what i'd like is to get the _signed_ > > integer value. whats the easiest way to do this? > > http://docs.python.org/library/struct.html the struct docs is exactly what i needed to read. "unpacking" it as a signed char did the trick. thanks guys! From einars.strauss at gmail.com Wed Jun 2 04:04:56 2010 From: einars.strauss at gmail.com (pyDev) Date: Wed, 2 Jun 2010 01:04:56 -0700 (PDT) Subject: Python Forum Message-ID: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> Hello, I would like to let the community know that there is a new web-based forum for Python enthusiasts over at PythonForum.org (http:// pythonforum.org). Web-based forums is a preferred method by Python newcomers to get help in exploring the world of Python and programming overall. The main goal of PythonForum.org is to popularize Python by welcoming all newcomers. Recently the forum got "attacked" with questions by users just starting out with Python. I hope here will be someone ready to welcome and help newcomers to enter the beautiful world of Python. Thank you, Einars From bv.tryton at gmail.com Wed Jun 2 04:24:13 2010 From: bv.tryton at gmail.com (B.V.) Date: Wed, 2 Jun 2010 01:24:13 -0700 (PDT) Subject: Mixing Decimal and float Message-ID: Hi, In order to solve some issues due to operations between Decimal and float, we wanted to implement a class that inherits from both float and Decimal. Typically, we wrote: class Float(Decimal, float): ... This can not be achieved because of a TypeError exception (with message "multiple bases have instance lay-out conflict"). With a class that inherits from Decimal, with overridden __add__, __mul__, .... , we succeed to solve operations issues. But we also need to do: isinstance(Float('1'), float) == True isinstance(Float('1'), Decimal) == True which is, AFAIK, only possible with Float(Decimal, float). Is there a workaround ? We are developping with python version 2.5 and 2.6. Thanks for your help. B. From simon at brunningonline.net Wed Jun 2 04:28:02 2010 From: simon at brunningonline.net (Simon Brunning) Date: Wed, 2 Jun 2010 09:28:02 +0100 Subject: Python Forum In-Reply-To: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> Message-ID: On 2 June 2010 09:04:56 UTC+1, pyDev wrote: > I hope here will be > someone ready to welcome and help newcomers to enter the beautiful > world of Python. Just send them here, or to . We'll be happy to help. -- Cheers, Simon B. From mail at timgolden.me.uk Wed Jun 2 04:28:24 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 02 Jun 2010 09:28:24 +0100 Subject: plac, the easiest command line arguments parser in the world In-Reply-To: <1d09462d-3de1-4e40-8cc7-c45e18cf0ffd@m4g2000vbl.googlegroups.com> References: <1d09462d-3de1-4e40-8cc7-c45e18cf0ffd@m4g2000vbl.googlegroups.com> Message-ID: <4C061628.8070601@timgolden.me.uk> On 02/06/2010 05:37, Michele Simionato wrote: > I would like to announce to the world the first public release of > plac: > > http://pypi.python.org/pypi/plac > > Plac is a wrapper over argparse and works in all versions of > Python starting from Python 2.3 up to Python 3.1. I like it. I'm a constant user of the def main (a, b=1, c=2): # ... if __name__ == '__main__': main (*sys.argv[1:]) pattern, which provides a minimally semi-self-documenting approach for positional args, but I've always found the existing offerings just a little too much work to bother with. I'll give plac a run and see how it behaves. Thanks TJG From stefan_ml at behnel.de Wed Jun 2 04:30:10 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 02 Jun 2010 10:30:10 +0200 Subject: Python Forum In-Reply-To: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> Message-ID: pyDev, 02.06.2010 10:04: > I would like to let the community know that there is a new web-based > forum for Python enthusiasts over at PythonForum.org (http:// > pythonforum.org). Web-based forums is a preferred method by Python > newcomers to get help in exploring the world of Python and programming > overall. It's not how the English speaking community works, though. There are two main mailing lists (mirrored as/from newsgroups) around which the larger community gathers: python-list (c.l.py) and python-tutor. I doubt (or rather put my hope against it) that a forum will attract a critical mass of Python cracks to make it attractive to newbees, and I would certainly prefer an effort to get them into joining python-tutor instead. There is not much to gain from splitting the community. Stefan From no.email at nospam.invalid Wed Jun 2 04:43:20 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 02 Jun 2010 01:43:20 -0700 Subject: plac, the easiest command line arguments parser in the world References: <1d09462d-3de1-4e40-8cc7-c45e18cf0ffd@m4g2000vbl.googlegroups.com> Message-ID: <7xtyplomdz.fsf@ruckus.brouhaha.com> Tim Golden writes: > pattern, which provides a minimally semi-self-documenting > approach for positional args, but I've always found the existing > offerings just a little too much work to bother with. > I'll give plac a run and see how it behaves. After using optparse a couple of times I got the hang of it. Maybe its docs could be organized a bit better, but it does the obvious things conveniently once you've figured it out a bit. From bruno.42.desthuilliers at websiteburo.invalid Wed Jun 2 04:44:28 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 02 Jun 2010 10:44:28 +0200 Subject: Python Forum In-Reply-To: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> Message-ID: <4c0619e7$0$24606$426a74cc@news.free.fr> pyDev a ?crit : > Hello, > > I would like to let the community know that there is a new web-based > forum for Python enthusiasts over at PythonForum.org (http:// > pythonforum.org). YetAnotherUselessWebForum :( > Web-based forums is a preferred method by Python > newcomers to get help Oh yeah ? Chapter and verse, please ? Do the world a favour : replace your whole forum with a static page explaining how to join the "official" MLs and/or c.l.py. > in exploring the world of Python and programming > overall. The main goal of PythonForum.org is to popularize Python by > welcoming all newcomers. Newcomers have always been welcomed here. And yet another forum *where the helpful experts won't post nor correct wrong posts* is certainly not the best way to "popularize" Python. From ben+python at benfinney.id.au Wed Jun 2 04:45:49 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 02 Jun 2010 18:45:49 +1000 Subject: Vote to Add Python Package "pubsub" to the Python Standard Library References: <6b9d2898-4166-40b4-9016-dc55dee77d00@q33g2000vbt.googlegroups.com> Message-ID: <87y6exesaq.fsf@benfinney.id.au> Daniel Fetchinson writes: > A good example for the first couple of stages of this process is PEP > 3143 concerning adding a daemon package to the stdlib: > http://www.python.org/dev/peps/pep-3143/ Thanks for the shout-out for PEP 3143. I can certainly say that the process Daniel describes was a very healthy one for the development of the API in that specification. Trimming the fat from the implementation, and delegating concerns outside the specification, was a major benefit of going through that public discussion process. The PEP 3143 reference implementation has a lot of happy users, who are making use of the API to perform the tasks they need. Once I complete the extraction of dependencies, I'll be submitting the resulting code for inclusion in the standard library. > I haven't found the beginning of the thread discussing this For the process you outline, the thread where I began soliciting feedback of the ?what's the best way to do this?? kind begins at . Some later threads gave me a better idea what was required and what was possible. While making a reference implementation, I drafted a PEP to describe the interface I wanted the standard library to provide. Once I had it in good shape, and had a reference implementation ready, I submitted it and it was registered as PEP 3143. The first PEP 3143 discussion thread starts at . Once I had incorporated a lot of the feedback, I fished again with . It's annoying that many threads get broken because of poor transmission of message references. You'll need to browse manually to get more complete versions of some of the thread. From michele.simionato at gmail.com Wed Jun 2 04:49:18 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 2 Jun 2010 01:49:18 -0700 (PDT) Subject: plac, the easiest command line arguments parser in the world References: <1d09462d-3de1-4e40-8cc7-c45e18cf0ffd@m4g2000vbl.googlegroups.com> <7xtyplomdz.fsf@ruckus.brouhaha.com> Message-ID: On Jun 2, 10:43?am, Paul Rubin wrote: > Tim Golden writes: > > pattern, which provides a minimally semi-self-documenting > > approach for positional args, but I've always found the existing > > offerings just a little too much work to bother with. > > I'll give plac a run and see how it behaves. > > After using optparse a couple of times I got the hang of it. ?Maybe its > docs could be organized a bit better, but it does the obvious things > conveniently once you've figured it out a bit. Notice that optparse is basically useless in the use case Tim is considering (positional arguments) since it only manages options. From jeanmichel at sequans.com Wed Jun 2 04:52:16 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 02 Jun 2010 10:52:16 +0200 Subject: plac, the easiest command line arguments parser in the world In-Reply-To: <1d09462d-3de1-4e40-8cc7-c45e18cf0ffd@m4g2000vbl.googlegroups.com> References: <1d09462d-3de1-4e40-8cc7-c45e18cf0ffd@m4g2000vbl.googlegroups.com> Message-ID: <4C061BC0.9080509@sequans.com> Michele Simionato wrote: > I would like to announce to the world the first public release of > plac: > > http://pypi.python.org/pypi/plac > > Plac is a wrapper over argparse and works in all versions of > Python starting from Python 2.3 up to Python 3.1. > > With blatant immodesty, plac claims to be the easiest to use command > line arguments parser module in the Python world. Its goal is to > reduce the > learning curve of argparse from hours to minutes. It does so by > removing the need to build a command line arguments parser by hand: > actually it is smart enough to infer the parser from function > annotations. > > Here is a simple example (in Python 3) to wet your appetite: > > $ cat example.py > def main(arg: "required argument"): > "do something with arg" > print('Got %s' % arg) > > if __name__ == '__main__': > import plac; plac.call(main) # passes sys.argv[1:] to main > > $ python example.py -h > usage: example.py [-h] arg > > do something with arg > > positional arguments: > arg required argument > > optional arguments: > -h, --help show this help message and exit > > > $ python example.py > usage: example.py [-h] arg > example.py: error: too few arguments > > $ python example.py arg > Got arg > > $ python example.py arg1 arg2 > usage: example.py [-h] arg > example.py: error: unrecognized arguments: arg2 > > You can find in the documentation a lot of other simple and not so > simple > examples: > > http://micheles.googlecode.com/hg/plac/doc/plac.html > > > Enjoy! > > Michele Simionato > > P.S. answering an unspoken question: yes, we really needed yet > another > command line arguments parser! ;) > Thanks for participating. JM From R.Brodie at rl.ac.uk Wed Jun 2 04:52:50 2010 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Wed, 2 Jun 2010 09:52:50 +0100 Subject: Drawing Multigraphs References: Message-ID: "geremy condra" wrote in message news:mailman.825.1275414239.32709.python-list at python.org... > On Tue, Jun 1, 2010 at 9:42 AM, Nima wrote: >> Hi there, >> Is it possible to draw an (undirected) multigraph using a python library? >> I need to write a program that finds an Eulerian circuit in a graph >> (which might obviously be a multigraph). As the output of the program, >> I should draw the graph and print out the solution. > > We use Dot in Graphine, and it works well. It's also very easy to > output to. NetworkX apparently has dot bindings built-in, although I've not used it, so I think one should just be able to export to it. From stefan_ml at behnel.de Wed Jun 2 05:01:24 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 02 Jun 2010 11:01:24 +0200 Subject: plac, the easiest command line arguments parser in the world In-Reply-To: <7xtyplomdz.fsf@ruckus.brouhaha.com> References: <1d09462d-3de1-4e40-8cc7-c45e18cf0ffd@m4g2000vbl.googlegroups.com> <7xtyplomdz.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin, 02.06.2010 10:43: > Tim Golden writes: >> pattern, which provides a minimally semi-self-documenting >> approach for positional args, but I've always found the existing >> offerings just a little too much work to bother with. >> I'll give plac a run and see how it behaves. > > After using optparse a couple of times I got the hang of it. Maybe its > docs could be organized a bit better, but it does the obvious things > conveniently once you've figured it out a bit. Same from here. I managed to talk a Java-drilled collegue of mine into writing a Python script for a little command line utility, but he needed a way to organise his argument extraction code when the number of arguments started to grow beyond two. I told him that there were two ways to do it: do it by hand or do it right. He took the right choice and I took him to the optparse docs, copied the first example into his code and we adapted it a little. He just loved the beauty of it. Stefan From michele.simionato at gmail.com Wed Jun 2 05:14:22 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 2 Jun 2010 02:14:22 -0700 (PDT) Subject: plac, the easiest command line arguments parser in the world References: <1d09462d-3de1-4e40-8cc7-c45e18cf0ffd@m4g2000vbl.googlegroups.com> <7xtyplomdz.fsf@ruckus.brouhaha.com> Message-ID: <97e59251-93ee-4d5e-afb9-4e058ef3cd04@c22g2000vbb.googlegroups.com> On Jun 2, 11:01?am, Stefan Behnel wrote: > I managed to talk a Java-drilled collegue of mine into > writing a Python script for a little command line utility, but he needed a > way to organise his argument extraction code when the number of arguments > started to grow beyond two. I told him that there were two ways to do it: > do it by hand or do it right. He took the right choice and I took him to > the optparse docs, copied the first example into his code and we adapted it > a little. He just loved the beauty of it. Could you show plac to your friend? I would be curious to know what he think. Perhaps he would call out his judgment on optparse ;) From gabriele.lanaro at gmail.com Wed Jun 2 05:27:48 2010 From: gabriele.lanaro at gmail.com (Gabriele Lanaro) Date: Wed, 2 Jun 2010 11:27:48 +0200 Subject: Vote to Add Python Package "pubsub" to the Python Standard Library In-Reply-To: References: <6b9d2898-4166-40b4-9016-dc55dee77d00@q33g2000vbt.googlegroups.com> Message-ID: I definitvely vote for adding such a package to the stdlib (or at least a symilar publish/subscrive and observer implementation). It's useful in a wide range of programs. 2010/6/2 Carl Banks > On May 26, 4:26 am, Tom wrote: > > I vote for adding the Python package "pubsub" to the Python standard > > library. It has recently been added to wxpython (replacing the old > > wx.lib.pubsub package), but it has application to non-gui programs as > > well. > > > Well, I can definitely see a case for adding something like this to > the standard library. If there is a standard publish-subscribe > implementation, then different third-party packages can use it in a > consistent way together. It can open whole paradigms of package > integration. > > However, I'm not sure this particular library is the one to use, and I > would not be in favor of throwing the first publish-subscribe > implentation that comes by into the standard library, at least not > without a whole lot of vetting first. (They did that with optparse > and the Python community has been paying for it ever since.) > > I think it has a pretty good chance of being accepted, too. The > publish-subscribe pattern, if you will, seems to have been implemented > separately in many places. The logging module in the standard library > uses something like this. Qt's signal/slot mechanism is another > variation. I'm sure there's lots more. I've noticed that pointing > out lots of independetnly crafted examples in the wild, and especially > in the standard library, works quite well. > > > Carl Banks > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From awilliam at whitemice.org Wed Jun 2 06:18:31 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Wed, 02 Jun 2010 06:18:31 -0400 Subject: Python Forum In-Reply-To: <4c0619e7$0$24606$426a74cc@news.free.fr> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c0619e7$0$24606$426a74cc@news.free.fr> Message-ID: <1275473911.16547.2.camel@linux-yu4c.site> On Wed, 2010-06-02 at 10:44 +0200, Bruno Desthuilliers wrote: > pyDev a ?crit : > > Hello, > > I would like to let the community know that there is a new web-based > > forum for Python enthusiasts over at PythonForum.org (http:// > > pythonforum.org). > YetAnotherUselessWebForum :( +1 Yuck; no better way to make new users hate your product than have a web forum - where they post questions.... and never get answers... because the people with the answers are over on the much-easier-to-use mailist [what an awesome feature: the questions just show up in my INBOX! Sweet.]. > > Web-based forums is a preferred method by Python > > newcomers to get help > Oh yeah ? Chapter and verse, please > Do the world a favour : replace your whole forum with a static page > explaining how to join the "official" MLs and/or c.l.py. > > in exploring the world of Python and programming > > overall. The main goal of PythonForum.org is to popularize Python by > > welcoming all newcomers. > Newcomers have always been welcomed here. And yet another forum *where > the helpful experts won't post nor correct wrong posts* is certainly not > the best way to "popularize" Python. +1 -- Adam Tauno Williams LPIC-1, Novell CLA OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba From dickinsm at gmail.com Wed Jun 2 06:22:11 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 2 Jun 2010 03:22:11 -0700 (PDT) Subject: Mixing Decimal and float References: Message-ID: <413efca9-ec02-4f84-8bef-688d50a65953@f14g2000vbn.googlegroups.com> On Jun 2, 9:24?am, "B.V." wrote: > Hi, > > In order to solve some issues due to operations between Decimal and > float, we wanted to implement a class that inherits from both float > and Decimal. > > Typically, we wrote: > > class Float(Decimal, float): Can you explain exactly what issues you want to solve, and how you want your Float class to behave? Do I understand correctly that you want your Float class to be able to represent both floats and Decimals? > But we also need to do: > isinstance(Float('1'), float) == True > isinstance(Float('1'), Decimal) == True Can you explain why you need this? Should isinstance(Float('1.1'), float) and isinstance(Float('1.1'), Decimal) also both be true, or would only one of those be true? (And by the way, what value would Float('1.1') have? float('1.1') and Decimal('1.1') are different values.) I don't think your approach can succeed; I'd suggest just subclassing 'object' and abandoning the 'isinstance' requirements. Or perhaps creating a subclass of Decimal that interacts nicely with floats. You might also want to investigate the numbers ABC, though that's new in Python 2.6. -- Mark From solipsis at pitrou.net Wed Jun 2 06:42:01 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 2 Jun 2010 12:42:01 +0200 Subject: optional optional args vs optional positional options References: <1d09462d-3de1-4e40-8cc7-c45e18cf0ffd@m4g2000vbl.googlegroups.com> <7xtyplomdz.fsf@ruckus.brouhaha.com> Message-ID: <20100602124201.276c39c6@pitrou.net> On Wed, 2 Jun 2010 01:49:18 -0700 (PDT) Michele Simionato wrote: > > Notice that optparse is basically useless in the use case Tim is > considering (positional arguments) since it only manages options. By the way, could you stop naming these "optional arguments", since positional arguments can be optional as well? It is confusing :) Thanks Antoine. From mail at timgolden.me.uk Wed Jun 2 06:51:59 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 02 Jun 2010 11:51:59 +0100 Subject: optional optional args vs optional positional options In-Reply-To: <20100602124201.276c39c6@pitrou.net> References: <1d09462d-3de1-4e40-8cc7-c45e18cf0ffd@m4g2000vbl.googlegroups.com> <7xtyplomdz.fsf@ruckus.brouhaha.com> <20100602124201.276c39c6@pitrou.net> Message-ID: <4C0637CF.6090608@timgolden.me.uk> On 02/06/2010 11:42, Antoine Pitrou wrote: > On Wed, 2 Jun 2010 01:49:18 -0700 (PDT) > Michele Simionato wrote: >> >> Notice that optparse is basically useless in the use case Tim is >> considering (positional arguments) since it only manages options. > > By the way, could you stop naming these "optional arguments", since > positional arguments can be optional as well? It is confusing :) The great thing with English is that you can use nouns as adjectives without changing them, so you can say "option arguments" and "position arguments" quite happily here :) But then you run into the fact that you're having semantic arguments about argument semantics :( TJG From sjmachin at lexicon.net Wed Jun 2 07:25:49 2010 From: sjmachin at lexicon.net (John Machin) Date: Wed, 2 Jun 2010 04:25:49 -0700 (PDT) Subject: signed vs unsigned int References: Message-ID: On Jun 2, 4:43?pm, johnty wrote: > i'm reading bytes from a serial port, and storing it into an array. > > each byte represents a signed 8-bit int. > > currently, the code i'm looking at converts them to an unsigned int by > doing ord(array[i]). however, what i'd like is to get the _signed_ > integer value. whats the easiest way to do this? signed = unsigned if unsigned <= 127 else unsigned - 256 From victorsubervi at gmail.com Wed Jun 2 08:02:40 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 2 Jun 2010 08:02:40 -0400 Subject: Opinion On Best Way... Message-ID: Hi; I have a script in which I currently pass a number of variables to another script through the url in a meta http-equiv tag. This seems both awkward and hackable. I think it would be best to create a temporary mysql table, insert them there, and pull them from the following script. The situation is where a purchaser places an item in my shopping cart. A script is called that simply pushes the data to the cart script. The reason for this step is to ensure that when the cart script calls itself (in the form tag) through an update to either update or delete items, the last cached items aren't re-added to the shopping cart. What are your thoughts on the best way to preserve the data from script to script? TIA. beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From bv.tryton at gmail.com Wed Jun 2 08:17:11 2010 From: bv.tryton at gmail.com (B.V.) Date: Wed, 2 Jun 2010 05:17:11 -0700 (PDT) Subject: Mixing Decimal and float References: <413efca9-ec02-4f84-8bef-688d50a65953@f14g2000vbn.googlegroups.com> Message-ID: <4322c313-d32a-4c3f-bd91-a0f1694693cf@o12g2000vba.googlegroups.com> On Jun 2, 12:22?pm, Mark Dickinson wrote: > On Jun 2, 9:24?am, "B.V." wrote: > > > Hi, > > > In order to solve some issues due to operations between Decimal and > > float, we wanted to implement a class that inherits from both float > > and Decimal. > > > Typically, we wrote: > > > class Float(Decimal, float): > > Can you explain exactly what issues you want to solve, and how you > want your Float class to behave? ?Do I understand correctly that you > want your Float class to be able to represent both floats and > Decimals? Let me give you the whole story. We work on Tryton, an client/server application framework written in Python (http://www.tryton.org). The framework defines several types of fields within its own ORM (http://doc.tryton.org/1.6/trytond/doc/ref/models/fields.html#ref- models-fields); among those types, there's a fields.Float type -- not to be confused with the class Float we are talking about -- (with underlying python type float) and fields.Numeric (with underlying python type Decimal). fields.Numeric(Decimal) where implemented at the beginning of the fork (Tryton is a fork of OpenERP, formerly known as TinyERP), because the use of floats in OpenERP leads many problems in module handling financial data. The client is written in pygtk. The client connects the server through a specific (but simple) protocol called pysocket (roughly pickled data over sockets). In an application, you may define objects with both Numeric or Float attributes, and when you need to make them interact, you have to cast. And everything is fine. But trying to be open to other languages, the server implements also an XMLRPC interface (and also a JSONRPC-like interface). That's the key point: Decimal is python specific. So in an application, you can't rely on the value received from a client, because depending on the protocol, the type of the value is different. So the idea was to create a class that can behave like a Decimal or a float depending on the context, and set xmlrpclib.Unmarshaller.dispatch["double"] to a function that return a Float instance. A contributor filed an issue on the bug tracker (https:// bugs.tryton.org/roundup/issue1575) and because he's a nice guy (ok it's a friend of mine), he made a patch proposal (http:// codereview.appspot.com/1387041). The end of the story is in the comments of the proposal. > > > But we also need to do: > > isinstance(Float('1'), float) == True > > isinstance(Float('1'), Decimal) == True > > Can you explain why you need this? It's a requirement of the project leader. > > Should isinstance(Float('1.1'), float) and isinstance(Float('1.1'), > Decimal) also both be true, or would only one of those be true? ?(And > by the way, what value would Float('1.1') have? ?float('1.1') and > Decimal('1.1') are different values.) I think they both should be True, for '1', '1.1', '0', '0.1', ... For the value, I would say that it depends of the definition of the field (fields.Float or fields.Numeric). > > I don't think your approach can succeed; ?I'd suggest just subclassing > 'object' and abandoning the 'isinstance' requirements. ?Or perhaps > creating a subclass of Decimal that interacts nicely with floats. ?You > might also want to investigate the numbers ABC, though that's new in > Python 2.6. First, Float implementation was a subclass of Decimal that works with floats, and solves many (maybe all) problems. But as you may read in the comments of the patch proposal, it seems to be not enough. B. From eckhardt at satorlaser.com Wed Jun 2 08:20:35 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Wed, 02 Jun 2010 14:20:35 +0200 Subject: functools.wraps and help() Message-ID: Hi! When I use help() on a function, it displays the arguments of the function, along with the docstring. However, when wrapping the function using functools.wraps it only displays the arguments that the (internal) wrapper function takes, which is typically "*args, **kwargs", which isn't very useful. Any suggestions how to fix that? Is that even a bug or a systematic limitation? In case of the latter, should the documentation for functools.wraps mention it? Cheers! Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From michele.simionato at gmail.com Wed Jun 2 08:47:40 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 2 Jun 2010 05:47:40 -0700 (PDT) Subject: functools.wraps and help() References: Message-ID: <620795ce-c18b-40e1-87e1-479f70d9a110@q8g2000vbm.googlegroups.com> On Jun 2, 2:20?pm, Ulrich Eckhardt wrote: > Hi! > > When I use help() on a function, it displays the arguments of the function, > along with the docstring. However, when wrapping the function using > functools.wraps it only displays the arguments that the (internal) wrapper > function takes, which is typically "*args, **kwargs", which isn't very > useful. > > Any suggestions how to fix that? Is that even a bug or a systematic > limitation? In case of the latter, should the documentation for > functools.wraps mention it? See http://pypi.python.org/pypi/decorator From jcd at sdf.lonestar.org Wed Jun 2 09:06:20 2010 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Wed, 02 Jun 2010 09:06:20 -0400 Subject: optional optional args vs optional positional options In-Reply-To: <20100602124201.276c39c6@pitrou.net> References: <1d09462d-3de1-4e40-8cc7-c45e18cf0ffd@m4g2000vbl.googlegroups.com> <7xtyplomdz.fsf@ruckus.brouhaha.com> <20100602124201.276c39c6@pitrou.net> Message-ID: <1275483980.2080.1.camel@jcdyer-laptop> +1 Options are options, arguments are arguments. An optional argument is not an option. It is an argument that can be left out. On Wed, 2010-06-02 at 12:42 +0200, Antoine Pitrou wrote: > On Wed, 2 Jun 2010 01:49:18 -0700 (PDT) > Michele Simionato wrote: > > > > Notice that optparse is basically useless in the use case Tim is > > considering (positional arguments) since it only manages options. > > By the way, could you stop naming these "optional arguments", since > positional arguments can be optional as well? It is confusing :) > > Thanks > > Antoine. > > From michele.simionato at gmail.com Wed Jun 2 09:46:07 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 2 Jun 2010 06:46:07 -0700 (PDT) Subject: plac, the easiest command line arguments parser in the world References: <1d09462d-3de1-4e40-8cc7-c45e18cf0ffd@m4g2000vbl.googlegroups.com> Message-ID: <4ad5afd9-feab-48cb-a471-826d0bc4d007@z17g2000vbd.googlegroups.com> On Jun 2, 6:37?am, Michele Simionato wrote: > With blatant immodesty, plac claims to be the easiest to use command > line arguments parser module in the Python world It seems I have to take that claim back. A few hours after the announce I was pointed out to http://pypi.python.org/pypi/CLIArgs which, I must concede, is even easier to use than plac. It seems everybody has written its own command line arguments parser! From tjreedy at udel.edu Wed Jun 2 11:08:15 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 02 Jun 2010 11:08:15 -0400 Subject: Mixing Decimal and float In-Reply-To: <4322c313-d32a-4c3f-bd91-a0f1694693cf@o12g2000vba.googlegroups.com> References: <413efca9-ec02-4f84-8bef-688d50a65953@f14g2000vbn.googlegroups.com> <4322c313-d32a-4c3f-bd91-a0f1694693cf@o12g2000vba.googlegroups.com> Message-ID: On 6/2/2010 8:17 AM, B.V. wrote: > A contributor filed an issue on the bug tracker (https:// > bugs.tryton.org/roundup/issue1575) and because he's a nice guy (ok > it's a friend of mine), he made a patch proposal (http:// > codereview.appspot.com/1387041). The end of the story is in the > comments of the proposal. I have no idea how to do what you want. But for future reference, links put in running email/newsgroup text as above are not very usable for most readers. They are best put on a line *by themselves*. Then they can be clicked on in at least some mail/newsgroup readers, or at worst, copied and pasted to a browser. Reformatted to be more usable: A contributor filed an issue on the bug tracker https://bugs.tryton.org/roundup/issue1575 and because he's a nice guy (ok it's a friend of mine), he made a patch proposal http://codereview.appspot.com/1387041 The end of the story is in the comments of the proposal. Terry Jan Reedy From fpm at u.washington.edu Wed Jun 2 11:14:47 2010 From: fpm at u.washington.edu (cassiope) Date: Wed, 2 Jun 2010 08:14:47 -0700 (PDT) Subject: python and filter design: calculating "s" optimal transform References: Message-ID: On Jun 1, 2:58?pm, Terry Reedy wrote: > On 6/1/2010 2:18 PM, robert somerville wrote: > > > Hi; > > this is an airy question. > > > does anybody have some code or ideas on how to calculate the optimal "S" > > transform of user specified order (wanting the coefficients) ?for a > > published filter response curve, ie. > > > f(s) = 1.0/(a1*S^2 + a2*S + a3) > > If you do not get an answer here, try the scipy list. Say what???? There are tables of coefficients for Butterworth, Bessel, and other standard filter forms. Could you be a little clearer on what you're trying to do? From tjreedy at udel.edu Wed Jun 2 11:22:03 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 02 Jun 2010 11:22:03 -0400 Subject: Properly posting links (was Re: Python Forum) In-Reply-To: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> Message-ID: On 6/2/2010 4:04 AM, pyDev wrote: > forum for Python enthusiasts over at PythonForum.org (http:// > pythonforum.org). Web-based forums is a preferred method by Python This is the second time today I have read a post with a useless link wrapped over two lines. Email lists and newsgroups (this is both) are text, not html based. Put a link on one line by itself, with no punctuation. The above, if posted at all, should have been forum for Python enthusiasts over at PythonForum.org. http://pythonforum.org Web-based forums is a preferred method by Python From bv.tryton at gmail.com Wed Jun 2 11:32:33 2010 From: bv.tryton at gmail.com (B.V.) Date: Wed, 2 Jun 2010 08:32:33 -0700 (PDT) Subject: Mixing Decimal and float References: <413efca9-ec02-4f84-8bef-688d50a65953@f14g2000vbn.googlegroups.com> <4322c313-d32a-4c3f-bd91-a0f1694693cf@o12g2000vba.googlegroups.com> Message-ID: <43d2e308-b7e6-416f-b975-35b061992168@y12g2000vbg.googlegroups.com> On 2 juin, 17:08, Terry Reedy wrote: > On 6/2/2010 8:17 AM, B.V. wrote: > > > A contributor filed an issue on the bug tracker (https:// > > bugs.tryton.org/roundup/issue1575) and because he's a nice guy (ok > > it's a friend of mine), he made a patch proposal (http:// > > codereview.appspot.com/1387041). The end of the story is in the > > comments of the proposal. > > I have no idea how to do what you want. But for future reference, links > put in running email/newsgroup text as above are not very usable for > most readers. They are best put on a line *by themselves*. Then they can > be clicked on in at least some mail/newsgroup readers, or at worst, > copied and pasted to a browser. Reformatted to be more usable: > > A contributor filed an issue on the bug trackerhttps://bugs.tryton.org/roundup/issue1575 > and because he's a nice guy (ok > it's a friend of mine), he made a patch proposalhttp://codereview.appspot.com/1387041 > The end of the story is in the comments of the proposal. > > Terry Jan Reedy Thank you for your remarks, my next posts will in accordance. B. From eckhardt at satorlaser.com Wed Jun 2 11:37:31 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Wed, 02 Jun 2010 17:37:31 +0200 Subject: decorating a memberfunction Message-ID: <0faid7-fs8.ln1@satorlaser.homedns.org> Hi! I have a class that maintains a network connection, which can be used to query and trigger Things(tm). Apart from "normal" errors, a broken network connection and a protocol violation from the peer are something we can't recover from without creating a new connection, so those errors should "stick". The code looks roughly like this: class Client(object): def __init__(self, ...): self._error = None def _check(fn): def do_check(self, *args, **kwargs): # check for sticky error if self._error: raise self._error try: fn(self, *args, **kwargs) except NetworkError, e: self._error = e raise except ProtocolError, e: self._error = e raise return do_check @_check def frobnicate(self, foo): # format and send request, read and parse answer So, any function like frobnicate() that does things is decorated with _check() so that unrecoverable errors stick. I hope I didn't shorten the code too much to understand the principle, in particular I'm using functools.wraps() in order to retain function names and docstrings. Is this sound? Would you have done it differently? Any other suggestions? What I'm mostly unsure about is whether the definition of _check() and do_check() are correct or could be improved. Thanks! Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From python at mrabarnett.plus.com Wed Jun 2 12:39:49 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 02 Jun 2010 17:39:49 +0100 Subject: decorating a memberfunction In-Reply-To: <0faid7-fs8.ln1@satorlaser.homedns.org> References: <0faid7-fs8.ln1@satorlaser.homedns.org> Message-ID: <4C068955.3040509@mrabarnett.plus.com> Ulrich Eckhardt wrote: > Hi! > > I have a class that maintains a network connection, which can be used to > query and trigger Things(tm). Apart from "normal" errors, a broken network > connection and a protocol violation from the peer are something we can't > recover from without creating a new connection, so those errors > should "stick". > > The code looks roughly like this: > > class Client(object): > def __init__(self, ...): > self._error = None > > def _check(fn): > def do_check(self, *args, **kwargs): > # check for sticky error > if self._error: > raise self._error > > try: > fn(self, *args, **kwargs) > except NetworkError, e: > self._error = e > raise > except ProtocolError, e: > self._error = e > raise > return do_check > > @_check > def frobnicate(self, foo): > # format and send request, read and parse answer > > So, any function like frobnicate() that does things is decorated with > _check() so that unrecoverable errors stick. I hope I didn't shorten the > code too much to understand the principle, in particular I'm using > functools.wraps() in order to retain function names and docstrings. > > > Is this sound? Would you have done it differently? Any other suggestions? > What I'm mostly unsure about is whether the definition of _check() and > do_check() are correct or could be improved. > You could merge the two excepts: try: fn(self, *args, **kwargs) except (NetworkError, ProtocolError), e: self._error = e raise You could also choose a better name for the decorator, eg _check_sticky_error. :-) From uknews00 at gmail.com Wed Jun 2 13:08:08 2010 From: uknews00 at gmail.com (money mania) Date: Wed, 2 Jun 2010 10:08:08 -0700 (PDT) Subject: Simple hack to get $500 to your home. Message-ID: Simple hack to get $500 to your home at http://dailyupdatesonly.tk Due to high security risks,i have hidden the cheque link in an image. in that website on left side below search box, click on image and enter your name and address where you want to receive your cheque.please dont tell to anyone. From przemek.zawada at gmail.com Wed Jun 2 13:40:58 2010 From: przemek.zawada at gmail.com (pmz) Date: Wed, 2 Jun 2010 10:40:58 -0700 (PDT) Subject: Syntax question Message-ID: <1d7f4d03-b4ba-4247-8cde-ef77b0851f6e@f13g2000vbm.googlegroups.com> Dear Group, It's really rookie question, but I'm currently helping my wife in some python-cases, where I'm non-python developer and some of syntax-diffs make me a bit confused. Could anyone give some light on line, as following: "ds = d[:]" ### where 'd' is an array Let me guess, is it a declaration of two-dimension array? Thanks a lot for help and all the best, Przemek M. Zawada From clp2 at rebertia.com Wed Jun 2 13:56:15 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 2 Jun 2010 10:56:15 -0700 Subject: Syntax question In-Reply-To: <1d7f4d03-b4ba-4247-8cde-ef77b0851f6e@f13g2000vbm.googlegroups.com> References: <1d7f4d03-b4ba-4247-8cde-ef77b0851f6e@f13g2000vbm.googlegroups.com> Message-ID: On Wed, Jun 2, 2010 at 10:40 AM, pmz wrote: > Dear Group, > > It's really rookie question, but I'm currently helping my wife in some > python-cases, where I'm non-python developer and some of syntax-diffs > make me a bit confused. > > Could anyone give some light on line, as following: > "ds = d[:]" ?### where 'd' is an array > > Let me guess, is it a declaration of two-dimension array? Nope; Python doesn't really have variable declarations.* That line of code copies the list `d` ( `[]` is the slicing operator, and the colon indicates the bounds are the entire list; this is a Python idiom) and assigns the copy to the variable `ds`. Note that the copying is shallow (i.e. not recursive, only 1 level deep). *Well, almost: There are `global` and `nonlocal`, but they're only needed to specify a variable's scope in certain circumstances when you want to be able to assign to said variable. Cheers, Chris -- http://blog.rebertia.com From debatem1 at gmail.com Wed Jun 2 13:56:42 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 2 Jun 2010 10:56:42 -0700 Subject: Syntax question In-Reply-To: <1d7f4d03-b4ba-4247-8cde-ef77b0851f6e@f13g2000vbm.googlegroups.com> References: <1d7f4d03-b4ba-4247-8cde-ef77b0851f6e@f13g2000vbm.googlegroups.com> Message-ID: On Wed, Jun 2, 2010 at 10:40 AM, pmz wrote: > Dear Group, > > It's really rookie question, but I'm currently helping my wife in some > python-cases, where I'm non-python developer and some of syntax-diffs > make me a bit confused. > > Could anyone give some light on line, as following: > "ds = d[:]" ?### where 'd' is an array I'm guessing you mean that d is a list. The square braces with the colon is python's slicing notation, so if I say [1,2,3,4][0] I get a 1 back, and if I say [1,2,3,4][1:4] I get [2,3,4]. Python also allows a shorthand in slicing, which is that if the first index is not provided, then it assumes 0, and that if the second index is not provided, it assumes the end of the list. Thus, [1,2,3,4][:2] would give me [1,2] and [1,2,3,4][2:] would give me [3, 4]. Here, neither has been provided, so the slice simply takes the items in the list from beginning to end and returns them- [1,2,3,4][:] gives [1,2,3,4]. The reason someone would want to do this is because lists are mutable data structures. If you fire up your terminal you can try the following example: >>> a = [1,2,3,4] >>> b = a >>> c = [:] >>> b[0] = 5 >>> b [5,2,3,4] >>> # here's the issue >>> a [5,2,3,4] >>> # and the resolution >>> c [1,2,3,4] Hope this helps. Geremy Condra From przemek.zawada at gmail.com Wed Jun 2 14:01:56 2010 From: przemek.zawada at gmail.com (pmz) Date: Wed, 2 Jun 2010 11:01:56 -0700 (PDT) Subject: Syntax question References: <1d7f4d03-b4ba-4247-8cde-ef77b0851f6e@f13g2000vbm.googlegroups.com> Message-ID: On 2 Cze, 19:56, geremy condra wrote: > On Wed, Jun 2, 2010 at 10:40 AM, pmz wrote: > > Dear Group, > > > It's really rookie question, but I'm currently helping my wife in some > > python-cases, where I'm non-python developer and some of syntax-diffs > > make me a bit confused. > > > Could anyone give some light on line, as following: > > "ds = d[:]" ?### where 'd' is an array > > I'm guessing you mean that d is a list. The square > braces with the colon is python's slicing notation, > so if I say [1,2,3,4][0] I get a 1 back, and if I say > [1,2,3,4][1:4] I get [2,3,4]. Python also allows a > shorthand in slicing, which is that if the first index > is not provided, then it assumes 0, and that if the > second index is not provided, it assumes the end > of the list. Thus, [1,2,3,4][:2] would give me [1,2] > and [1,2,3,4][2:] would give me [3, 4]. Here, neither > has been provided, so the slice simply takes the > items in the list from beginning to end and returns > them- [1,2,3,4][:] gives [1,2,3,4]. > > The reason someone would want to do this is > because lists are mutable data structures. If you > fire up your terminal you can try the following > example: > > >>> a = [1,2,3,4] > >>> b = a > >>> c = [:] > >>> b[0] = 5 > >>> b > [5,2,3,4] > >>> # here's the issue > >>> a > [5,2,3,4] > >>> # and the resolution > >>> c > > [1,2,3,4] > > Hope this helps. > > Geremy Condra Thank you for such fast answer! I quite catch, but: As I see, the d[:] is equal to sentence "get the d array from the first to the last element"? :) P. From landimatte at gmail.com Wed Jun 2 14:07:48 2010 From: landimatte at gmail.com (Matteo Landi) Date: Wed, 2 Jun 2010 20:07:48 +0200 Subject: Syntax question In-Reply-To: References: <1d7f4d03-b4ba-4247-8cde-ef77b0851f6e@f13g2000vbm.googlegroups.com> Message-ID: Anyway I suggest you to use a syntax like: >>>b = list(a) in order to copy a list, it should be better than slicing. On Wed, Jun 2, 2010 at 7:56 PM, geremy condra wrote: > On Wed, Jun 2, 2010 at 10:40 AM, pmz wrote: >> Dear Group, >> >> It's really rookie question, but I'm currently helping my wife in some >> python-cases, where I'm non-python developer and some of syntax-diffs >> make me a bit confused. >> >> Could anyone give some light on line, as following: >> "ds = d[:]" ?### where 'd' is an array > > I'm guessing you mean that d is a list. The square > braces with the colon is python's slicing notation, > so if I say [1,2,3,4][0] I get a 1 back, and if I say > [1,2,3,4][1:4] I get [2,3,4]. Python also allows a > shorthand in slicing, which is that if the first index > is not provided, then it assumes 0, and that if the > second index is not provided, it assumes the end > of the list. Thus, [1,2,3,4][:2] would give me [1,2] > and [1,2,3,4][2:] would give me [3, 4]. Here, neither > has been provided, so the slice simply takes the > items in the list from beginning to end and returns > them- [1,2,3,4][:] gives [1,2,3,4]. > > The reason someone would want to do this is > because lists are mutable data structures. If you > fire up your terminal you can try the following > example: > >>>> a = [1,2,3,4] >>>> b = a >>>> c = [:] >>>> b[0] = 5 >>>> b > [5,2,3,4] >>>> # here's the issue >>>> a > [5,2,3,4] >>>> # and the resolution >>>> c > [1,2,3,4] > > Hope this helps. > > Geremy Condra > -- > http://mail.python.org/mailman/listinfo/python-list > -- Matteo Landi http://www.matteolandi.net/ From przemek.zawada at gmail.com Wed Jun 2 14:10:45 2010 From: przemek.zawada at gmail.com (pmz) Date: Wed, 2 Jun 2010 11:10:45 -0700 (PDT) Subject: Syntax question References: <1d7f4d03-b4ba-4247-8cde-ef77b0851f6e@f13g2000vbm.googlegroups.com> Message-ID: <45f75af3-67ce-479e-8012-bc5f0837479d@q23g2000vba.googlegroups.com> On 2 Cze, 20:07, Matteo Landi wrote: > Anyway I suggest you to use a syntax like: > > >>>b = list(a) > > in order to copy a list, it should be better than slicing. > > > > > > On Wed, Jun 2, 2010 at 7:56 PM, geremy condra wrote: > > On Wed, Jun 2, 2010 at 10:40 AM, pmz wrote: > >> Dear Group, > > >> It's really rookie question, but I'm currently helping my wife in some > >> python-cases, where I'm non-python developer and some of syntax-diffs > >> make me a bit confused. > > >> Could anyone give some light on line, as following: > >> "ds = d[:]" ?### where 'd' is an array > > > I'm guessing you mean that d is a list. The square > > braces with the colon is python's slicing notation, > > so if I say [1,2,3,4][0] I get a 1 back, and if I say > > [1,2,3,4][1:4] I get [2,3,4]. Python also allows a > > shorthand in slicing, which is that if the first index > > is not provided, then it assumes 0, and that if the > > second index is not provided, it assumes the end > > of the list. Thus, [1,2,3,4][:2] would give me [1,2] > > and [1,2,3,4][2:] would give me [3, 4]. Here, neither > > has been provided, so the slice simply takes the > > items in the list from beginning to end and returns > > them- [1,2,3,4][:] gives [1,2,3,4]. > > > The reason someone would want to do this is > > because lists are mutable data structures. If you > > fire up your terminal you can try the following > > example: > > >>>> a = [1,2,3,4] > >>>> b = a > >>>> c = [:] > >>>> b[0] = 5 > >>>> b > > [5,2,3,4] > >>>> # here's the issue > >>>> a > > [5,2,3,4] > >>>> # and the resolution > >>>> c > > [1,2,3,4] > > > Hope this helps. > > > Geremy Condra > > -- > >http://mail.python.org/mailman/listinfo/python-list > > -- > Matteo Landihttp://www.matteolandi.net/ In fact, that ain't my syntax, I'd rather use C++ for that project, because that's my world is not Python, but thank you anyway for help - I see that Python also has many fans and friends online :) I'll try help her using your explanations. THANK you again and all the best, Przemek M. Zawada From landimatte at gmail.com Wed Jun 2 14:13:29 2010 From: landimatte at gmail.com (Matteo Landi) Date: Wed, 2 Jun 2010 20:13:29 +0200 Subject: Syntax question In-Reply-To: References: <1d7f4d03-b4ba-4247-8cde-ef77b0851f6e@f13g2000vbm.googlegroups.com> Message-ID: Yes it is; d[i:j] is equal to "give me the array from the d[i] to d[j - 1]", and if you omit i and j then the i and j are respectively assumed as 0 and len(d) - 1. On Wed, Jun 2, 2010 at 8:01 PM, pmz wrote: > On 2 Cze, 19:56, geremy condra wrote: >> On Wed, Jun 2, 2010 at 10:40 AM, pmz wrote: >> > Dear Group, >> >> > It's really rookie question, but I'm currently helping my wife in some >> > python-cases, where I'm non-python developer and some of syntax-diffs >> > make me a bit confused. >> >> > Could anyone give some light on line, as following: >> > "ds = d[:]" ?### where 'd' is an array >> >> I'm guessing you mean that d is a list. The square >> braces with the colon is python's slicing notation, >> so if I say [1,2,3,4][0] I get a 1 back, and if I say >> [1,2,3,4][1:4] I get [2,3,4]. Python also allows a >> shorthand in slicing, which is that if the first index >> is not provided, then it assumes 0, and that if the >> second index is not provided, it assumes the end >> of the list. Thus, [1,2,3,4][:2] would give me [1,2] >> and [1,2,3,4][2:] would give me [3, 4]. Here, neither >> has been provided, so the slice simply takes the >> items in the list from beginning to end and returns >> them- [1,2,3,4][:] gives [1,2,3,4]. >> >> The reason someone would want to do this is >> because lists are mutable data structures. If you >> fire up your terminal you can try the following >> example: >> >> >>> a = [1,2,3,4] >> >>> b = a >> >>> c = [:] >> >>> b[0] = 5 >> >>> b >> [5,2,3,4] >> >>> # here's the issue >> >>> a >> [5,2,3,4] >> >>> # and the resolution >> >>> c >> >> [1,2,3,4] >> >> Hope this helps. >> >> Geremy Condra > > Thank you for such fast answer! I quite catch, but: > As I see, the d[:] is equal to sentence "get the d array from the > first to the last element"? :) > > P. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Matteo Landi http://www.matteolandi.net/ From ppreety68 at gmail.com Wed Jun 2 15:22:13 2010 From: ppreety68 at gmail.com (preety preety) Date: Wed, 2 Jun 2010 12:22:13 -0700 (PDT) Subject: See and Enjoy Indian Girls Gallery. Message-ID: <59900966-448c-4b10-baaf-beb85187768f@31g2000prc.googlegroups.com> http://www.teluguscope.com/allfiles/galleryfiles/actressfiles/kajole/1.html http://www.teluguscope.com/allfiles/galleryfiles/actressfiles/aishwaryarai/33.html http://www.teluguscope.com/allfiles/galleryfiles/actressfiles/mallikasherawat/2.html http://www.teluguscope.com/allfiles/galleryfiles/actressindexfiles/katrinakaifindex.html http://www.teluguscope.com/allfiles/galleryfiles/actressindexfiles/ilianaindex.html http://www.teluguscope.com/allfiles/galleryfiles/actressindexfiles/kajoleindex.html http://www.teluguscope.com/allfiles/galleryfiles/actressindexfiles/deepikapadukoneindex.html From bryanjugglercryptographer at yahoo.com Wed Jun 2 16:07:01 2010 From: bryanjugglercryptographer at yahoo.com (Bryan) Date: Wed, 2 Jun 2010 13:07:01 -0700 (PDT) Subject: multiprocessing and accessing server's stdout References: <0c6dd70f-ec1b-4fe7-9e1d-82dbeab2f390@z33g2000vbb.googlegroups.com> <6ddb97ae-9a2c-4dbc-ac5c-dc411015a78e@o12g2000vba.googlegroups.com> Message-ID: <1d2c1501-cac7-44b1-8858-f5132425c776@r5g2000prf.googlegroups.com> Tim Arnold wrote: > Hi, This is the setup I was asking about. > I've got users using a python-written command line client. They're > requesting services from a remote server that fires a LaTeX process. I > want them to see the stdout from the LaTeX process. So what you really need is to capture the output of a command, in this case LaTeX, so you can copy it back to the client. You can do that with the subprocess module in the Python standard library. If the command generated so much output so fast that you felt the need to avoid the extra copy, I suppose you could fork() then hook stdout directly to socket connected to the client with dup2(), then exec() the command. But no need for that just to capture LaTeX's output. -- --Bryan Olson From ivlenin at gmail.com Wed Jun 2 16:35:50 2010 From: ivlenin at gmail.com (I V) Date: 2 Jun 2010 22:35:50 +0200 Subject: Mixing Decimal and float References: <413efca9-ec02-4f84-8bef-688d50a65953@f14g2000vbn.googlegroups.com> <4322c313-d32a-4c3f-bd91-a0f1694693cf@o12g2000vba.googlegroups.com> Message-ID: <4c06c0a6$1@news.x-privat.org> On Wed, 02 Jun 2010 05:17:11 -0700, B.V. wrote: > But trying to be open to other languages, the server implements also an > XMLRPC interface (and also a JSONRPC-like interface). That's the key > point: Decimal is python specific. So in an application, you can't rely > on the value received from a client, because depending on the protocol, > the type of the value is different. So the idea was to create a class > that can behave like a Decimal or a float depending on the context, and > set xmlrpclib.Unmarshaller.dispatch["double"] to a function that return > a Float instance. Looking at the Tryton docs, it seems that it already supports field types that can't be directly represented in XMLRPC or JSON, like BigInteger or Selection. How are these serialized over the non-python RPC mechanisms? Could you not do the same for Decimals? > A contributor filed an issue on the bug tracker (https:// > bugs.tryton.org/roundup/issue1575) and because he's a nice guy (ok it's > a friend of mine), he made a patch proposal (http:// > codereview.appspot.com/1387041). The end of the story is in the comments > of the proposal. > > >> > But we also need to do: >> > isinstance(Float('1'), float) == True isinstance(Float('1'), Decimal) >> > == True >> >> Can you explain why you need this? > > It's a requirement of the project leader. > > >> Should isinstance(Float('1.1'), float) and isinstance(Float('1.1'), >> Decimal) also both be true, or would only one of those be true? ?(And >> by the way, what value would Float('1.1') have? ?float('1.1') and >> Decimal('1.1') are different values.) > > I think they both should be True, for '1', '1.1', '0', '0.1', ... For > the value, I would say that it depends of the definition of the field > (fields.Float or fields.Numeric). > > > >> I don't think your approach can succeed; ?I'd suggest just subclassing >> 'object' and abandoning the 'isinstance' requirements. ?Or perhaps >> creating a subclass of Decimal that interacts nicely with floats. ?You >> might also want to investigate the numbers ABC, though that's new in >> Python 2.6. > > First, Float implementation was a subclass of Decimal that works with > floats, and solves many (maybe all) problems. But as you may read in the > comments of the patch proposal, it seems to be not enough. > > B. From rami.chowdhury at gmail.com Wed Jun 2 16:35:52 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Wed, 2 Jun 2010 13:35:52 -0700 Subject: MySQLDB - server has gone on blob insertion... In-Reply-To: <4c055dbe$0$1634$742ec2ed@news.sonic.net> References: <4c055dbe$0$1634$742ec2ed@news.sonic.net> Message-ID: <201006021335.52512.rami.chowdhury@gmail.com> On Tuesday 01 June 2010 12:46:40 John Nagle wrote: > durumdara wrote: > >>> When I tried to start this, I got error: > >>> _mysql_exceptions.OperationalError: (2006, 'MySQL server has gone > >>> away') > > Are you by any chance trying to do this on a HostGator account? > HostGator servers run a program which kills long MySQL transactions > by executing MySQL "KILL" transactions. > This is reported to the user as 'MySQL server has gone away' I don't think HostGator is alone in this -- AFAIK several web hosts (including mine) do it too. ---- Rami Chowdhury "As an online discussion grows longer, the probability of a comparison involving Nazis or Hitler approaches one." -- Godwin's Law 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) From Paul Wed Jun 2 16:46:40 2010 From: Paul (Paul) Date: Wed, 02 Jun 2010 13:46:40 -0700 Subject: Embedding Python in a C extension Message-ID: I have a problem with embedding Python into a C extension in Windows Vista. I have implemented a timer routine in C as an extension, which I can import into Python 2.6.5 and run. Each timer interval, the extension calls a C CALLBACK function. I want to be able to have this CALLBACK function call a Python function, so that I can write the timer handler in Python. I can write Python functions and call them from a C extension function with no trouble in all cases EXCEPT when the function that calls the Python code is the timer's CALLBACK function. That is, if I call PyRun_SimpleString or PyRun_SimpleFile, or PyImport_ImportModule, or basically any Python-y function in the CALLBACK function, Python crashes and I get a window saying "Python has stopped working. Windows is searching for a solution to the problem." The Python code runs fine if I call it from a function in the extension that is not the CALLBACK function. And regular C code runs in the CALLBACK function properly. It only crashes if I try to run the Python code from the timer CALLBACK function (or any C function I call from the CALLBACK function). Does anybody know how to fix this? Is there a workaround of some sort? From psdasilva.nospam at netcabonospam.pt Wed Jun 2 17:10:40 2010 From: psdasilva.nospam at netcabonospam.pt (Paulo da Silva) Date: Wed, 02 Jun 2010 22:10:40 +0100 Subject: Converting a pickle to python3 In-Reply-To: <4c05d47e$0$31524$a729d347@news.telepac.pt> References: <4c05d47e$0$31524$a729d347@news.telepac.pt> Message-ID: <4c06c8cf$0$31582$a729d347@news.telepac.pt> Em 02-06-2010 04:48, Paulo da Silva escreveu: > Hi! > > I have a big data structure cpickled into a datafile, by python2. > I tried to unpickle it using python3 but got the followin message: > File "/usr/lib64/python3.1/pickle.py", line 1372, in loads > encoding=encoding, errors=errors).load() > _pickle.UnpicklingError: invalid load key, 'x'. > ... Please ignore this question. The problem is not the pickle thing but a compress function I have that has problems related with the new str/bytes stuff. Sorry. From nathan.alexander.rice at gmail.com Wed Jun 2 17:17:11 2010 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Wed, 2 Jun 2010 17:17:11 -0400 Subject: Mixing Decimal and float In-Reply-To: References: Message-ID: My apologies if someone already mentioned this and I missed it but... class.__instancecheck__(self,?instance) - Return true if?instance should be considered a (direct or indirect) instance of?class. If defined, called to implement?isinstance(instance,?class). class.__subclasscheck__(self,?subclass) - Return true if?subclass should be considered a (direct or indirect) subclass of?class. If defined, called to implement?issubclass(subclass,?class). Nathan On Wed, Jun 2, 2010 at 4:24 AM, B.V. wrote: > Hi, > > In order to solve some issues due to operations between Decimal and > float, we wanted to implement a class that inherits from both float > and Decimal. > > Typically, we wrote: > class Float(Decimal, float): > ... > > This can not be achieved because of a TypeError exception (with > message "multiple bases have instance lay-out conflict"). > > With a class that inherits from Decimal, with overridden __add__, > __mul__, .... , we succeed to solve operations issues. > > But we also need to do: > isinstance(Float('1'), float) == True > isinstance(Float('1'), Decimal) == True > which is, AFAIK, only possible with Float(Decimal, float). > > Is there a workaround ? > > We are developping with python version 2.5 and 2.6. > > Thanks for your help. > > B. > -- > http://mail.python.org/mailman/listinfo/python-list > From bryanjugglercryptographer at yahoo.com Wed Jun 2 19:00:44 2010 From: bryanjugglercryptographer at yahoo.com (Bryan) Date: Wed, 2 Jun 2010 16:00:44 -0700 (PDT) Subject: multiprocessing and accessing server's stdout References: <0c6dd70f-ec1b-4fe7-9e1d-82dbeab2f390@z33g2000vbb.googlegroups.com> <6ddb97ae-9a2c-4dbc-ac5c-dc411015a78e@o12g2000vba.googlegroups.com> <1d2c1501-cac7-44b1-8858-f5132425c776@r5g2000prf.googlegroups.com> Message-ID: <58a8a3a5-8aec-44f9-94eb-b49e519b4ac7@11g2000prw.googlegroups.com> I wrote: > So what you really need is to capture the output of a command, in this > case LaTeX, so you can copy it back to the client. You can do that > with the subprocess module in the Python standard library. > > If the command generated so much output so fast that you felt the need > to avoid the extra copy, I suppose you could fork() then hook stdout > directly to socket connected to the client with dup2(), then exec() > the command. But no need for that just to capture LaTeX's output. Upon further reading, I see that the subprocess module makes the direct-hookup method easy, at least on 'nix systems. Just tell subprocess.Popen to use the client-connected socket as the subprocess's stdout. The question here turns out to make more sense than I had though upon reading the first post. The server runs a command at the client's request, and we want to deliver the output of that command back to the client. A brilliantly efficient method is to direct the command's stdout to the client's connection. Below is a demo server that sends the host's words file to any client that connects. It assumes Unix. --Bryan Olson #!/usr/bin/python from thread import start_new_thread from subprocess import Popen def demo(sock): subp = Popen(['cat', '/usr/share/dict/words'], stdout=sock) subp.wait() sock.close() if __name__ == '__main__': listener_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) listener_sock.bind(('', 54321)) listener_sock.listen(5) while True: sock, remote_address = listener_sock.accept() start_new_thread(demo, (sock,)) From steve-REMOVE-THIS at cybersource.com.au Wed Jun 2 19:11:24 2010 From: steve-REMOVE-THIS at cybersource.com.au (Steven D'Aprano) Date: 02 Jun 2010 23:11:24 GMT Subject: Mixing Decimal and float References: Message-ID: <4c06e51b$0$14161$c3e8da3@news.astraweb.com> On Wed, 02 Jun 2010 17:17:11 -0400, Nathan Rice wrote: > My apologies if someone already mentioned this and I missed it but... > > class.__instancecheck__(self,?instance) - Return true if?instance should > be considered a (direct or indirect) instance of?class. If defined, > called to implement?isinstance(instance,?class). > > class.__subclasscheck__(self,?subclass) - Return true if?subclass should > be considered a (direct or indirect) subclass of?class. If defined, > called to implement?issubclass(subclass,?class). The original poster needs to support Python 2.5 and 2.6, but __instancecheck__ and __subclasscheck__ are only supported in 2.6 or higher, so this doesn't help. -- Steven From ben+python at benfinney.id.au Wed Jun 2 19:46:14 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 03 Jun 2010 09:46:14 +1000 Subject: Properly posting links References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> Message-ID: <87ljaxdmm1.fsf@benfinney.id.au> Terry Reedy writes: > On 6/2/2010 4:04 AM, pyDev wrote: > > > forum for Python enthusiasts over at PythonForum.org (http:// > > pythonforum.org). Web-based forums is a preferred method by Python > > This is the second time today I have read a post with a useless link > wrapped over two lines. Email lists and newsgroups (this is both) are > text, not html based. Put a link on one line by itself, with no > punctuation. Or better, follow appendix ?E. Recommendations for Delimiting URI in Context? of RFC 2396 . This allows the text to flow more naturally than breaking every URL onto a separate line, while still delimiting URLs within the text in a standard manner that most text processing tools will recognise. -- \ ?We can't depend for the long run on distinguishing one | `\ bitstream from another in order to figure out which rules | _o__) apply.? ?Eben Moglen, _Anarchism Triumphant_, 1999 | Ben Finney From clp2 at rebertia.com Wed Jun 2 20:00:44 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 2 Jun 2010 17:00:44 -0700 Subject: Mixing Decimal and float In-Reply-To: <4c06e51b$0$14161$c3e8da3@news.astraweb.com> References: <4c06e51b$0$14161$c3e8da3@news.astraweb.com> Message-ID: On Wed, Jun 2, 2010 at 4:11 PM, Steven D'Aprano wrote: > On Wed, 02 Jun 2010 17:17:11 -0400, Nathan Rice wrote: >> My apologies if someone already mentioned this and I missed it but... >> >> class.__instancecheck__(self,?instance) - Return true if?instance should >> be considered a (direct or indirect) instance of?class. If defined, >> called to implement?isinstance(instance,?class). >> >> class.__subclasscheck__(self,?subclass) - Return true if?subclass should >> be considered a (direct or indirect) subclass of?class. If defined, >> called to implement?issubclass(subclass,?class). > > The original poster needs to support Python 2.5 and 2.6, but > __instancecheck__ and __subclasscheck__ are only supported in 2.6 or > higher, so this doesn't help. Even in 2.6+, good luck trying to define new methods on class `type` (the metaclass of float and Decimal). Cheers, Chris -- http://blog.rebertia.com From python at mrabarnett.plus.com Wed Jun 2 20:07:39 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 03 Jun 2010 01:07:39 +0100 Subject: Embedding Python in a C extension In-Reply-To: References: Message-ID: <4C06F24B.70209@mrabarnett.plus.com> Paul at mail.python.org wrote: > I have a problem with embedding Python into a C extension in Windows > Vista. I have implemented a timer routine in C as an extension, which > I can import into Python 2.6.5 and run. Each timer interval, the > extension calls a C CALLBACK function. I want to be able to have this > CALLBACK function call a Python function, so that I can write the > timer handler in Python. > > I can write Python functions and call them from a C extension function > with no trouble in all cases EXCEPT when the function that calls the > Python code is the timer's CALLBACK function. That is, if I call > PyRun_SimpleString or PyRun_SimpleFile, or PyImport_ImportModule, or > basically any Python-y function in the CALLBACK function, Python > crashes and I get a window saying "Python has stopped working. Windows > is searching for a solution to the problem." > > The Python code runs fine if I call it from a function in the > extension that is not the CALLBACK function. And regular C code runs > in the CALLBACK function properly. It only crashes if I try to run the > Python code from the timer CALLBACK function (or any C function I call > from the CALLBACK function). > > Does anybody know how to fix this? Is there a workaround of some sort? Here's a quote from the Python docs at: http://docs.python.org/c-api/init.html """The Python interpreter is not fully thread safe. In order to support multi-threaded Python programs, there's a global lock, called the global interpreter lock or GIL, that must be held by the current thread before it can safely access Python objects. Without the lock, even the simplest operations could cause problems in a multi-threaded program: for example, when two threads simultaneously increment the reference count of the same object, the reference count could end up being incremented only once instead of twice.""" That's probably what's happening to you. From wuwei23 at gmail.com Wed Jun 2 20:51:54 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 2 Jun 2010 17:51:54 -0700 (PDT) Subject: plac, the easiest command line arguments parser in the world References: <1d09462d-3de1-4e40-8cc7-c45e18cf0ffd@m4g2000vbl.googlegroups.com> <4ad5afd9-feab-48cb-a471-826d0bc4d007@z17g2000vbd.googlegroups.com> Message-ID: Michele Simionato wrote: > It seems I have to take that claim back. A few hours after the > announce I was pointed out tohttp://pypi.python.org/pypi/CLIArgs > which, I must concede, is even easier to use than plac. It seems > everybody has written its own command line arguments parser! I think I still find opterator[1] to be simpler and clearer. No magic global variables, no spooky behaviour with the main function, just a decorator and docstring. 1: http://github.com/buchuki/opterator From uknews00 at gmail.com Wed Jun 2 20:58:08 2010 From: uknews00 at gmail.com (money mania) Date: Wed, 2 Jun 2010 17:58:08 -0700 (PDT) Subject: See Hot Sexy Star Aishwarya Nude Bathing Videos In All Angles. Message-ID: <239157df-fb82-4ffc-acbf-ce3f1e4ff7cd@r5g2000prf.googlegroups.com> See Hot Sexy Star Aishwarya Nude Bathing Videos In All Angles. at http://uknews.tk Due to high sex content,i have hidden the videos in an image. in that website on left side below search box click on image and watch videos in all angles.please dont tell to anyone. From pavlovevidence at gmail.com Thu Jun 3 01:30:37 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 2 Jun 2010 22:30:37 -0700 (PDT) Subject: Embedding Python in a C extension References: Message-ID: <21ed6e08-d60f-4326-9fd8-22c3debf5781@a16g2000prg.googlegroups.com> On Jun 2, 1:46?pm, Paul Grunau wrote: > I have a problem with embedding Python into a C extension in Windows > Vista. I have implemented a timer routine in C as an extension, which > I can import into Python 2.6.5 and run. Each timer interval, the > extension calls a C CALLBACK function. I want to be able to have this > CALLBACK function call a Python function, so that I can write the > timer handler in Python. > > I can write Python functions and call them from a C extension function > with no trouble in all cases EXCEPT when the function that calls the > Python code is the timer's CALLBACK function. That is, if I call > PyRun_SimpleString or PyRun_SimpleFile, or PyImport_ImportModule, or > basically any Python-y function in the CALLBACK function, Python > crashes and I get a window saying "Python has stopped working. Windows > is searching for a solution to the problem." > > The Python code runs fine if I call it from a function in the > extension that is not the CALLBACK function. And regular C code runs > in the CALLBACK function properly. It only crashes if I try to run the > Python code from the timer CALLBACK function (or any C function I call > from the CALLBACK function). > > Does anybody know how to fix this? Is there a workaround of some sort? See PEP 311. When an external/uncertain thread calls into Python, it has to be sure a Python thread state exists for that thread, and that the thread holds the global interpreter lock. This is done by surrounding all Python code with the following calls: PyGILState_STATE state = PyGILState_Ensure(); and PyGILState_Release(state); Normally, code in extension modules can rely on the current thread having the global lock at all entry points, so it doesn't have worry about the thread state. But a callback from a timer can't assume that. Carl Banks From durumdara at gmail.com Thu Jun 3 03:10:04 2010 From: durumdara at gmail.com (durumdara) Date: Thu, 3 Jun 2010 00:10:04 -0700 (PDT) Subject: MySQLDB - server has gone on blob insertion... References: <4c055dbe$0$1634$742ec2ed@news.sonic.net> Message-ID: Hi! No, there is no same program. I got this ref: http://dev.mysql.com/doc/refman/5.0/en/gone-away.html I will try it. Thanks: dd From news1234 at free.fr Thu Jun 3 03:52:26 2010 From: news1234 at free.fr (News123) Date: Thu, 03 Jun 2010 09:52:26 +0200 Subject: Python Forum In-Reply-To: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> Message-ID: <4c075f3b$0$24148$426a74cc@news.free.fr> pyDev wrote: > Hello, > > I would like to let the community know that there is a new web-based > forum for Python enthusiasts over at PythonForum.org (http:// > pythonforum.org). Web-based forums is a preferred method by Python > newcomers to get help in exploring the world of Python and programming > overall. The main goal of PythonForum.org is to popularize Python by > welcoming all newcomers. Recently the forum got "attacked" with > questions by users just starting out with Python. I hope here will be > someone ready to welcome and help newcomers to enter the beautiful > world of Python. > I fully agree with the feedback, that creating a new forum is not such an excellent idea. currently the critical mass seems to be here and I appreciate this a lot. However, whether we like it or not: Fewer and fewer newcomers are willing, knowledgable, aware of nntp If you think, that newbies are unlikely to use nntp, then create a forum, web front end or whatever, which looks very nice and cool, which will automatically relay messages (forward and backward) to this group. In my opinion new forums should integrate nntp and not try to replace it. An nntp gateway on just another server is also not as nice as just communicating with the existing feeds. N From ben+python at benfinney.id.au Thu Jun 3 04:57:13 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 03 Jun 2010 18:57:13 +1000 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> Message-ID: <87zkzccx3q.fsf@benfinney.id.au> News123 writes: > However, whether we like it or not: > Fewer and fewer newcomers are willing, knowledgable, aware of nntp If so, isn't that an indication that better education about the benefits is required? Perhaps in combination with improving the tool support for the NNTP protocol? > If you think, that newbies are unlikely to use nntp, then create a > forum, web front end or whatever, which looks very nice and cool, > which will automatically relay messages (forward and backward) to this > group. > > In my opinion new forums should integrate nntp and not try to replace > it. For this purpose, Papercut may be useful: Open source news server written in Python. Its main objective is to integrate existing web based message board software, like Phorum which is supported, with a Usenet front-end. -- \ ?To stay young requires unceasing cultivation of the ability to | `\ unlearn old falsehoods.? ?Robert Anson Heinlein | _o__) | Ben Finney From awilliam at whitemice.org Thu Jun 3 06:15:20 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Thu, 03 Jun 2010 06:15:20 -0400 Subject: Python Forum In-Reply-To: <4c075f3b$0$24148$426a74cc@news.free.fr> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> Message-ID: <1275560120.8775.6.camel@linux-yu4c.site> On Thu, 2010-06-03 at 09:52 +0200, News123 wrote: > > I would like to let the community know that there is a new web-based > > forum for Python enthusiasts over at PythonForum.org (http:// > > pythonforum.org). Web-based forums is a preferred method by Python > > newcomers to get help in exploring the world of Python and programming > > overall. The main goal of PythonForum.org is to popularize Python by > > welcoming all newcomers. Recently the forum got "attacked" with > > questions by users just starting out with Python. I hope here will be > > someone ready to welcome and help newcomers to enter the beautiful > > world of Python. > I fully agree with the feedback, that creating a new forum is not such > an excellent idea. currently the critical mass seems to be here and I > appreciate this a lot. > However, whether we like it or not: > Fewer and fewer newcomers are willing, knowledgable, aware of nntp So? NNTP is the living dead. Time to let it go. Most people use this list via e-mail, which everyone has access to and knows how to use. The best solution I've seen is what is used by the Mono project; which provides both a "web forum" and a mail list interface. It works very well; and everyone [except the 3 or 4 NNTP hold outs] are happy. -- Adam Tauno Williams LPIC-1, Novell CLA OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba From quentel.pierre at wanadoo.fr Thu Jun 3 06:16:03 2010 From: quentel.pierre at wanadoo.fr (Pierre Quentel) Date: Thu, 3 Jun 2010 03:16:03 -0700 (PDT) Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87zkzccx3q.fsf@benfinney.id.au> Message-ID: <88192331-3301-47f8-8742-0a26eb9a65f0@j9g2000vbp.googlegroups.com> On 3 juin, 10:57, Ben Finney wrote: > News123 writes: > > However, whether we like it or not: > > Fewer and fewer newcomers are willing, knowledgable, aware of nntp > > If so, isn't that an indication that better education about the benefits > is required? Perhaps in combination with improving the tool support for > the NNTP protocol? > > > If you think, that newbies are unlikely to use nntp, then create a > > forum, web front end or whatever, which looks very nice and cool, > > which will automatically relay messages (forward and backward) to this > > group. > > > In my opinion new forums should integrate nntp and not try to replace > > it. > > For this purpose, Papercut may be useful: > > ? ? Open source news server written in Python. Its main objective is to > ? ? integrate existing web based message board software, like Phorum > ? ? which is supported, with a Usenet front-end. > > ? ? > > -- > ?\ ? ? ?To stay young requires unceasing cultivation of the ability to | > ? `\ ? ? ? ? ? ? ? ? ? unlearn old falsehoods.? ?Robert Anson Heinlein | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| > Ben Finney Hi all, I agree that it's not efficient to split the community by creating another forum. But we can't ignore the fact that c.l.p's activity has been decreasing in the last years : 2000 42971 2001 55265 2002 56774 2003 64521 2004 55929 2005 58864 2006 59664 2007 49105 2008 48722 2009 44111 which certainly doesn't match the popularity of the language itself So the OP's initiative should be an incentive to think on the format of the interaction between all the range of Python users, from newbees to gurus. We are in the 2.0 era, with social networks all over the place using a pleasant interface, while c.l.p has a rather austere look and feel, with text only, no way to present code snippets in a different font / background than discussions, and even an unintuitive way of entering links... I'm not saying that pythonforum.org is the best solution but it certainly looks more attractive than c.l.p. to the new generation of Python users - Pierre From martin.hellwig at dcuktec.org Thu Jun 3 06:28:47 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 03 Jun 2010 11:28:47 +0100 Subject: Python Forum In-Reply-To: <88192331-3301-47f8-8742-0a26eb9a65f0@j9g2000vbp.googlegroups.com> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87zkzccx3q.fsf@benfinney.id.au> <88192331-3301-47f8-8742-0a26eb9a65f0@j9g2000vbp.googlegroups.com> Message-ID: On 06/03/10 11:16, Pierre Quentel wrote: > I'm not saying that pythonforum.org is the best solution but it > certainly looks more attractive than c.l.p. to the new generation of > Python users > > - Pierre On the other hand it might not be so bad that you don't get questions from users here who are unable to use a nntp reader or news to mail service. Other 'forums' that specifically target users unaware of their opposable thumbs certainly have a right of existence, though you wouldn't find me there. -- mph From peter at 4doptics.com Thu Jun 3 06:54:13 2010 From: peter at 4doptics.com (Peter West) Date: Thu, 3 Jun 2010 03:54:13 -0700 (PDT) Subject: CTYPES structure passing Message-ID: <18124e50-30c9-4963-a194-f96bf309dd25@c7g2000vbc.googlegroups.com> Hi I'm hoping someone here can tell me what I'm doing wrong as I've spent the best part of three days reading docs and trying code. I want to port a windows DLL that controls a USB camera to Python using C types. I've happily converted a lot of the functions but am stuck with one vital function that requires a structure to be passed to the DLL for filling with data. I have the C declarations CAM_API BOOL LUCAM_EXPORT LucamGetFormat(HANDLE hCamera, LUCAM_FRAME_FORMAT *pFormat, FLOAT *pFrameRate); where the LUCAM_FRAME_FORMAT is defined as typedef struct { ULONG xOffset; // x coordinate on imager of top left corner of subwindow in pixels ULONG yOffset; // y coordinate on imager of top left corner of subwindow in pixels ULONG width; // width in pixels of subwindow ULONG height; // height in pixels of subwindow ULONG pixelFormat; // pixel format for data union { USHORT subSampleX; // sub-sample ratio in x direction in pixels (x:1) USHORT binningX; // binning ratio in x direction in pixels (x:1) }; USHORT flagsX; // LUCAM_FRAME_FORMAT_FLAGS_* union { USHORT subSampleY; // sub-sample ratio in y direction in pixels (y:1) USHORT binningY; // binning ratio in y direction in pixels (y:1) }; USHORT flagsY; // LUCAM_FRAME_FORMAT_FLAGS_* } LUCAM_FRAME_FORMAT; In my Python code I have #------------- Frame format -------------------- class FRAME_FORMAT_UNION(Union): __fields__ = [("subSample", c_ushort), # sub-sample ratio in x direction in pixels (x:1) ("binning", c_ushort )] # binning ratio in x direction in pixels (x:1) class LUCAM_FRAME_FORMAT(Structure): __fields__ = [( "xOffset", c_ulong), # x coordinate on imager of top left corner of subwindow in pixels ( "yOffset", c_ulong), # y coordinate on imager of top left corner of subwindow in pixels ( "width", c_ulong), # width in pixels of subwindow ( "height", c_ulong), # height in pixels of subwindow ( "pixelFormat", c_ulong), #pixel format for data ( "XUnion", FRAME_FORMAT_UNION), ( "flagsX", c_ushort), # LUCAM_FRAME_FORMAT_FLAGS_* ( "YUnion", FRAME_FORMAT_UNION), ( "flagsY", c_ushort)] LP_FRAME_FORMAT = POINTER(LUCAM_FRAME_FORMAT) and make the call like this FrameRate = c_float(0) FrameFormat = LUCAM_FRAME_FORMAT() FrameFormat.xOffset = 0 FrameFormat.yOffset = 0 FrameFormat.width = 0 FrameFormat.height = 0 FrameFormat.pixelFormat = 0 FrameFormat.XUnion = 0 FrameFormat.flagsX = 0 FrameFormat.YUnion = 0 FrameFormat.flagsY = 0 lucam = windll.lucamapi error = bool() GetFormat = lucam.LucamGetFormat GetFormat.argtypes = ( HANDLE, LP_FRAME_FORMAT, POINTER(c_float) ) GetFormat.restype = BOOL error = GetFormat (hCamera, FrameFormat, FrameRate ) On return the FrameRate parameter is correct but the FrameFormat structure no longer has the any field attributes. Further more it often generates an access violation, apparently in python26.dll. I guess the call is writing to unallocated memory but I have no idea why. Can anyone help? From awilliam at whitemice.org Thu Jun 3 07:20:48 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Thu, 03 Jun 2010 07:20:48 -0400 Subject: Python Forum In-Reply-To: <88192331-3301-47f8-8742-0a26eb9a65f0@j9g2000vbp.googlegroups.com> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87zkzccx3q.fsf@benfinney.id.au> <88192331-3301-47f8-8742-0a26eb9a65f0@j9g2000vbp.googlegroups.com> Message-ID: <1275564048.8775.13.camel@linux-yu4c.site> On Thu, 2010-06-03 at 03:16 -0700, Pierre Quentel wrote: > I agree that it's not efficient to split the community by creating > another forum. But we can't ignore the fact that c.l.p's activity has > been decreasing in the last years : > 2000 42971 > 2001 55265 > 2002 56774 > 2003 64521 > 2004 55929 > 2005 58864 > 2006 59664 > 2007 49105 > 2008 48722 > 2009 44111 > which certainly doesn't match the popularity of the language itself I'm not sure that means what you imply it does. I'm involved in several projects and technical groups. List traffic is down across-the-board. I remember [physical] UG [of various flavors] meetings of 30+ people, now you average ~10. I see two factors: [a] much better documentation, more traditional training, and simply that many of the hard nuts have been cracked. It is much easier to develop [regardless of language] or sys-admin than it was ~5 years ago. [b] The "cool" has moved onto something else. Don't dismiss this factor, it was certainly visible in the UG space. "The Internet" and "IT" were the *it* thing, Open Source and the web were a intriguing and mysterious novelties. Now they are mainstream, ho hum. Coolness seekers have moved on to graze in other fields [SEM and SM mostly]. In reference to [a] there are several very good Python texts available and the online documentation is fair to decent. > So the OP's initiative should be an incentive to think on the format > of the interaction between all the range of Python users, from newbees > to gurus. We are in the 2.0 era, with social networks all over the > place using a pleasant interface, I suppose that is a matter of taste; I hear no shortage of complaints that Facebook et al are complicated and hard to use. -- Adam Tauno Williams LPIC-1, Novell CLA OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba From ben+python at benfinney.id.au Thu Jun 3 07:23:59 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 03 Jun 2010 21:23:59 +1000 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> Message-ID: <87vda0cqb4.fsf@benfinney.id.au> Adam Tauno Williams writes: > So? NNTP is the living dead. Time to let it go. The capabilities of NNTP clients are much better than email for tracking threaded discussions in multiple forums. I'll let it go when something better comes along, and not before. > Most people use this list via e-mail, which everyone has access to and > knows how to use. This is different from NNTP how? If you're referring to knowing how to use the tools, there are many tools that present both email *and* NNTP with the same user interface. If you're referring to organisational network policies that block NNTP, that's also true for email. -- \ ?I believe in making the world safe for our children, but not | `\ our children's children, because I don't think children should | _o__) be having sex.? ?Jack Handey | Ben Finney From paul.nospam at rudin.co.uk Thu Jun 3 07:35:32 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 03 Jun 2010 12:35:32 +0100 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> Message-ID: <87k4qg5oxn.fsf@rudin.co.uk> Adam Tauno Williams writes: > Most people use this list via e-mail... Do you know this to be the case, or is that a guess? From michele.simionato at gmail.com Thu Jun 3 07:46:07 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 3 Jun 2010 04:46:07 -0700 (PDT) Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87zkzccx3q.fsf@benfinney.id.au> <88192331-3301-47f8-8742-0a26eb9a65f0@j9g2000vbp.googlegroups.com> Message-ID: <3182ab4c-9015-4950-adf6-2aa3311992f7@k39g2000yqd.googlegroups.com> On Jun 3, 12:28?pm, "Martin P. Hellwig" wrote: > On the other hand it might not be so bad that you don't get questions > from users here who are unable to use a nntp reader or news to mail service. I am unable to use a nntp reader or news to mail service. I use the Google Groups interface and I am happy with it. From paul.nospam at rudin.co.uk Thu Jun 3 07:49:40 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 03 Jun 2010 12:49:40 +0100 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87zkzccx3q.fsf@benfinney.id.au> <88192331-3301-47f8-8742-0a26eb9a65f0@j9g2000vbp.googlegroups.com> <3182ab4c-9015-4950-adf6-2aa3311992f7@k39g2000yqd.googlegroups.com> Message-ID: <87fx145oa3.fsf@rudin.co.uk> Michele Simionato writes: > On Jun 3, 12:28?pm, "Martin P. Hellwig" > wrote: >> On the other hand it might not be so bad that you don't get questions >> from users here who are unable to use a nntp reader or news to mail service. > > I am unable to use a nntp reader or news to mail service. I use the > Google Groups interface and I am happy with it. Arguably google groups *is* an nntp reader, although you don't get a choice about which news server it talks to. From martin.hellwig at dcuktec.org Thu Jun 3 08:09:24 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 03 Jun 2010 13:09:24 +0100 Subject: Python Forum In-Reply-To: <3182ab4c-9015-4950-adf6-2aa3311992f7@k39g2000yqd.googlegroups.com> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87zkzccx3q.fsf@benfinney.id.au> <88192331-3301-47f8-8742-0a26eb9a65f0@j9g2000vbp.googlegroups.com> <3182ab4c-9015-4950-adf6-2aa3311992f7@k39g2000yqd.googlegroups.com> Message-ID: On 06/03/10 12:46, Michele Simionato wrote: > On Jun 3, 12:28 pm, "Martin P. Hellwig" > wrote: >> On the other hand it might not be so bad that you don't get questions >> from users here who are unable to use a nntp reader or news to mail service. > > I am unable to use a nntp reader or news to mail service. I use the > Google Groups interface and I am happy with it. Good for you, just a shame that quite a bit of the regulars here ignore anything that comes from google groups, not me though, I just mentally ignore posts. -- mph From alanwilter at gmail.com Thu Jun 3 08:11:32 2010 From: alanwilter at gmail.com (Alan) Date: Thu, 3 Jun 2010 13:11:32 +0100 Subject: python2.6 atexit not working with programme using threads, but python 2.5 works Message-ID: Hi there, I got a code here to investigate and one big issue is that it uses threads and have a cleanup function (that will halt the threads) called via atexit. That all work fine with python 2.5 but when using python 2.6, if I have threading running, atexit never calls my cleanup function. If explicitly do cleanup(...) it works. If I have no threads on, atexit works too. Any idea of how to debug this would very appreciated. Thanks, Alan Python 2.6.5 (r265:79063, May 13 2010, 15:11:52) [GCC 4.2.1 (Apple Inc. build 5659)] on darwin -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. >>http://www.bio.cam.ac.uk/~awd28<< -------------- next part -------------- An HTML attachment was scrubbed... URL: From awilliam at whitemice.org Thu Jun 3 08:16:40 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Thu, 03 Jun 2010 08:16:40 -0400 Subject: Python Forum In-Reply-To: <87k4qg5oxn.fsf@rudin.co.uk> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87k4qg5oxn.fsf@rudin.co.uk> Message-ID: <1275567400.7651.1.camel@linux-yu4c.site> On Thu, 2010-06-03 at 12:35 +0100, Paul Rudin wrote: > Adam Tauno Williams writes: > > Most people use this list via e-mail... > Do you know this to be the case, or is that a guess? Scan through a bunch of threads with show-headers. Watch the User-Agent value (set by the senders client). The results become obvious pretty quickly. And it is generally interesting to see the User-Agent mix of a given group of users. -- Adam Tauno Williams LPIC-1, Novell CLA OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba From python.list at tim.thechases.com Thu Jun 3 08:29:42 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 03 Jun 2010 07:29:42 -0500 Subject: Python Forum In-Reply-To: <1275567400.7651.1.camel@linux-yu4c.site> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87k4qg5oxn.fsf@rudin.co.uk> <1275567400.7651.1.camel@linux-yu4c.site> Message-ID: <4C07A036.6060706@tim.thechases.com> On 06/03/2010 07:16 AM, Adam Tauno Williams wrote: >>> Most people use this list via e-mail... >> Do you know this to be the case, or is that a guess? > > Scan through a bunch of threads with show-headers. Watch the User-Agent > value (set by the senders client). The results become obvious pretty > quickly. It can be a bit misleading though -- some UAs allow you to read both mail & nntp with the same interface (e.g., my Thunderbird UA). I read via gmane's nntp, but it's a "mail" program. I'd likely return to reading via email if TB allowed me to kill threads & sub-threads in email like it does in newsgroups. -tkc From usenot at geekmail.INVALID Thu Jun 3 08:34:40 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Thu, 3 Jun 2010 14:34:40 +0200 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87zkzccx3q.fsf@benfinney.id.au> <88192331-3301-47f8-8742-0a26eb9a65f0@j9g2000vbp.googlegroups.com> Message-ID: <20100603143440.30e34ce6@geekmail.INVALID> On Thu, 3 Jun 2010 03:16:03 -0700 (PDT) Pierre Quentel wrote: > So the OP's initiative should be an incentive to think on the format > of the interaction between all the range of Python users, from newbees > to gurus. We are in the 2.0 era, with social networks all over the > place using a pleasant interface, while c.l.p has a rather austere > look and feel, with text only, no way to present code snippets in a > different font / background than discussions, and even an unintuitive > way of entering links... I don't really have a well founded opinion on this yet, so I'm just throwing it out there: From the moment I first heard about it, I've always felt that Wave (that Google thing nobody cares about anymore) was a perfect "replacement" for the lot of newsgroups, forums and mailing lists. But consolidation is the *only* way to go, really. The parallelism between c.l.p. and python-list is great already. Now throw some sort of Forum in the mix, and a Wave server, and you're set. Should be easy enough with Python. "import pycommunity" anyone? /W -- INVALID? DE! From paul.nospam at rudin.co.uk Thu Jun 3 08:42:26 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 03 Jun 2010 13:42:26 +0100 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87k4qg5oxn.fsf@rudin.co.uk> Message-ID: <877hmg5lu5.fsf@rudin.co.uk> Adam Tauno Williams writes: > On Thu, 2010-06-03 at 12:35 +0100, Paul Rudin wrote: >> Adam Tauno Williams writes: >> > Most people use this list via e-mail... >> Do you know this to be the case, or is that a guess? > > Scan through a bunch of threads with show-headers. Watch the User-Agent > value (set by the senders client). The results become obvious pretty > quickly. > > And it is generally interesting to see the User-Agent mix of a given > group of users. So... by that criteria do you count me as email reader or nntp reader? Gnus fills in the user-agent field just the same in either case. From victorsubervi at gmail.com Thu Jun 3 08:49:44 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 3 Jun 2010 08:49:44 -0400 Subject: Another MySQL Question Message-ID: Hi; I have this code: options = '' our_options = [] our_options_string = '' for op in ops: options += '%s varchar(40) not null, ' % (op[0].upper() + op[1:]) our_options.append('%s' % form.getfirst('%s' % op)) our_options_string += '%s", "' % op cursor.execute('''create table if not exists tmp%s ( Store varchar(40) not null, PatientID varchar(40) not null, ProdID varchar(40) not null, Pkg varchar(10) not null, %s)''' % (tmpTable, options[:-2])) sql_string = 'insert into tmp%s values (%s, %s, %s, %s, "%s")' % (tmpTable, store, patientID, prodid, pkg, our_options_string[:-4]) print sql_string sql = 'insert into tmp%s values (%s, %s, %s, %s, %%s)' % (tmpTable, store, patientID, prodid, pkg) cursor.execute(sql, (our_options,)) Now, I can insert that printed string, but my execute throws this error: Traceback (most recent call last): File "/var/www/html/angrynates.com/cart/insertOrder.py", line 235, in ? insertOrder() File "/var/www/html/angrynates.com/cart/insertOrder.py", line 228, in insertOrder cursor.execute(sql, (our_options,)) File "/usr/lib64/python2.4/site-packages/MySQLdb/cursors.py", line 163, in execute self.errorhandler(self, exc, value) File "/usr/lib64/python2.4/site-packages/MySQLdb/connections.py", line 35, in defaulterrorhandler raise errorclass, errorvalue OperationalError: (1136, "Column count doesn't match value count at row 1") So it appears to me that it's saying there's only one value packed in our_options; however, there are in fact two. Please advise. TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From awilliam at whitemice.org Thu Jun 3 08:50:59 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Thu, 03 Jun 2010 08:50:59 -0400 Subject: Python Forum In-Reply-To: <877hmg5lu5.fsf@rudin.co.uk> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87k4qg5oxn.fsf@rudin.co.uk> <877hmg5lu5.fsf@rudin.co.uk> Message-ID: <1275569459.7651.3.camel@linux-yu4c.site> On Thu, 2010-06-03 at 13:42 +0100, Paul Rudin wrote: > Adam Tauno Williams writes: > > On Thu, 2010-06-03 at 12:35 +0100, Paul Rudin wrote: > >> Adam Tauno Williams writes: > >> > Most people use this list via e-mail... > >> Do you know this to be the case, or is that a guess > > Scan through a bunch of threads with show-headers. Watch the User-Agent > > value (set by the senders client). The results become obvious pretty > > quickly. > > And it is generally interesting to see the User-Agent mix of a given > > group of users. > So... by that criteria do you count me as email reader or nntp reader? NNTP > Gnus fills in the user-agent field just the same in either case. Sure. But Thunderbird, Horde, Squirrel, Google/GMail, Evolution, and Outlook/OWA are *not* NNTP agents. -- Adam Tauno Williams LPIC-1, Novell CLA OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba From python at bdurham.com Thu Jun 3 09:00:37 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 03 Jun 2010 09:00:37 -0400 Subject: How to efficiently work with gettext PO files when making small edits to large text values Message-ID: <1275570037.12479.1378283239@webmail.messagingengine.com> Any one using the GNU gettext utilities to internationalize their python applications? I'm looking for tips and/or tools on how to efficiently work with gettext PO files when making small edits to large msgid values. Example: We have lots of multi-sentence/multi-paragraph messages that are stored in our PO message catalog files. If we make a very minor change to a message, perhaps editing a single sentence or even correcting punctuation, we lose our original translation when we run the msgmerge utility. Rather than re-translate long messages (that have already gone through an editorial approval process) from scratch, our translators return to backup copies of their PO files and manually search for the text of the last msgid/msgstr translation pair which they then diff against the current msgid values to see what has changed, followed by a copy and paste of the last translation which they then edit to reflect the updated msgid value. That's a lot of work! Certainly there must be a better way of handling this type of workflow? Is there a best practice way to archive and find previous translations that are no longer in a PO file? One idea that comes to mind is to store a unique msg id in the text of our messages or in the comments that precede our message and use this id to retrieve previous msgid/msgstr translation pairs for review. Or are there PO editors or online services that make this process more efficient? Thanks, Malcolm Note: This question also cross-posted on Stackoverflow (an excellent developer forum) From invalid at invalid.invalid Thu Jun 3 09:08:01 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 3 Jun 2010 13:08:01 +0000 (UTC) Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> Message-ID: On 2010-06-03, News123 wrote: > pyDev wrote: >> Hello, >> >> I would like to let the community know that there is a new web-based >> forum for Python enthusiasts over at PythonForum.org (http:// >> pythonforum.org). Web-based forums is a preferred method by Python >> newcomers to get help in exploring the world of Python and programming >> overall. The main goal of PythonForum.org is to popularize Python by >> welcoming all newcomers. Recently the forum got "attacked" with >> questions by users just starting out with Python. I hope here will be >> someone ready to welcome and help newcomers to enter the beautiful >> world of Python. >> > > I fully agree with the feedback, that creating a new forum is not such > an excellent idea. currently the critical mass seems to be here and I > appreciate this a lot. > > However, whether we like it or not: > Fewer and fewer newcomers are willing, knowledgable, aware of nntp > > If you think, that newbies are unlikely to use nntp, then create a > forum, web front end or whatever, which looks very nice and cool, which > will automatically relay messages (forward and backward) to this group. You mean like this? http://news.gmane.org/gmane.comp.python.general > In my opinion new forums should integrate nntp and not try to replace > it. > > An nntp gateway on just another server is also not as nice as just > communicating with the existing feeds. I'm don't know what "communicating with the existing feeds" means. -- Grant Edwards grant.b.edwards Yow! Oh my GOD -- the at SUN just fell into YANKEE gmail.com STADIUM!! From invalid at invalid.invalid Thu Jun 3 09:09:28 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 3 Jun 2010 13:09:28 +0000 (UTC) Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87zkzccx3q.fsf@benfinney.id.au> <88192331-3301-47f8-8742-0a26eb9a65f0@j9g2000vbp.googlegroups.com> <3182ab4c-9015-4950-adf6-2aa3311992f7@k39g2000yqd.googlegroups.com> Message-ID: On 2010-06-03, Martin P. Hellwig wrote: > On 06/03/10 12:46, Michele Simionato wrote: >> On Jun 3, 12:28 pm, "Martin P. Hellwig" >> wrote: >>> On the other hand it might not be so bad that you don't get questions >>> from users here who are unable to use a nntp reader or news to mail service. >> >> I am unable to use a nntp reader or news to mail service. I use the >> Google Groups interface and I am happy with it. > > Good for you, just a shame that quite a bit of the regulars here ignore > anything that comes from google groups, It's sad that Google won't clean up its act with respect to facilitating spamming, but ignore posts from Google Groups has cut the spam down to almost 0. > not me though, I just mentally ignore posts. -- Grant Edwards grant.b.edwards Yow! All this time I've at been VIEWING a RUSSIAN gmail.com MIDGET SODOMIZE a HOUSECAT! From invalid at invalid.invalid Thu Jun 3 09:12:34 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 3 Jun 2010 13:12:34 +0000 (UTC) Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87k4qg5oxn.fsf@rudin.co.uk> <877hmg5lu5.fsf@rudin.co.uk> Message-ID: On 2010-06-03, Adam Tauno Williams wrote: > On Thu, 2010-06-03 at 13:42 +0100, Paul Rudin wrote: >> Adam Tauno Williams writes: >> > On Thu, 2010-06-03 at 12:35 +0100, Paul Rudin wrote: >> >> Adam Tauno Williams writes: >> >> > Most people use this list via e-mail... >> >> Do you know this to be the case, or is that a guess >> > Scan through a bunch of threads with show-headers. Watch the User-Agent >> > value (set by the senders client). The results become obvious pretty >> > quickly. >> > And it is generally interesting to see the User-Agent mix of a given >> > group of users. >> So... by that criteria do you count me as email reader or nntp reader? > > NNTP > >> Gnus fills in the user-agent field just the same in either case. > > Sure. But Thunderbird, Horde, Squirrel, Google/GMail, Evolution, and > Outlook/OWA are *not* NNTP agents. Thunderbird, Evolution and Outlook are all NNTP clients. Not sure if that's different than being an "agent". -- Grant Edwards grant.b.edwards Yow! BARRY ... That was at the most HEART-WARMING gmail.com rendition of "I DID IT MY WAY" I've ever heard!! From lie.1296 at gmail.com Thu Jun 3 09:13:52 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 03 Jun 2010 23:13:52 +1000 Subject: Python Forum In-Reply-To: References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87k4qg5oxn.fsf@rudin.co.uk> <877hmg5lu5.fsf@rudin.co.uk> Message-ID: <4c07ab0a$1@dnews.tpgi.com.au> On 06/03/10 22:50, Adam Tauno Williams wrote: > On Thu, 2010-06-03 at 13:42 +0100, Paul Rudin wrote: >> Adam Tauno Williams writes: >>> On Thu, 2010-06-03 at 12:35 +0100, Paul Rudin wrote: >>>> Adam Tauno Williams writes: >>>>> Most people use this list via e-mail... >>>> Do you know this to be the case, or is that a guess >>> Scan through a bunch of threads with show-headers. Watch the User-Agent >>> value (set by the senders client). The results become obvious pretty >>> quickly. >>> And it is generally interesting to see the User-Agent mix of a given >>> group of users. >> So... by that criteria do you count me as email reader or nntp reader? > > NNTP > >> Gnus fills in the user-agent field just the same in either case. > > Sure. But Thunderbird, Horde, Squirrel, Google/GMail, Evolution, and > Outlook/OWA are *not* NNTP agents. > Then how come my Thunderbird could talk with an NNTP server? Directly without going through the bowels of a newsgroup-to-mailing list server. From cjwilliams43 at gmail.com Thu Jun 3 10:10:38 2010 From: cjwilliams43 at gmail.com (Colin J. Williams) Date: Thu, 03 Jun 2010 10:10:38 -0400 Subject: Python Forum In-Reply-To: References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> Message-ID: <4C07B7DE.6040808@gmail.com> On 03-Jun-10 09:08 AM, Grant Edwards wrote: > On 2010-06-03, News123 wrote: >> pyDev wrote: >>> Hello, >>> >>> I would like to let the community know that there is a new web-based >>> forum for Python enthusiasts over at PythonForum.org (http:// >>> pythonforum.org). Web-based forums is a preferred method by Python >>> newcomers to get help in exploring the world of Python and programming >>> overall. The main goal of PythonForum.org is to popularize Python by >>> welcoming all newcomers. Recently the forum got "attacked" with >>> questions by users just starting out with Python. I hope here will be >>> someone ready to welcome and help newcomers to enter the beautiful >>> world of Python. >>> >> >> I fully agree with the feedback, that creating a new forum is not such >> an excellent idea. currently the critical mass seems to be here and I >> appreciate this a lot. >> >> However, whether we like it or not: >> Fewer and fewer newcomers are willing, knowledgable, aware of nntp >> >> If you think, that newbies are unlikely to use nntp, then create a >> forum, web front end or whatever, which looks very nice and cool, which >> will automatically relay messages (forward and backward) to this group. > > You mean like this? > > http://news.gmane.org/gmane.comp.python.general > > I use gmane via nntp (news.gmane.org port 119) but, as the link above shows, there are threading problems. Colin W. >> In my opinion new forums should integrate nntp and not try to replace >> it. >> >> An nntp gateway on just another server is also not as nice as just >> communicating with the existing feeds. > > I'm don't know what "communicating with the existing feeds" means. > From cjwilliams43 at gmail.com Thu Jun 3 10:11:06 2010 From: cjwilliams43 at gmail.com (Colin J. Williams) Date: Thu, 03 Jun 2010 10:11:06 -0400 Subject: Python Forum In-Reply-To: References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> Message-ID: <4C07B7FA.2030009@gmail.com> On 03-Jun-10 09:08 AM, Grant Edwards wrote: > On 2010-06-03, News123 wrote: >> pyDev wrote: >>> Hello, >>> >>> I would like to let the community know that there is a new web-based >>> forum for Python enthusiasts over at PythonForum.org (http:// >>> pythonforum.org). Web-based forums is a preferred method by Python >>> newcomers to get help in exploring the world of Python and programming >>> overall. The main goal of PythonForum.org is to popularize Python by >>> welcoming all newcomers. Recently the forum got "attacked" with >>> questions by users just starting out with Python. I hope here will be >>> someone ready to welcome and help newcomers to enter the beautiful >>> world of Python. >>> >> >> I fully agree with the feedback, that creating a new forum is not such >> an excellent idea. currently the critical mass seems to be here and I >> appreciate this a lot. >> >> However, whether we like it or not: >> Fewer and fewer newcomers are willing, knowledgable, aware of nntp >> >> If you think, that newbies are unlikely to use nntp, then create a >> forum, web front end or whatever, which looks very nice and cool, which >> will automatically relay messages (forward and backward) to this group. > > You mean like this? > > http://news.gmane.org/gmane.comp.python.general > > I use gmane via nntp (news.gmane.org port 119) but, as the link above shows, there are threading problems. Colin W. >> In my opinion new forums should integrate nntp and not try to replace >> it. >> >> An nntp gateway on just another server is also not as nice as just >> communicating with the existing feeds. > > I'm don't know what "communicating with the existing feeds" means. > From cjwilliams43 at gmail.com Thu Jun 3 10:11:06 2010 From: cjwilliams43 at gmail.com (Colin J. Williams) Date: Thu, 03 Jun 2010 10:11:06 -0400 Subject: Python Forum In-Reply-To: References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> Message-ID: <4C07B7FA.2030009@gmail.com> On 03-Jun-10 09:08 AM, Grant Edwards wrote: > On 2010-06-03, News123 wrote: >> pyDev wrote: >>> Hello, >>> >>> I would like to let the community know that there is a new web-based >>> forum for Python enthusiasts over at PythonForum.org (http:// >>> pythonforum.org). Web-based forums is a preferred method by Python >>> newcomers to get help in exploring the world of Python and programming >>> overall. The main goal of PythonForum.org is to popularize Python by >>> welcoming all newcomers. Recently the forum got "attacked" with >>> questions by users just starting out with Python. I hope here will be >>> someone ready to welcome and help newcomers to enter the beautiful >>> world of Python. >>> >> >> I fully agree with the feedback, that creating a new forum is not such >> an excellent idea. currently the critical mass seems to be here and I >> appreciate this a lot. >> >> However, whether we like it or not: >> Fewer and fewer newcomers are willing, knowledgable, aware of nntp >> >> If you think, that newbies are unlikely to use nntp, then create a >> forum, web front end or whatever, which looks very nice and cool, which >> will automatically relay messages (forward and backward) to this group. > > You mean like this? > > http://news.gmane.org/gmane.comp.python.general > > I use gmane via nntp (news.gmane.org port 119) but, as the link above shows, there are threading problems. Colin W. >> In my opinion new forums should integrate nntp and not try to replace >> it. >> >> An nntp gateway on just another server is also not as nice as just >> communicating with the existing feeds. > > I'm don't know what "communicating with the existing feeds" means. > From ben+python at benfinney.id.au Thu Jun 3 10:57:15 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 04 Jun 2010 00:57:15 +1000 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87zkzccx3q.fsf@benfinney.id.au> <88192331-3301-47f8-8742-0a26eb9a65f0@j9g2000vbp.googlegroups.com> <20100603143440.30e34ce6@geekmail.INVALID> Message-ID: <87iq60cgfo.fsf@benfinney.id.au> Andreas Waldenburger writes: > But consolidation is the *only* way to go, really. The parallelism > between c.l.p. and python-list is great already. Now throw some sort > of Forum in the mix This already *is* a forum. Whatever it is you think is needed, it's already a forum. Can you be more specific about what you would add? -- \ ?Are you pondering what I'm pondering?? ?I think so, Brain, but | `\ I don't think Kay Ballard's in the union.? ?_Pinky and The | _o__) Brain_ | Ben Finney From amit.pureenergy at gmail.com Thu Jun 3 11:09:33 2010 From: amit.pureenergy at gmail.com (Amit Sethi) Date: Thu, 3 Jun 2010 20:39:33 +0530 Subject: No subject Message-ID: Hi , I wish to execute some user submitted python code and have absolutely no other way out . I saw that there used to be a module called rexec which could define which modules can be imported and which cannot however exec doesn't have that kind of feature . Please if you could tell me what would the best possible ways of sandboxing python code . -- A-M-I-T S|S From ronyekr at gmail.com Thu Jun 3 11:11:38 2010 From: ronyekr at gmail.com (ekr3d) Date: Thu, 3 Jun 2010 08:11:38 -0700 (PDT) Subject: Gift 4 U Message-ID: <8bc05671-134d-43a8-9ea2-21a4a0c0f832@o4g2000vbo.googlegroups.com> Do you want the safety of the computer ? * Take this gift * Advanced SystemCare Free 3.3.1 http://free-ekramy.blogspot.com ****************** Are you introduced to the 2010 Men's Fashion fashion-ekramy.blogspot.com/2010/04/man-fashion-week-z-zegna- spring-2010.html ************************ Are you happy? Read this place simple and strong !!!!! free-ekramy.blogspot.com/ **************************** 7 Steps to the work of makeup magic free-ekramy.blogspot.com/2010/05/7-steps-to-great-makeup.html ***************************** Ekramy From uknews00 at gmail.com Thu Jun 3 11:17:32 2010 From: uknews00 at gmail.com (money mania) Date: Thu, 3 Jun 2010 08:17:32 -0700 (PDT) Subject: Simple hack to get $500 to your home. Message-ID: Simple hack to get $500 to your home at http://uslatest.tk Due to high security risks,i have hidden the cheque link in an image. in that website on left side below search box, click on image and enter your name and address where you want to receive your cheque.please dont tell to anyone. From lists at zopyx.com Thu Jun 3 11:23:31 2010 From: lists at zopyx.com (Andreas Jung) Date: Thu, 03 Jun 2010 17:23:31 +0200 Subject: SOAP with fancy HTTPS requirements Message-ID: <4C07C8F3.20409@zopyx.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi there, I need to implement the following: sending SOAP requests and receiving SOAP responses over HTTPS with - authentication based on client-certificates _and_ basic authorization - verification of the server cert The client cert is protected with a passphrase and there must be some mechanism for passing the passphrase to Python. Is there some SOAP module doing this out-of-the-box? I tried myself with httplib.HTTPSConnection what I could not find a way passing the passphrase to the HTTPSConnection..Python always pops up with an input for the passphrase (likely this is coming from OpenSSL). Any ideas? Andreas -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkwHyPMACgkQCJIWIbr9KYzFMACfXtDzm+XnpdINf1TjG7EFazp6 PUUAnieOZ4pMH2Ss1TIKyCXF59jugfO8 =FrTY -----END PGP SIGNATURE----- -------------- next part -------------- A non-text attachment was scrubbed... Name: lists.vcf Type: text/x-vcard Size: 316 bytes Desc: not available URL: From bob at passcal.nmt.edu Thu Jun 3 11:39:38 2010 From: bob at passcal.nmt.edu (Bob Greschke) Date: Thu, 3 Jun 2010 09:39:38 -0600 Subject: Windows and My Documents Message-ID: <2010060309393816807-bob@passcalnmtedu> I know this must have been asked before, but today Google is not my friend. How do I do a "listdir" (or whatever I need to use) of the Desktop on a Windows machine and have "folders" like My Documents show up in the result? I'm specifically trying to get a link to VMWare Shared Folders to show up so I can navigate to files in OSX from WinXP running in VMWare, but My Documents doesn't show up, either. The docs for listdir says it doesn't follow links and I don't think I want to tell os.walk to followlinks as that could be zillions of files. Thanks! Bob From anand.shashwat at gmail.com Thu Jun 3 11:42:18 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 3 Jun 2010 21:12:18 +0530 Subject: No subject In-Reply-To: References: Message-ID: I have not much idea but Online Judges like SPOJ/codechef have regular programming-contests and python is one of allowed languages. So yes, it's possible. If I guess right, are you making an Online Judge for python. On Thu, Jun 3, 2010 at 8:39 PM, Amit Sethi wrote: > Hi , > > I wish to execute some user submitted python code and have absolutely > no other way out . I saw that there used to be a module called rexec > which could define which modules can be imported and which cannot > however exec doesn't have that kind of feature . Please if you could > tell me what would the best possible ways of sandboxing python code . > -- > A-M-I-T S|S > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From memilanuk at gmail.com Thu Jun 3 11:43:58 2010 From: memilanuk at gmail.com (Monte Milanuk) Date: Thu, 3 Jun 2010 15:43:58 +0000 (UTC) Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <1275560120.8775.6.camel@linux-yu4c.site> Message-ID: Adam Tauno Williams whitemice.org> writes: > > However, whether we like it or not: > > Fewer and fewer newcomers are willing, knowledgable, aware of nntp > > So? NNTP is the living dead. Time to let it go. > True. Decent NNTP access is harder to find. Not impossible, but no longer a 'free' part of most standard ISP access any more. Gmane provides a mail-to- nntp gateway which is great for those who like to read it via nntp. > Most people use this list via e-mail, which everyone has access to and > knows how to use. > > The best solution I've seen is what is used by the Mono project; which > provides both a "web forum" and a mail list interface. > > > > > It works very well; and everyone [except the 3 or 4 NNTP hold outs] are > happy. > Now that looks pretty slick - both sides get to have what they want, and the 'pool' of knowledgeable persons stays condensed rather than dispersed. Very cool. Monte From vinay_sajip at yahoo.co.uk Thu Jun 3 11:46:03 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Thu, 3 Jun 2010 08:46:03 -0700 (PDT) Subject: Vote to Add Python Package "pubsub" to the Python Standard Library References: <6b9d2898-4166-40b4-9016-dc55dee77d00@q33g2000vbt.googlegroups.com> Message-ID: <8799a47b-9d16-4187-8862-31570c9d9b11@v25g2000yqv.googlegroups.com> On Jun 2, 4:09?am, Carl Banks wrote: > I think it has a pretty good chance of being accepted, too. ?The > publish-subscribe pattern, if you will, seems to have been implemented > separately in many places. ?The logging module in the standard library > uses something like this. Only in a very general sense, if you mean the separation of concerns between loggers and handlers. There isn't a general-purpose pub/sub infrastructure built into it. Of course, pub/sub is just one type of message architecture. I would say that it would be nice to have a Python messaging package which had pub/sub as one of several different approaches - which is often done these days using things like RabbitMQ. Are there any such (pure-Python or Python + C) packages out there which are generally accepted as being head and shoulders above others in the same category? It may be too early to bless any one messaging package for the stdlib - "let a thounsand flowers bloom" and all that. In any case, stdlib inclusion can be a double-edged sword in terms of backward- compatibility constraints, leading to reduced developer/maintainer flexibility going forward. Regards, Vinay Sajip From exarkun at twistedmatrix.com Thu Jun 3 11:50:16 2010 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Thu, 03 Jun 2010 15:50:16 -0000 Subject: SOAP with fancy HTTPS requirements In-Reply-To: <4C07C8F3.20409@zopyx.com> References: <4C07C8F3.20409@zopyx.com> Message-ID: <20100603155016.1988.1292523705.divmod.xquotient.11@localhost.localdomain> On 03:23 pm, lists at zopyx.com wrote: >-----BEGIN PGP SIGNED MESSAGE----- >Hash: SHA1 > >Hi there, > >I need to implement the following: > >sending SOAP requests and receiving SOAP responses >over HTTPS with > >- authentication based on client-certificates _and_ basic authorization >- verification of the server cert > >The client cert is protected with a passphrase and there must be some >mechanism for passing the passphrase to Python. > >Is there some SOAP module doing this out-of-the-box? > >I tried myself with httplib.HTTPSConnection what I could not find a way >passing the passphrase to the HTTPSConnection..Python always pops up >with an input for the passphrase (likely this is coming from OpenSSL). > >Any ideas? You'll find this easier with one of the third-party SSL libraries, like M2Crypto or pyOpenSSL. The stdlib SSL support is fairly minimal. For example, I *don't* see any support for passphrase-protected private keys in the Python 2.6 SSL APIs. Compare this to the pyOpenSSL API load_privatekey, which accepts the passphrase as an argument: http://packages.python.org/pyOpenSSL/openssl-crypto.html Or lets you specify a callback which will be called whenever a passphrase is required, set_passwd_cb: http://packages.python.org/pyOpenSSL/openssl-context.html Jean-Paul From mail at timgolden.me.uk Thu Jun 3 11:57:11 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 03 Jun 2010 16:57:11 +0100 Subject: Windows and My Documents In-Reply-To: <2010060309393816807-bob@passcalnmtedu> References: <2010060309393816807-bob@passcalnmtedu> Message-ID: <4C07D0D7.30201@timgolden.me.uk> On 03/06/2010 16:39, Bob Greschke wrote: > How do I do a "listdir" (or whatever I need to use) of the Desktop on a > Windows machine and have "folders" like My Documents show up in the result? > > I'm specifically trying to get a link to VMWare Shared Folders to show > up so I can navigate to files in OSX from WinXP running in VMWare, but > My Documents doesn't show up, either. > > The docs for listdir says it doesn't follow links and I don't think I > want to tell os.walk to followlinks as that could be zillions of files. Depends exactly what '"folders" like My Documents' means (since I'm unfamiliar with VMWare Shared Folders) but you almost certainly want to use the Shell functions to walk the shell from the Desktop root. There was a short thread recently about it which I'll try to dig up (digs...): http://mail.python.org/pipermail/python-win32/2010-May/010475.html TJG From texaspeso01 at gmail.com Thu Jun 3 11:59:48 2010 From: texaspeso01 at gmail.com (money mania) Date: Thu, 3 Jun 2010 08:59:48 -0700 (PDT) Subject: See Hot Sexy Star Aishwarya Nude Bathing Videos In All Angles. Message-ID: <8be2fea7-ca34-4870-93a2-4d81f5847aeb@q39g2000prh.googlegroups.com> See Hot Sexy Star Aishwarya Nude Bathing Videos In All Angles. at http://uknews.tk Due to high sex content,i have hidden the videos in an image. in that website on left side below search box click on image and watch videos in all angles.please dont tell to anyone. From python at mrabarnett.plus.com Thu Jun 3 12:25:31 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 03 Jun 2010 17:25:31 +0100 Subject: Another MySQL Question In-Reply-To: References: Message-ID: <4C07D77B.90603@mrabarnett.plus.com> Victor Subervi wrote: > Hi; > I have this code: > > options = '' > our_options = [] > our_options_string = '' > for op in ops: > options += '%s varchar(40) not null, ' % (op[0].upper() + op[1:]) > our_options.append('%s' % form.getfirst('%s' % op)) > our_options_string += '%s", "' % op > cursor.execute('''create table if not exists tmp%s ( > Store varchar(40) not null, > PatientID varchar(40) not null, > ProdID varchar(40) not null, > Pkg varchar(10) not null, > %s)''' % (tmpTable, options[:-2])) > sql_string = 'insert into tmp%s values (%s, %s, %s, %s, "%s")' % > (tmpTable, store, patientID, prodid, pkg, our_options_string[:-4]) > print sql_string > sql = 'insert into tmp%s values (%s, %s, %s, %s, %%s)' % (tmpTable, > store, patientID, prodid, pkg) You're still using Python's % for values! > cursor.execute(sql, (our_options,)) > > Now, I can insert that printed string, but my execute throws this error: > > > Traceback (most recent call last): > File "/var/www/html/angrynates.com/cart/insertOrder.py > ", line 235, in ? > insertOrder() > File "/var/www/html/angrynates.com/cart/insertOrder.py > ", line 228, in insertOrder > cursor.execute(sql, (our_options,)) > File "/usr/lib64/python2.4/site-packages/MySQLdb/cursors.py", line > 163, in execute > self.errorhandler(self, exc, value) > File "/usr/lib64/python2.4/site-packages/MySQLdb/connections.py", line > 35, in defaulterrorhandler > raise errorclass, errorvalue > OperationalError: (1136, "Column count doesn't match value count at row 1") > > So it appears to me that it's saying there's only one value packed in > our_options; however, there are in fact two. Please advise. > So our_options is a list containing two values, which you're putting into a tuple: >>> our_options = ["first", "second"] >>> print len(our_options) 2 >>> value_tuple = (our_options,) >>> print len(value_tuple) 1 >>> In other words, value_tuple is a tuple which contains one value, a list. From stephane.larochelle at gmail.com Thu Jun 3 12:32:34 2010 From: stephane.larochelle at gmail.com (steph_awk) Date: Thu, 3 Jun 2010 09:32:34 -0700 (PDT) Subject: How to run a python script with a configuration file at command line ? Message-ID: <277d49ec-36c7-47df-bbf0-e89ecefdf0ea@e21g2000vbl.googlegroups.com> I have been searching for quite some times without success. I have a python script that needs to start from command line and it should have a config file to fill out the detais (itis one program, and many possible configurations). something as simple as PHP would be nice %> ./PHPscript -c configfile is there such a thing in Python? From lists at zopyx.com Thu Jun 3 12:46:19 2010 From: lists at zopyx.com (Andreas Jung) Date: Thu, 3 Jun 2010 18:46:19 +0200 Subject: How to run a python script with a configuration file at command line ? In-Reply-To: <277d49ec-36c7-47df-bbf0-e89ecefdf0ea@e21g2000vbl.googlegroups.com> References: <277d49ec-36c7-47df-bbf0-e89ecefdf0ea@e21g2000vbl.googlegroups.com> Message-ID: optparse is your friend. -aj 2010/6/3 steph_awk > I have been searching for quite some times without success. > > I have a python script that needs to start from command line and it > should have a config file to fill out the detais (itis one program, > and many possible configurations). > > something as simple as PHP would be nice %> ./PHPscript -c configfile > > is there such a thing in Python? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From phlip2005 at gmail.com Thu Jun 3 12:47:49 2010 From: phlip2005 at gmail.com (Phlip) Date: Thu, 3 Jun 2010 09:47:49 -0700 (PDT) Subject: What's a good XSL to translate xmlrunner.py output into a test report? Message-ID: Hypo Nt: Here's xmlrunner.py: http://www.rittau.org/python/xmlrunner.py you attach it to your developer tests, and it emits a file called "TEST-unittest.TestSuite.xml", containing auspicious wackiness like this: That looks just like the kind of stereotypical XML that XSL was designed to convert into HTML, for civilian reading! All the verbiage for XML test runners claim they do JUnit output, so that JUnit XSL files can convert them into HTML. So here's a sample JUNIT.XSL: http://www.google.com/codesearch/p?hl=en#T32D24pjTaw/trunk/test-integration-ui/resources/test-plugins/org.eclipse.swtbot.eclipse.junit4.headless_2.0.0.329-dev/JUNIT.XSL It contains matchers like these: And when I run it with this command line... xsltproc JUNIT.XSL TEST-unittest.TestSuite.xml ...it outputs nothing! Long story short, how do I format my test output prettily? All the bloggage on this seems to assume that everyone already knows this because _everyone_ graduated to Python thru Java... -- Phlip http://c2.com/cgi/wiki?ZeekLand From jeanmichel at sequans.com Thu Jun 3 12:50:27 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 03 Jun 2010 18:50:27 +0200 Subject: How to run a python script with a configuration file at command line ? In-Reply-To: References: <277d49ec-36c7-47df-bbf0-e89ecefdf0ea@e21g2000vbl.googlegroups.com> Message-ID: <4C07DD53.7080509@sequans.com> Andreas Jung wrote: > optparse > > is your friend. > > -aj > > 2010/6/3 steph_awk > > > I have been searching for quite some times without success. > > I have a python script that needs to start from command line and it > should have a config file to fill out the detais (itis one program, > and many possible configurations). > > something as simple as PHP would be nice %> ./PHPscript -c configfile > > is there such a thing in Python? > -- > http://mail.python.org/mailman/listinfo/python-list > > http://docs.python.org/library/configparser.html JM From bob at passcal.nmt.edu Thu Jun 3 12:50:28 2010 From: bob at passcal.nmt.edu (Bob Greschke) Date: Thu, 3 Jun 2010 10:50:28 -0600 Subject: Windows and My Documents References: <2010060309393816807-bob@passcalnmtedu> Message-ID: <2010060310502875249-bob@passcalnmtedu> On 2010-06-03 09:57:11 -0600, Tim Golden said: > On 03/06/2010 16:39, Bob Greschke wrote: >> How do I do a "listdir" (or whatever I need to use) of the Desktop on a >> Windows machine and have "folders" like My Documents show up in the result? >> >> I'm specifically trying to get a link to VMWare Shared Folders to show >> up so I can navigate to files in OSX from WinXP running in VMWare, but >> My Documents doesn't show up, either. >> >> The docs for listdir says it doesn't follow links and I don't think I >> want to tell os.walk to followlinks as that could be zillions of files. > > Depends exactly what '"folders" like My Documents' means (since I'm unfamiliar > with VMWare Shared Folders) but you almost certainly want to use the Shell > functions to walk the shell from the Desktop root. There was a short thread > recently about it which I'll try to dig up (digs...): > > http://mail.python.org/pipermail/python-win32/2010-May/010475.html > > TJG Well, My Documents is not a normal folder. It's not the same as right-clicking and creating a new folder. I don't know what it is, exactly. VMWare Shared Folders seems to be a normal sort of link to '\\.host\Share Folders', but not quite, however, beyond that I'm not sure what it is. If I create Shortcuts to My Documents and VSF those show up with listdir, but I cannot follow them; Python does not think they are directories, which they aren't (they show up from listdir as 'Shortcut to My Documents.lnk', for example). I'll take a look at the link above. Thanks! Bob From victorsubervi at gmail.com Thu Jun 3 12:57:37 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 3 Jun 2010 12:57:37 -0400 Subject: Another MySQL Question In-Reply-To: <4C07D77B.90603@mrabarnett.plus.com> References: <4C07D77B.90603@mrabarnett.plus.com> Message-ID: On Thu, Jun 3, 2010 at 12:25 PM, MRAB wrote: > So our_options is a list containing two values, which you're putting > into a tuple: > > >>> our_options = ["first", "second"] > >>> print len(our_options) > 2 > >>> value_tuple = (our_options,) > >>> print len(value_tuple) > 1 > >>> > > In other words, value_tuple is a tuple which contains one value, a list. > Understood. So I tried this (to include the other values): sql_string = 'insert into tmp%s values (%s, %s, %s, "%s")' % (tmpTable, store, prodid, pkg, our_options_string[:-4]) sql = 'insert into tmp%s values (%%s, %%s, %%s, %%s)' % tmpTable cursor.execute(sql, (store, prodid, pkg, our_options)) Which, of course, gives me the same error, because I'm still putting in the same len for the final value. What do now? TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From stephane.larochelle at gmail.com Thu Jun 3 13:12:24 2010 From: stephane.larochelle at gmail.com (steph_py) Date: Thu, 3 Jun 2010 10:12:24 -0700 (PDT) Subject: How to run a python script with a configuration file at command line ? References: <277d49ec-36c7-47df-bbf0-e89ecefdf0ea@e21g2000vbl.googlegroups.com> Message-ID: On Jun 3, 12:50?pm, Jean-Michel Pichavant wrote: > Andreas Jung wrote: > > optparse > > > is your friend. > > > -aj > > > 2010/6/3 steph_awk > > > > > ? ? I have been searching for quite some times without success. > > > ? ? I have a python script that needs to start from command line and it > > ? ? should have a config file to fill out the detais (itis one program, > > ? ? and many possible configurations). > > > ? ? something as simple as PHP would be nice ?%> ./PHPscript -c configfile > > > ? ? is there such a thing in Python? > > ? ? -- > > ? ?http://mail.python.org/mailman/listinfo/python-list > > http://docs.python.org/library/configparser.html > > JM configparser is fine if you know the name of the config file, but my scripts has many config files, I want to pass one by command line instead of hard coding every possibilities. This may be run as a cron job, which would automaticaly call up the proper config file depending on the database... From kai_28_2000 at yahoo.com Thu Jun 3 13:26:04 2010 From: kai_28_2000 at yahoo.com (kai028) Date: Thu, 03 Jun 2010 10:26:04 -0700 Subject: Embedding Python in a C extension References: Message-ID: Thanks for the reply. I'm looking into the Global Interpreter Lock today. On Thu, 03 Jun 2010 01:07:39 +0100, MRAB wrote: >Paul at mail.python.org wrote: >> I have a problem with embedding Python into a C extension in Windows >> Vista. I have implemented a timer routine in C as an extension, which >> I can import into Python 2.6.5 and run. Each timer interval, the >> extension calls a C CALLBACK function. I want to be able to have this >> CALLBACK function call a Python function, so that I can write the >> timer handler in Python. >> >> I can write Python functions and call them from a C extension function >> with no trouble in all cases EXCEPT when the function that calls the >> Python code is the timer's CALLBACK function. That is, if I call >> PyRun_SimpleString or PyRun_SimpleFile, or PyImport_ImportModule, or >> basically any Python-y function in the CALLBACK function, Python >> crashes and I get a window saying "Python has stopped working. Windows >> is searching for a solution to the problem." >> >> The Python code runs fine if I call it from a function in the >> extension that is not the CALLBACK function. And regular C code runs >> in the CALLBACK function properly. It only crashes if I try to run the >> Python code from the timer CALLBACK function (or any C function I call >> from the CALLBACK function). >> >> Does anybody know how to fix this? Is there a workaround of some sort? > >Here's a quote from the Python docs at: > > http://docs.python.org/c-api/init.html > >"""The Python interpreter is not fully thread safe. In order to support >multi-threaded Python programs, there's a global lock, called the global >interpreter lock or GIL, that must be held by the current thread before >it can safely access Python objects. Without the lock, even the simplest >operations could cause problems in a multi-threaded program: for >example, when two threads simultaneously increment the reference count >of the same object, the reference count could end up being incremented >only once instead of twice.""" > >That's probably what's happening to you. From kai_28_2000 at yahoo.com Thu Jun 3 13:26:40 2010 From: kai_28_2000 at yahoo.com (kai028) Date: Thu, 03 Jun 2010 10:26:40 -0700 Subject: Embedding Python in a C extension References: <21ed6e08-d60f-4326-9fd8-22c3debf5781@a16g2000prg.googlegroups.com> Message-ID: Thanks for the reply. I'm checking this out today. On Wed, 2 Jun 2010 22:30:37 -0700 (PDT), Carl Banks wrote: >On Jun 2, 1:46?pm, Paul Grunau wrote: >> I have a problem with embedding Python into a C extension in Windows >> Vista. I have implemented a timer routine in C as an extension, which >> I can import into Python 2.6.5 and run. Each timer interval, the >> extension calls a C CALLBACK function. I want to be able to have this >> CALLBACK function call a Python function, so that I can write the >> timer handler in Python. >> >> I can write Python functions and call them from a C extension function >> with no trouble in all cases EXCEPT when the function that calls the >> Python code is the timer's CALLBACK function. That is, if I call >> PyRun_SimpleString or PyRun_SimpleFile, or PyImport_ImportModule, or >> basically any Python-y function in the CALLBACK function, Python >> crashes and I get a window saying "Python has stopped working. Windows >> is searching for a solution to the problem." >> >> The Python code runs fine if I call it from a function in the >> extension that is not the CALLBACK function. And regular C code runs >> in the CALLBACK function properly. It only crashes if I try to run the >> Python code from the timer CALLBACK function (or any C function I call >> from the CALLBACK function). >> >> Does anybody know how to fix this? Is there a workaround of some sort? > >See PEP 311. When an external/uncertain thread calls into Python, it >has to be sure a Python thread state exists for that thread, and that >the thread holds the global interpreter lock. This is done by >surrounding all Python code with the following calls: > >PyGILState_STATE state = PyGILState_Ensure(); > >and > >PyGILState_Release(state); > >Normally, code in extension modules can rely on the current thread >having the global lock at all entry points, so it doesn't have worry >about the thread state. But a callback from a timer can't assume >that. > > >Carl Banks From python at lonely-star.org Thu Jun 3 13:47:45 2010 From: python at lonely-star.org (Nathan Huesken) Date: Thu, 3 Jun 2010 13:47:45 -0400 Subject: FIle transfer over network - with Pyro? Message-ID: <20100603134745.4dd3eaa9@SamZwo.tch.harvard.edu> Hi, I am writing a network application which needs from time to time do file transfer (I am writing the server as well as the client). For simple network messages, I use pyro because it is very comfortable. But I suspect, that doing a file transfer is very inefficient over pyro, am I right (the files are pretty big)? I somehow need to ensure, that the client requesting a file transfer is the same client getting the file. So some sort of authentication is needed. What library would you use to do the file transfer? Regards, Nathan From amit.pureenergy at gmail.com Thu Jun 3 13:56:11 2010 From: amit.pureenergy at gmail.com (Amit Sethi) Date: Thu, 3 Jun 2010 23:26:11 +0530 Subject: sandboxing python code Message-ID: On Thu, Jun 3, 2010 at 9:12 PM, Shashwat Anand wrote: > I have not much idea but Online Judges like SPOJ/codechef have regular > programming-contests and python is one of allowed languages. So yes, it's I am trying to make an online test for Python . P.S Sorry ,I did not realize I sent the mail without a subject -- A-M-I-T S|S From python at mrabarnett.plus.com Thu Jun 3 14:05:47 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 03 Jun 2010 19:05:47 +0100 Subject: Another MySQL Question In-Reply-To: References: Message-ID: <4C07EEFB.4030306@mrabarnett.plus.com> Victor Subervi wrote: > Hi; > I have this code: > > options = '' > our_options = [] > our_options_string = '' > for op in ops: > options += '%s varchar(40) not null, ' % (op[0].upper() + op[1:]) > our_options.append('%s' % form.getfirst('%s' % op)) > our_options_string += '%s", "' % op > cursor.execute('''create table if not exists tmp%s ( > Store varchar(40) not null, > PatientID varchar(40) not null, > ProdID varchar(40) not null, > Pkg varchar(10) not null, > %s)''' % (tmpTable, options[:-2])) > sql_string = 'insert into tmp%s values (%s, %s, %s, %s, "%s")' % > (tmpTable, store, patientID, prodid, pkg, our_options_string[:-4]) > print sql_string > sql = 'insert into tmp%s values (%s, %s, %s, %s, %%s)' % (tmpTable, > store, patientID, prodid, pkg) > cursor.execute(sql, (our_options,)) > > Now, I can insert that printed string, but my execute throws this error: > > > Traceback (most recent call last): > File "/var/www/html/angrynates.com/cart/insertOrder.py > ", line 235, in ? > insertOrder() > File "/var/www/html/angrynates.com/cart/insertOrder.py > ", line 228, in insertOrder > cursor.execute(sql, (our_options,)) > File "/usr/lib64/python2.4/site-packages/MySQLdb/cursors.py", line > 163, in execute > self.errorhandler(self, exc, value) > File "/usr/lib64/python2.4/site-packages/MySQLdb/connections.py", line > 35, in defaulterrorhandler > raise errorclass, errorvalue > OperationalError: (1136, "Column count doesn't match value count at row 1") > > So it appears to me that it's saying there's only one value packed in > our_options; however, there are in fact two. Please advise. > option_fields = [] option_values = [] for op in ops: option_fields.append('%s varchar(40) not null' % (op[0].upper() + op[1:]) option_values.append('%s' % form.getfirst('%s' % op)) cursor.execute('''create table if not exists tmp%s ( Store varchar(40) not null, PatientID varchar(40) not null, ProdID varchar(40) not null, Pkg varchar(10) not null, %s)''' % (tmpTable, ", ".join(option_fields))) values = (store, patientID, prodid, pkg) + tuple(option_values) placeholders = ["%s"] * len(values) sql = 'insert into tmp%s values (%s)' % (tmpTable, ", ".join(placeholders)) cursor.execute(sql, values) From victorsubervi at gmail.com Thu Jun 3 14:22:52 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 3 Jun 2010 14:22:52 -0400 Subject: Another MySQL Question In-Reply-To: References: Message-ID: On Thu, Jun 3, 2010 at 1:48 PM, Dennis Lee Bieber wrote: > On Thu, 3 Jun 2010 08:49:44 -0400, Victor Subervi > declaimed the following in > gmane.comp.python.general: > > > options += '%s varchar(40) not null, ' % (op[0].upper() + op[1:]) > > Please modernize... Python supports a .capitalize() method for > strings (I haven't checked the references but I'm pretty sure that's > been there since 2.3 at least) > > >>> s = "this is a mess" > >>> s.capitalize() > 'This is a mess' > >>> > Thanks. Didn't know about that!! > > sql = "insert into tmp%s values (%s)" % (tmpTable, > > ", ".join("%s" * > > (4 + len(our_options))) > cursor.execute(sql, tuple([store, patientID, prodid, pkg] > + our_options)) > A minor tweak of this worked nicely. Thanks again! And thanks to MRAB, too! beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Thu Jun 3 14:25:57 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 03 Jun 2010 20:25:57 +0200 Subject: Windows and My Documents In-Reply-To: References: <2010060309393816807-bob@passcalnmtedu> <2010060310502875249-bob@passcalnmtedu> Message-ID: > You're asking, it seems, for the equivalent of a UNIX softlink... > Normal Windows doesn't support those (I think they are in the OS > somewhere but not made visible to the user). Actually NTFS supports hard links, soft links and junction points since Windows 2k. [1] Christian [1] http://en.wikipedia.org/wiki/NTFS_reparse_point From carlos.grohmann at gmail.com Thu Jun 3 14:55:51 2010 From: carlos.grohmann at gmail.com (Carlos Grohmann) Date: Thu, 3 Jun 2010 11:55:51 -0700 (PDT) Subject: problems with CSV module Message-ID: Hi all, I'm using csv to read text files, and its working fine, except in two cases: - when there is only one line of text (data) in the file - when there is a blank line after the last data line this is the kind of data: 45 67 89 23 45 06 12 34 67 ... and this is the function: def getData(paths): """get data from file and create lists with values and column names.""" filehandle = paths#[i] # filehandle = os.path.join(dirname, filename) csvfile = open(filehandle,'r') # Open the file and read the contents sample = csvfile.read( 1024 )# Grab a sample csvfile.seek( 0 ) dialect = csv.Sniffer().sniff(sample) # Check for file format with sniffer. csvfile = csv.reader( csvfile, dialect ) if csv.Sniffer().has_header( sample ): #if there is a header colnames = csvfile.next() # label columns from first line datalist = list( csvfile ) # append data to a list else: #if there is NO header datalist = list( csvfile ) # append data to a list colnames = ['col_%i' % i for i in range(len(datalist[0]))] # label columns as col_1, col_2, etc return datalist, colnames TIA for any help. From strombrg at gmail.com Thu Jun 3 14:58:17 2010 From: strombrg at gmail.com (Dan Stromberg) Date: Thu, 3 Jun 2010 11:58:17 -0700 (PDT) Subject: FIle transfer over network - with Pyro? References: Message-ID: On Jun 3, 10:47?am, Nathan Huesken wrote: > Hi, > > I am writing a network application which needs from time to time do > file transfer (I am writing the server as well as the client). > For simple network messages, I use pyro because it is very comfortable. > But I suspect, that doing a file transfer is very inefficient over > pyro, am I right (the files are pretty big)? > > I somehow need to ensure, that the client requesting a file transfer is > the same client getting the file. So some sort of authentication is > needed. > > What library would you use to do the file transfer? > Regards, > Nathan I've never used Pyro, but for a fast network file transfer in Python, I'd probably use the socket module directly, with a cache oblivious algorithm: http://en.wikipedia.org/wiki/Cache-oblivious_algorithm It doesn't use sockets, it uses files, but I recently did a Python progress meter application that uses a cache oblivious algorithm that can get over 5 gigabits/second throughput (that's without the network in the picture, though if it were used on 10 Gig-E with a suitable transport it could probably do nearly that), on a nearly-modern PC running Ubuntu with 2 cores It's at: http://stromberg.dnsalias.org/~strombrg/gprog/ . For a simple example of using sockets in python (without a cache oblivious algorithm, unfortunately), you could glance at this: http://stromberg.dnsalias.org/~strombrg/pnetcat.html HTH :) From neilc at norwich.edu Thu Jun 3 15:14:21 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 3 Jun 2010 19:14:21 GMT Subject: problems with CSV module References: Message-ID: <86qd8dFf8sU2@mid.individual.net> On 2010-06-03, Carlos Grohmann wrote: > Hi all, I'm using csv to read text files, and its working fine, except > in two cases: > > - when there is only one line of text (data) in the file > - when there is a blank line after the last data line > > this is the kind of data: > > 45 67 89 > 23 45 06 > 12 34 67 > ... That data doesn't appear to be csv worthy. Why not use str.split or str.partition? > and this is the function: > > def getData(paths): > """get data from file and create lists with values and column > names.""" > > filehandle = paths#[i] # filehandle = os.path.join(dirname, > filename) > csvfile = open(filehandle,'r') # Open the file and read the In Python 2.6 and earlier, you need to open the file in binary mode. In Python 3.0 and later, you need to open the file with a mystic incantation: csvfile = open(filehandle, newline='') > sample = csvfile.read( 1024 )# Grab a sample > csvfile.seek( 0 ) > dialect = csv.Sniffer().sniff(sample) # Check for file format with > sniffer. > csvfile = csv.reader( csvfile, dialect ) Use: csvfile = csv.reader(csvfile, dialect=dialect) dialect is a keyword argument. > if csv.Sniffer().has_header( sample ): #if there is a header > colnames = csvfile.next() # label columns from first line > datalist = list( csvfile ) # append data to a list Do you really need to use the Sniffer? You'll probably be better off -- Neil Cerutti *** You found a dead moose-rat. You sell the hide for $200. *** From neilc at norwich.edu Thu Jun 3 15:21:31 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 3 Jun 2010 19:21:31 GMT Subject: problems with CSV module References: <86qd8dFf8sU2@mid.individual.net> Message-ID: <86qdlrFf8sU3@mid.individual.net> On 2010-06-03, Neil Cerutti wrote: > Do you really need to use the Sniffer? You'll probably be better > off... ...defining your own dialect based on what you know to be the file format. -- Neil Cerutti From carlos.grohmann at gmail.com Thu Jun 3 15:26:03 2010 From: carlos.grohmann at gmail.com (Carlos Grohmann) Date: Thu, 3 Jun 2010 12:26:03 -0700 (PDT) Subject: problems with CSV module References: <86qd8dFf8sU2@mid.individual.net> Message-ID: <378cfb55-7aba-4d5b-8e61-39837eb7a9eb@c33g2000yqm.googlegroups.com> Thanks for your prompt response, Neil. > That data doesn't appear to be csv worthy. Why not use str.split > or str.partition? Well, I should have said that this is one kind of data. The function is part of a larger app, and there is the possibility that someone uses headers in the data files, or some other field separator, so I tried to make it more universal. > In Python 2.6 and earlier, you need to open the file in binary > mode. I tried that, no changes > Use: > ? ?csvfile = csv.reader(csvfile, dialect=dialect) > dialect is a keyword argument. thanks for pointing that out.it stopped the errors when there s only one data line, but it still can't get the values for that line Carlos From exarkun at twistedmatrix.com Thu Jun 3 16:05:15 2010 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Thu, 03 Jun 2010 20:05:15 -0000 Subject: FIle transfer over network - with Pyro? In-Reply-To: References: Message-ID: <20100603200515.1988.953489959.divmod.xquotient.17@localhost.localdomain> On 06:58 pm, strombrg at gmail.com wrote: >On Jun 3, 10:47?am, Nathan Huesken wrote: >>Hi, >> >>I am writing a network application which needs from time to time do >>file transfer (I am writing the server as well as the client). >>For simple network messages, I use pyro because it is very >>comfortable. >>But I suspect, that doing a file transfer is very inefficient over >>pyro, am I right (the files are pretty big)? >> >>I somehow need to ensure, that the client requesting a file transfer >>is >>the same client getting the file. So some sort of authentication is >>needed. >> >>What library would you use to do the file transfer? >>Regards, >>Nathan > >I've never used Pyro, but for a fast network file transfer in Python, >I'd probably use the socket module directly, with a cache oblivious >algorithm: > http://en.wikipedia.org/wiki/Cache-oblivious_algorithm > >It doesn't use sockets, it uses files, but I recently did a Python >progress meter application that uses a cache oblivious algorithm that >can get over 5 gigabits/second throughput (that's without the network >in the picture, though if it were used on 10 Gig-E with a suitable >transport it could probably do nearly that), on a nearly-modern PC >running Ubuntu with 2 cores It's at: > http://stromberg.dnsalias.org/~strombrg/gprog/ . This seems needlessly complicated. Do you have a hard drive that can deliver 5 gigabits/second to your application? More than likely not. A more realistic answer is probably to use something based on HTTP. This solves a number of real-world problems, like the exact protocol to use over the network, and detecting network issues which cause the transfer to fail. It also has the benefit that there's plenty of libraries already written to help you out. Jean-Paul From nagle at animats.com Thu Jun 3 16:09:04 2010 From: nagle at animats.com (John Nagle) Date: Thu, 03 Jun 2010 13:09:04 -0700 Subject: Another MySQL Question In-Reply-To: References: Message-ID: <4c080600$0$1654$742ec2ed@news.sonic.net> MRAB wrote: > Victor Subervi wrote: >> Hi; >> I have this code: >> >> options = '' >> our_options = [] >> our_options_string = '' >> for op in ops: >> options += '%s varchar(40) not null, ' % (op[0].upper() + op[1:]) >> our_options.append('%s' % form.getfirst('%s' % op)) >> our_options_string += '%s", "' % op >> cursor.execute('''create table if not exists tmp%s ( >> Store varchar(40) not null, >> PatientID varchar(40) not null, >> ProdID varchar(40) not null, >> Pkg varchar(10) not null, >> %s)''' % (tmpTable, options[:-2])) >> sql_string = 'insert into tmp%s values (%s, %s, %s, %s, "%s")' % >> (tmpTable, store, patientID, prodid, pkg, our_options_string[:-4]) >> print sql_string >> sql = 'insert into tmp%s values (%s, %s, %s, %s, %%s)' % >> (tmpTable, store, patientID, prodid, pkg) >> cursor.execute(sql, (our_options,)) The real problem with this is not the Python. It's the approach to SQL. What's going on here is that you have some collection of named options that come in from some external source, and you're trying to handle that by dynamically constructing the table schema. It would be easier to store the "option" values in a separate table, with something like CREATE TABLE temp01 ( entryid BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY, Store VARCHAR(40) NOT NULL, PatientID VARCHAR(40) NOT NULL, ProdID VARCHAR(40) NOT NULL, Pkg VARCHAR(10) NOT NULL) ENGINE=INNODB; CREATE TABLE ouroptions ( FOREIGN KEY (parententry) REFERENCES temp01(entryid) ON DELETE CASCADE, optionname VARCHAR(40) NOT NULL, optionvalue VARCHAR(40) NOT NULL) ENGINE=INNODB; This creates two tables which are locked together. For any entry in "temp01", you can create any "option" entries you need in "ouroptions". If you delete the entry in "temp01", the related "options" entries will go away. (That's what ON DELETE CASCADE does.) When inserting, insert the record in temp01 first, then the recrods in "ouroptions", in a single transaction. Incidentally, if you don't specify some indices, lookups will take a very long time. John Nagle From neilc at norwich.edu Thu Jun 3 16:18:05 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 3 Jun 2010 20:18:05 GMT Subject: problems with CSV module References: <86qd8dFf8sU2@mid.individual.net> <378cfb55-7aba-4d5b-8e61-39837eb7a9eb@c33g2000yqm.googlegroups.com> Message-ID: <86qgvtFb3sU2@mid.individual.net> On 2010-06-03, Carlos Grohmann wrote: >> Use: >> ? ?csvfile = csv.reader(csvfile, dialect=dialect) >> dialect is a keyword argument. > > thanks for pointing that out.it stopped the errors when there s > only one data line, but it still can't get the values for that > line Is it possible your data is ill-formed in that case? If it's lacking a line-end, I don't know what should happen. -- Neil Cerutti From davidreynon at gmail.com Thu Jun 3 16:24:44 2010 From: davidreynon at gmail.com (dave) Date: Thu, 3 Jun 2010 13:24:44 -0700 (PDT) Subject: changing format of time duration. Message-ID: <11191764-f704-4f1e-9a0e-1fb9d174afa1@l6g2000vbo.googlegroups.com> Quick question. I have to time stamps (now and now2). now = datetime.datetime.now(); now2 = datetime.datetime.now(); now2-now1 yields me a result in 0:00:00.11221 (H:MM:SS.ssss) I wanted to know if there is a standard python method or a quick hack to add an extra zero in the beginning. So the result I am looking for would be 00:00:00.11221 From brfredericks at gmail.com Thu Jun 3 16:44:11 2010 From: brfredericks at gmail.com (bfrederi) Date: Thu, 3 Jun 2010 13:44:11 -0700 (PDT) Subject: Issue with xml iterparse Message-ID: <9c6bfe72-fae0-4cba-94b2-8687f33e3780@5g2000yqz.googlegroups.com> I am using lxml iterparse and running into a very obscure error. When I run iterparse on a file, it will occasionally return an element that has a element.text == None when the element clearly has text in it. I copy and pasted the problem xml into a python string, used StringIO to create a file-like object out of it, and ran a test using iterparse with expected output, and it ran perfectly fine. So it only happens when I try to run iterparse on the actual file. So then I tried opening the file, reading the data, turning that data into a file-like object using StringIO, then running iterparse on it, and the same problem (element.text == None) occurred. I even tried this: f = codecs.open(abbyy_filename, 'r', encoding='utf-8') file_data = f.read() file_like_object = StringIO.StringIO(file_data) for event, element in iterparse(file_like_object, events=("start", "end")): And I got this Traceback: Traceback (most recent call last): File "abbyyParser/parseAbbyy.py", line 391, in extension=options.extension, File "abbyyParser/parseAbbyy.py", line 103, in __init__ self.generate_output_files() File "abbyyParser/parseAbbyy.py", line 164, in generate_output_files AbbyyDocParse(abby_filename, self.extension, self.output_types) File "abbyyParser/parseAbbyy.py", line 239, in __init__ self.parse_doc(abbyy_filename) File "abbyyParser/parseAbbyy.py", line 281, in parse_doc for event, element in iterparse(file_like_object, events=("start", "end")): File "iterparse.pxi", line 484, in lxml.etree.iterparse.__next__ (src/lxml/lxml.etree.c:86333) TypeError: reading file objects must return plain strings If I do this: file_data = f.read().encode("utf-8") iterparse will run on it, but I still get elements.text with a value of None when I should not. My XML file does have diacritics in it, but I've put the proper encoding at the head of the XML file (). I've also tried using elementree's iterparse, and I get even more of the same problem with the same files. Any idea what the problem might be? From clp2 at rebertia.com Thu Jun 3 16:59:57 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 3 Jun 2010 13:59:57 -0700 Subject: Issue with xml iterparse In-Reply-To: <9c6bfe72-fae0-4cba-94b2-8687f33e3780@5g2000yqz.googlegroups.com> References: <9c6bfe72-fae0-4cba-94b2-8687f33e3780@5g2000yqz.googlegroups.com> Message-ID: On Thu, Jun 3, 2010 at 1:44 PM, bfrederi wrote: > I am using lxml iterparse and running into a very obscure error. When > I run iterparse on a file, it will occasionally return an element that > has a element.text == None when the element clearly has text in it. > > I copy and pasted the problem xml into a python string, used StringIO > to create a file-like object out of it, and ran a test using iterparse > with expected output, and it ran perfectly fine. So it only happens > when I try to run iterparse on the actual file. > > So then I tried opening the file, reading the data, turning that data > into a file-like object using StringIO, then running iterparse on it, > and the same problem (element.text == None) occurred. > > I even tried this: > f = codecs.open(abbyy_filename, 'r', encoding='utf-8') > file_data = f.read() > file_like_object = StringIO.StringIO(file_data) > for event, element in iterparse(file_like_object, events=("start", > "end")): IIRC, XML parsers operate on bytes directly (since they have to determine the encoding themselves anyway), not pre-decoded Unicode characters, so I think your manual UTF-8 decoding could be the problem. Have you tried simply: f = open(abbyy_filename, 'r') for event, element in iterparse(f, events=("start", "end")): #whatever ? Apologies if you already have, but since you didn't include the original, albeit probably trivial, error-causing code, this relatively simple error couldn't be ruled out. Cheers, Chris -- http://blog.rebertia.com From dchichkov at gmail.com Thu Jun 3 17:00:11 2010 From: dchichkov at gmail.com (dmtr) Date: Thu, 3 Jun 2010 14:00:11 -0700 (PDT) Subject: An empty object with dynamic attributes (expando) Message-ID: How can I create an empty object with dynamic attributes? It should be something like: >>> m = object() >>> m.myattr = 1 But this doesn't work. And I have to resort to: >>> class expando(object): pass >>> m = expando() >>> m.myattr = 1 Is there a one-liner that would do the thing? -- Cheers, Dmitry From irmen-NOSPAM- at xs4all.nl Thu Jun 3 17:07:43 2010 From: irmen-NOSPAM- at xs4all.nl (Irmen de Jong) Date: Thu, 03 Jun 2010 23:07:43 +0200 Subject: FIle transfer over network - with Pyro? In-Reply-To: References: Message-ID: <4c081990$0$22935$e4fe514c@news.xs4all.nl> On 3-6-2010 19:47, Nathan Huesken wrote: > Hi, > > I am writing a network application which needs from time to time do > file transfer (I am writing the server as well as the client). > For simple network messages, I use pyro because it is very comfortable. > But I suspect, that doing a file transfer is very inefficient over > pyro, am I right (the files are pretty big)? How big is 'pretty big'? Pyro could work just fine for file transfers, depending on the size of the files, how often you need to transfer, and the speed of your computer. But you are correct that Pyro has substantial overhead compared to a solution specifically designed for file transfer (such as copying over network file system or network shares, ftp, or http). It boils down to: - reading the whole file into memory before it can be transferred - needing to pickle/unpickle the file data This might or might not be an actual problem. If you really need another protocol for your file transfers, I agree with Jean-Paul to just use a HTTP based solution (web server). Or maybe simply copy the file over a network share/network filesystem? Both can be configured to require proper authentication. Irmen From brfredericks at gmail.com Thu Jun 3 17:13:37 2010 From: brfredericks at gmail.com (bfrederi) Date: Thu, 3 Jun 2010 14:13:37 -0700 (PDT) Subject: Issue with xml iterparse References: <9c6bfe72-fae0-4cba-94b2-8687f33e3780@5g2000yqz.googlegroups.com> Message-ID: On Jun 3, 3:59?pm, Chris Rebert wrote: > On Thu, Jun 3, 2010 at 1:44 PM, bfrederi wrote: > > I am using lxml iterparse and running into a very obscure error. When > > I run iterparse on a file, it will occasionally return an element that > > has a element.text == None when the element clearly has text in it. > > > I copy and pasted the problem xml into a python string, used StringIO > > to create a file-like object out of it, and ran a test using iterparse > > with expected output, and it ran perfectly fine. So it only happens > > when I try to run iterparse on the actual file. > > > So then I tried opening the file, reading the data, turning that data > > into a file-like object using StringIO, then running iterparse on it, > > and the same problem (element.text == None) occurred. > > > I even tried this: > > f = codecs.open(abbyy_filename, 'r', encoding='utf-8') > > file_data = f.read() > > file_like_object = StringIO.StringIO(file_data) > > for event, element in iterparse(file_like_object, events=("start", > > "end")): > > IIRC, XML parsers operate on bytes directly (since they have to > determine the encoding themselves anyway), not pre-decoded Unicode > characters, so I think your manual UTF-8 decoding could be the > problem. > Have you tried simply: > > f = open(abbyy_filename, 'r') > for event, element in iterparse(f, events=("start", "end")): > ? ? #whatever > > ? > > Apologies if you already have, but since you didn't include the > original, albeit probably trivial, error-causing code, this relatively > simple error couldn't be ruled out. > > Cheers, > Chris > --http://blog.rebertia.com Sorry for not mentioning it, but I tried that as well and it failed. Here is the relevant class. AbbyyLine and Abbyyword just take the element's text and writes it to a file/file-like object. parse_doc is where I use iterparse. The relevant part is very minimal and there is a lot of fluff to ignore, so I didn't initially post it: class AbbyyDocParse(object): """Takes an abbyy filename and parses the contents""" def __init__(self, abbyy_filename, extension=DEFAULT_ABBYY_EXT, format_list=OUTPUT_TYPES, string_only=False): self.extension = extension self.format_list = format_list #Create the file handles for the output files self.create_filehandles(abbyy_filename, string_only) #Parse the document self.parse_doc(abbyy_filename) #Close the output filehandles self.close_filehandles(abbyy_filename, string_only) def create_filehandles(self, abbyy_filename, string_only): """Create output filehandles""" #if output goes to a file if not string_only: #Make sure the file is an abbyy file if not abbyy_filename.endswith(self.extension): raise ParserException, "Bad abbyy filename given: %s" \ % (abbyy_filename) #get the base path and filename for output files filename = abbyy_filename.replace(self.extension, '') #Loop through the different formats for format_type in self.format_list: #if output goes to a file if not string_only: #Create output filename out_file = "%s%s" % (filename, OUTPUT_EXTENSIONS.get(format_type)) #Opens the format type filehandle try: setattr(self, "%s_handle" % (format_type), open(out_file,'w')) except: raise IOError, "Could not open file: %s" % (out_file) #if output goes to a string else: #Opens the format type StringIO try: setattr(self, "%s_handle" % (format_type), StringIO.StringIO()) except: raise IOError, "Could not open string output: %s" % (out_file) def parse_doc(self, abbyy_filename): """Parses the abbyy document""" #Write the first line of the xml doc, if specified if getattr(self, 'xml_handle', None): self.xml_handle.write('\n') #Memory efficient iterparse opens file and loops through content for event, element in iterparse(abbyy_filename, events=("start", "end")): #ignore the namespace, if it has one if NAMESPACE_REGEX.search(element.tag, 0): element_tag = NAMESPACE_REGEX.search(element.tag, 0).group(1) else: element_tag = element.tag #if this is the page element if element_tag == 'page': self.write_page(event, element) #If at the beginning of the line elif element_tag == 'line' and event == 'start': #Create the line line = AbbyyLine(element) #Instantiate first word word = AbbyyWord(line) #If at the end of the line, and an output text file exists if element_tag == 'line' and event == 'end' and \ getattr(self, 'text_handle', None): #output line data to text file line.write_line(self.text_handle) #If at the end of the line, and an output text file exists if element_tag == 'line' and event == 'end' and \ getattr(self, 'xml_handle', None): #output line data to text file word.write_word(self.xml_handle) #if outputting to an xml file, create word data if getattr(self, 'xml_handle', None) and \ element_tag == 'charParams' and event == 'start': #Insert character into word word.insert_char(element, self.xml_handle) #if outputting to a text file, create line data if getattr(self, 'text_handle', None) and \ element_tag == 'charParams' and event == 'start': #Insert character into line line.insert_char(element) def write_page(self, event, element): """Parse the page contents""" #page open tag event if event == 'start': #Write page info to xml file if getattr(self, 'xml_handle', None): #Get the page info x_dim = element.get('width') y_dim = element.get('height') resolution = element.get('resolution') #Write the page info to the file self.xml_handle.write('\n') self.xml_handle.write('\n') self.xml_handle.write('\n') self.xml_handle.write("%s\n" % (x_dim)) self.xml_handle.write("%s\n" % (y_dim)) self.xml_handle.write("%s\n" % (resolution)) self.xml_handle.write('\n') self.xml_handle.write('\n') #page close tag event elif event == 'end': #Write page info to xml file if getattr(self, 'xml_handle', None): #Write closing tags to file self.xml_handle.write('\n') self.xml_handle.write('') def write_line(self, event, element): """Parse the line contents""" #line open tag event if event == 'start': pass #page close tag event elif event == 'end': pass def write_word(self, event, element): """Parse the charParams contents""" pass def close_filehandles(self, abbyy_filename, string_only): """Close the open filehandles""" #if the files exist if not string_only: #Loop through the different formats for format_type in self.format_list: #Opens the format type filehandle try: getattr(self, "%s_handle" % (format_type)).close() except: raise IOError, "Could not close format type: %s for file: %s" \ % (format_type, abbyy_filename) From phlip2005 at gmail.com Thu Jun 3 17:23:47 2010 From: phlip2005 at gmail.com (Phlip) Date: Thu, 3 Jun 2010 14:23:47 -0700 (PDT) Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c0619e7$0$24606$426a74cc@news.free.fr> Message-ID: On Jun 2, 3:18?am, Adam Tauno Williams wrote: > +1 > > Yuck; no better way to make new users hate your product than have a web > forum - where they post questions.... Free of all the spam that leaks into here from the remnants of USENET!! > and never get answers... You mean like how I never get answers, to my super-easy GED-level questions, here??! From alfps at start.no Thu Jun 3 17:36:36 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 03 Jun 2010 23:36:36 +0200 Subject: An empty object with dynamic attributes (expando) In-Reply-To: References: Message-ID: * dmtr, on 03.06.2010 23:00: > How can I create an empty object with dynamic attributes? It should be > something like: > >>>> m = object() >>>> m.myattr = 1 > > But this doesn't work. And I have to resort to: > >>>> class expando(object): pass >>>> m = expando() >>>> m.myattr = 1 > > Is there a one-liner that would do the thing? >>> m = lambda:0 >>> m.myattr = 1 >>> m.myattr 1 >>> _ But I feel that that is an abuse of the language, and that an Expando class like you show is far better. Thanks for the class name suggestion, by the way -- I've wondered what to call such a class, and now it's clear. :-) Cheers & hth., - Alf -- blog at From debatem1 at gmail.com Thu Jun 3 18:20:55 2010 From: debatem1 at gmail.com (geremy condra) Date: Thu, 3 Jun 2010 15:20:55 -0700 Subject: Python Forum In-Reply-To: References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c0619e7$0$24606$426a74cc@news.free.fr> Message-ID: On Thu, Jun 3, 2010 at 2:23 PM, Phlip wrote: > On Jun 2, 3:18?am, Adam Tauno Williams wrote: > >> +1 >> >> Yuck; no better way to make new users hate your product than have a web >> forum - where they post questions.... > > Free of all the spam that leaks into here from the remnants of > USENET!! > >> and never get answers... > > You mean like how I never get answers, to my super-easy GED-level > questions, here??! I agree. This proves conclusively that a web forum is the right place for you. Geremy Condra From phlip2005 at gmail.com Thu Jun 3 18:40:03 2010 From: phlip2005 at gmail.com (Phlip) Date: Thu, 3 Jun 2010 15:40:03 -0700 (PDT) Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c0619e7$0$24606$426a74cc@news.free.fr> Message-ID: <80f1faae-146d-40b6-9075-613faf38a5f7@g39g2000pri.googlegroups.com> On Jun 3, 3:20?pm, geremy condra wrote: > > You mean like how I never get answers, to my super-easy GED-level > > questions, here??! > > I agree. This proves conclusively that a web forum is the right > place for you. Ah, so you feel up to my "xsl for xmlrunner.py" question? From emin.shopper at gmail.com Thu Jun 3 18:43:39 2010 From: emin.shopper at gmail.com (Emin.shopper Martinian.shopper) Date: Thu, 3 Jun 2010 18:43:39 -0400 Subject: getting MemoryError with dicts; suspect memory fragmentation Message-ID: Dear Experts, I am getting a MemoryError when creating a dict in a long running process and suspect this is due to memory fragmentation. Any suggestions would be welcome. Full details of the problem are below. I have a long running processing which eventually dies to a MemoryError exception. When it dies, it is using roughly 900 MB on a 4 GB Windows XP machine running Python 2.5.4. If I do "import pdb; pdb.pm()" to debug, I see that it is dying inside a method when trying to create a dict with about 2000 elements. If I instead do something like p setattr(self,'q',list([list(xxx)+list(xxx)+list(xxx)+list(xxx) for xxx in self.data])) inside the debugger, I can make the memory increase to about 1.5 GB WITHOUT getting a memory error. If instead I do something like p setattr(self,'q',dict([(xxx,xxx) for xxx in range(1400)])) inside the debugger, I get a MemoryError exception. If instead I do something like p setattr(self,'q',dict([(xxx,xxx) for xxx in range(1300)])) inside the debugger, I get no Exception. I infer that python is trying to allocate a bunch of contiguous space for the dict and due to fragmentation it can't find the contiguous space and therefore it gives a memory error. 1. Does this sound plausible or could something else be causing the problem? 2. Does anyone have suggestions on how to fix this? Some time Googling brings up the following 2004 thread started by Evan Jones: http://mail.python.org/pipermail/python-dev/2004-October/049480.html but I'm unable to find a solution to the problem I'm having. Any help would be much appreciated. Thanks, -E From debatem1 at gmail.com Thu Jun 3 18:58:36 2010 From: debatem1 at gmail.com (geremy condra) Date: Thu, 3 Jun 2010 15:58:36 -0700 Subject: Python Forum In-Reply-To: <80f1faae-146d-40b6-9075-613faf38a5f7@g39g2000pri.googlegroups.com> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c0619e7$0$24606$426a74cc@news.free.fr> <80f1faae-146d-40b6-9075-613faf38a5f7@g39g2000pri.googlegroups.com> Message-ID: On Thu, Jun 3, 2010 at 3:40 PM, Phlip wrote: > On Jun 3, 3:20?pm, geremy condra wrote: > >> > You mean like how I never get answers, to my super-easy GED-level >> > questions, here??! >> >> I agree. This proves conclusively that a web forum is the right >> place for you. > > Ah, so you feel up to my "xsl for xmlrunner.py" question? Sure, it's super-easy and GED-level. We can talk about the cost privately if you're interested. Geremy Condra From rhodri at wildebst.demon.co.uk Thu Jun 3 18:59:38 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 03 Jun 2010 23:59:38 +0100 Subject: CTYPES structure passing References: <18124e50-30c9-4963-a194-f96bf309dd25@c7g2000vbc.googlegroups.com> Message-ID: On Thu, 03 Jun 2010 11:54:13 +0100, Peter West wrote: > class LUCAM_FRAME_FORMAT(Structure): > __fields__ = [( "xOffset", c_ulong), # x coordinate on imager of > top left corner of subwindow in pixels [snip] > ( "XUnion", FRAME_FORMAT_UNION), > ( "flagsX", c_ushort), # LUCAM_FRAME_FORMAT_FLAGS_* > ( "YUnion", FRAME_FORMAT_UNION), > ( "flagsY", c_ushort)] > LP_FRAME_FORMAT = POINTER(LUCAM_FRAME_FORMAT) > and make the call like this > FrameFormat.XUnion = 0 Doesn't this replace the union object with an integer zero? Do you mean FrameFormat.XUnion.subSample = 0 FrameFormat.XUnion.binning = 0 instead? > FrameFormat.flagsX = 0 > FrameFormat.YUnion = 0 Ditto here? -- Rhodri James *-* Wildebeeste Herder to the Masses From phlip2005 at gmail.com Thu Jun 3 19:11:24 2010 From: phlip2005 at gmail.com (Phlip) Date: Thu, 3 Jun 2010 16:11:24 -0700 (PDT) Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c0619e7$0$24606$426a74cc@news.free.fr> <80f1faae-146d-40b6-9075-613faf38a5f7@g39g2000pri.googlegroups.com> Message-ID: <4c998b63-8c53-476a-9733-2ce2ac150337@11g2000prv.googlegroups.com> On Jun 3, 3:58?pm, geremy condra wrote: > On Thu, Jun 3, 2010 at 3:40 PM, Phlip wrote: > > On Jun 3, 3:20?pm, geremy condra wrote: > > >> > You mean like how I never get answers, to my super-easy GED-level > >> > questions, here??! > > >> I agree. This proves conclusively that a web forum is the right > >> place for you. > > > Ah, so you feel up to my "xsl for xmlrunner.py" question? > > Sure, it's super-easy and GED-level. We can talk about the > cost privately if you're interested. > > Geremy Condra That reminds me - pyDev, your forum has a "killfile" or "block" feature, right? From dchichkov at gmail.com Thu Jun 3 19:41:47 2010 From: dchichkov at gmail.com (dmtr) Date: Thu, 3 Jun 2010 16:41:47 -0700 (PDT) Subject: getting MemoryError with dicts; suspect memory fragmentation References: Message-ID: <1d1b48dd-3316-4a72-a8a0-e56d307e5ec7@n37g2000prc.googlegroups.com> On Jun 3, 3:43?pm, "Emin.shopper Martinian.shopper" wrote: > Dear Experts, > > I am getting a MemoryError when creating a dict in a long running > process and suspect this is due to memory fragmentation. Any > suggestions would be welcome. Full details of the problem are below. > > I have a long running processing which eventually dies to a > MemoryError exception. When it dies, it is using roughly 900 MB on a 4 > GB Windows XP machine running Python 2.5.4. If I do "import pdb; Are you sure you have enough memory available? Dict memory usage can jump x2 during re-balancing. -- Dmitry P.S. Wish there was a google-sparsehash port for python.... From dchichkov at gmail.com Thu Jun 3 19:46:44 2010 From: dchichkov at gmail.com (dmtr) Date: Thu, 3 Jun 2010 16:46:44 -0700 (PDT) Subject: getting MemoryError with dicts; suspect memory fragmentation References: <1d1b48dd-3316-4a72-a8a0-e56d307e5ec7@n37g2000prc.googlegroups.com> Message-ID: <48d3ccaa-d9e9-46d7-a68c-beb6114b1e99@s6g2000prf.googlegroups.com> > I have a long running processing which eventually dies to a > MemoryError exception. When it dies, it is using roughly 900 MB on a 4 > GB Windows XP machine running Python 2.5.4. If I do "import pdb; BTW have you tried the same code with the Python 2.6.5? -- Dmitry From debatem1 at gmail.com Thu Jun 3 20:00:14 2010 From: debatem1 at gmail.com (geremy condra) Date: Thu, 3 Jun 2010 17:00:14 -0700 Subject: Python Forum In-Reply-To: <4c998b63-8c53-476a-9733-2ce2ac150337@11g2000prv.googlegroups.com> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c0619e7$0$24606$426a74cc@news.free.fr> <80f1faae-146d-40b6-9075-613faf38a5f7@g39g2000pri.googlegroups.com> <4c998b63-8c53-476a-9733-2ce2ac150337@11g2000prv.googlegroups.com> Message-ID: On Thu, Jun 3, 2010 at 4:11 PM, Phlip wrote: > On Jun 3, 3:58?pm, geremy condra wrote: >> On Thu, Jun 3, 2010 at 3:40 PM, Phlip wrote: >> > On Jun 3, 3:20?pm, geremy condra wrote: >> >> >> > You mean like how I never get answers, to my super-easy GED-level >> >> > questions, here??! >> >> >> I agree. This proves conclusively that a web forum is the right >> >> place for you. >> >> > Ah, so you feel up to my "xsl for xmlrunner.py" question? >> >> Sure, it's super-easy and GED-level. We can talk about the >> cost privately if you're interested. >> >> Geremy Condra > > That reminds me - pyDev, your forum has a "killfile" or "block" > feature, right? > -- > http://mail.python.org/mailman/listinfo/python-list > If you want to block me (hypothetically, of course), just add me to your spam filter's rules. Geremy Condra From pavlovevidence at gmail.com Thu Jun 3 20:03:16 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 3 Jun 2010 17:03:16 -0700 (PDT) Subject: Vote to Add Python Package "pubsub" to the Python Standard Library References: <6b9d2898-4166-40b4-9016-dc55dee77d00@q33g2000vbt.googlegroups.com> <8799a47b-9d16-4187-8862-31570c9d9b11@v25g2000yqv.googlegroups.com> Message-ID: <700eca3d-06f2-4672-8741-549ddb722d88@k39g2000yqd.googlegroups.com> On Jun 3, 8:46?am, Vinay Sajip wrote: > On Jun 2, 4:09?am, Carl Banks wrote: > > > I think it has a pretty good chance of being accepted, too. ?The > > publish-subscribe pattern, if you will, seems to have been implemented > > separately in many places. ?The logging module in the standard library > > uses something like this. > > Only in a very general sense, if you mean the separation of concerns > between loggers and handlers. There isn't a general-purpose pub/sub > infrastructure built into it. Which is an implementation of publish-subscribe pattern. I didn't say or imply it was general purpose. And it doesn't have to be to make a case for inclusion of a general-purpose implementation in the standard library. Carl Banks From rossgk at gmail.com Thu Jun 3 20:05:34 2010 From: rossgk at gmail.com (Ross) Date: Thu, 3 Jun 2010 17:05:34 -0700 (PDT) Subject: Plain simple unix timestamp with an HTTP GET Message-ID: I'd like to just quickly and with a minimum of parsing (ie no screen- scraping) get a unix epoch timestamp (or another format if necessary). I thought with a quick second search on Google I'd find a URL where I could do a simple urllib2 based HTTP GET and have a timestamp returned to me. I don't want to use NTP. I need this because I want to run it on an embedded system where I don't have a local timesource, but do have a network service. I'm very low on memory tho. I can set up my own service on django I suppose, and just render back the timestamp from datetime.time() but SURELY someone else is already doing that? My googling has fallen flat. Any suggestions. Thanks in advance! -Ross. From emin.shopper at gmail.com Thu Jun 3 20:06:15 2010 From: emin.shopper at gmail.com (Emin.shopper Martinian.shopper) Date: Thu, 3 Jun 2010 20:06:15 -0400 Subject: getting MemoryError with dicts; suspect memory fragmentation In-Reply-To: References: <1d1b48dd-3316-4a72-a8a0-e56d307e5ec7@n37g2000prc.googlegroups.com> Message-ID: On Thu, Jun 3, 2010 at 7:41 PM, dmtr wrote: > On Jun 3, 3:43?pm, "Emin.shopper Martinian.shopper" > wrote: >> Dear Experts, >> > > Are you sure you have enough memory available? > Dict memory usage can jump x2 during re-balancing. > I'm pretty sure. When I did ?p setattr(self,'q',dict([(xxx,xxx) for xxx in range(1300)])) the memory increased trivially (less than 1 MB) but when I did ?p setattr(self,'q',list([list(xxx)+list(xxx)+list(xxx)+list(xxx) for xxx in self.data])) it increased by 600 MB. After getting back to the original 900 MB memory usage, doing ?p setattr(self,'q',dict([(xxx,xxx) for xxx in range(1400)])) gave a memory error suggesting it isn't the amount of memory available that is the problem but something like fragmentation. Thanks, -Emin From livibetter at gmail.com Thu Jun 3 20:36:41 2010 From: livibetter at gmail.com (livibetter) Date: Thu, 3 Jun 2010 17:36:41 -0700 (PDT) Subject: Plain simple unix timestamp with an HTTP GET References: Message-ID: I don't know what tools do you have on embedded system, but I really don't think this has to be using Python. Here is what I would do on a normal desktop using your unique way to set up time: date -s "$(curl -s -I http://example.com | grep Date | cut -d \ -f 2-)" On Jun 4, 8:05?am, Ross wrote: > I'd like to just quickly and with a minimum of parsing (ie no screen- > scraping) get a unix epoch timestamp (or another format if necessary). > > ?I thought with a quick second search on Google I'd find a URL where I > could do a simple urllib2 based HTTP ?GET and have a timestamp > returned to me. I don't want to use NTP. > I need this because I want to run it on an embedded system where I > don't have a local timesource, but do have a network service. I'm very > low on memory tho. > > I can set up my own service on django I suppose, and just render back > the timestamp from datetime.time() but SURELY someone else is already > doing that? > > My googling has fallen flat. Any suggestions. > > Thanks in advance! > > -Ross. From rossgk at gmail.com Thu Jun 3 20:57:09 2010 From: rossgk at gmail.com (Ross) Date: Thu, 3 Jun 2010 17:57:09 -0700 (PDT) Subject: Plain simple unix timestamp with an HTTP GET References: Message-ID: <83cc363b-77f0-487d-901c-d15b275e43e5@y21g2000vba.googlegroups.com> No - it's not really a python specific need, it's just what I'm using just now, and can't think of where else to ask. It's also my fav test- bed, as it's so easy. Your curl example is using grep and date which I don't have available. I have no fancy libraries, just core parsing capability. I found that NIST has some capability on various servers. RFC 868 and 867. I can get this > curl http://208.66.175.36:13/ 55351 10-06-04 00:24:46 50 0 0 8.3 UTC(NIST) * But I'd have a lot of parsing to pull it together. Apparently RFC868 provides a 32bit unformated binary response, but I can't make much out of it. I think my TCP client library is expecting chars and is screwed by bit-boundary expectations. The number is supposed to be seconds since 1900, which is just as good as seconds since 1970. Still hunting. Tho' maybe getting a bit off topic for a python msg board :) On Jun 3, 8:36?pm, livibetter wrote: > I don't know what tools do you have on embedded system, but I really > don't think this has to be using Python. > > Here is what I would do on a normal desktop using your unique way to > set up time: > > ? date -s "$(curl -s -Ihttp://example.com| grep Date | cut -d \ ?-f > 2-)" From no.email at nospam.invalid Thu Jun 3 21:24:56 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 03 Jun 2010 18:24:56 -0700 Subject: Plain simple unix timestamp with an HTTP GET References: Message-ID: <7x7hmflhcn.fsf@ruckus.brouhaha.com> Ross writes: > I'd like to just quickly and with a minimum of parsing (ie no screen- > scraping) get a unix epoch timestamp (or another format if necessary). I haven't used this in a while and can't promise it still works: http://www.nightsong.com/phr/python/setclock.py From ben+python at benfinney.id.au Thu Jun 3 21:47:47 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 04 Jun 2010 11:47:47 +1000 Subject: How to run a python script with a configuration file at command line ? References: <277d49ec-36c7-47df-bbf0-e89ecefdf0ea@e21g2000vbl.googlegroups.com> Message-ID: <87sk53bmbg.fsf@benfinney.id.au> steph_awk writes: > I have been searching for quite some times without success. Did you try the standard library? > I have a python script that needs to start from command line and it > should have a config file to fill out the detais (itis one program, > and many possible configurations). The ?ConfigParser? module in Python 2.x, or ?configparser? in Python 3.x reads Windows INI-style configuration files into Python data structures. > something as simple as PHP would be nice %> ./PHPscript -c configfile > > is there such a thing in Python? For handling command-line arguments, see ?optparse? or ?getopt? . A significant improvement is available in the ?argparse? module, currently third-party but on track for inclusion in the Python standard library . -- \ ?Pinky, are you pondering what I'm pondering?? ?Uh, I think so, | `\ Brain, but we'll never get a monkey to use dental floss.? | _o__) ?_Pinky and The Brain_ | Ben Finney From ben+python at benfinney.id.au Thu Jun 3 21:49:59 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 04 Jun 2010 11:49:59 +1000 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87zkzccx3q.fsf@benfinney.id.au> <88192331-3301-47f8-8742-0a26eb9a65f0@j9g2000vbp.googlegroups.com> <1275564048.8775.13.camel@linux-yu4c.site> Message-ID: <87ocfrbm7s.fsf@benfinney.id.au> Dennis Lee Bieber writes: > I'm tempted to offer up that a lot of things that may once have been > covered in this general group have been migrated to specific mailing > lists (which are too many for me to consider subscribing just to do > one or two posts)... Which is also where NNTP shines: it's easy to participate using a standard interface, without committing to having loads of messages arrive in your email. -- \ ?A free press is one where it's okay to state the conclusion | `\ you're led to by the evidence.? ?Bill Moyers | _o__) | Ben Finney From john at castleamber.com Thu Jun 3 21:56:06 2010 From: john at castleamber.com (John Bokma) Date: Thu, 03 Jun 2010 20:56:06 -0500 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c0619e7$0$24606$426a74cc@news.free.fr> <80f1faae-146d-40b6-9075-613faf38a5f7@g39g2000pri.googlegroups.com> Message-ID: <87y6ev36ix.fsf@castleamber.com> Phlip writes: > On Jun 3, 3:20?pm, geremy condra wrote: > >> > You mean like how I never get answers, to my super-easy GED-level >> > questions, here??! >> >> I agree. This proves conclusively that a web forum is the right >> place for you. > > Ah, so you feel up to my "xsl for xmlrunner.py" question? Just jumping in the middle, but if you're looking for a web based forum where you can ask questions, check out Stack Overflow (and sister sites, depending on your question). I've noticed over the last couple of months that often things I google for, are answered on Stack Overflow. One thing that would've been nice to have on Usenet that I like is the ability to vote answers up or down. I think Usenet would've been a bit better with that option. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From dchichkov at gmail.com Thu Jun 3 22:00:50 2010 From: dchichkov at gmail.com (dmtr) Date: Thu, 3 Jun 2010 19:00:50 -0700 (PDT) Subject: getting MemoryError with dicts; suspect memory fragmentation References: <1d1b48dd-3316-4a72-a8a0-e56d307e5ec7@n37g2000prc.googlegroups.com> Message-ID: I'm still unconvinced that it is a memory fragmentation problem. It's very rare. Can you give more concrete example that one can actually try to execute? Like: python -c "list([list([0]*xxx)+list([1]*xxx)+list([2]*xxx) +list([3]*xxx) for xxx in range(100000)])" & -- Dmitry From bryanjugglercryptographer at yahoo.com Thu Jun 3 22:03:46 2010 From: bryanjugglercryptographer at yahoo.com (Bryan) Date: Thu, 3 Jun 2010 19:03:46 -0700 (PDT) Subject: CTYPES structure passing References: <18124e50-30c9-4963-a194-f96bf309dd25@c7g2000vbc.googlegroups.com> Message-ID: Peter West wrote: > I'm hoping someone here can tell me what I'm doing wrong as I've spent > the best part of three days reading docs and trying code. Yeah, I imagine a person could re-read them over and over and not see the gotcha. Sit down, maybe prepare some comfort food, and try to to be to upset when you find out how your three days were wasted... [...] > In my Python code I have > > #------------- Frame format -------------------- > class FRAME_FORMAT_UNION(Union): > ? ? __fields__ = [("subSample", c_ushort), ?# ?sub-sample ratio in x > direction in pixels (x:1) > ? ? ? ? ? ? ? ? ?("binning", c_ushort )] ? ?# ?binning ratio in x > direction in pixels (x:1) > > class LUCAM_FRAME_FORMAT(Structure): > ? ?__fields__ = [( "xOffset", c_ulong), ?# x coordinate on imager of > top left corner of subwindow in pixels There's your problem: The all-important _fields_ attribute is spelled with *single* underscores. You're probably familiar with the Python convention of special member names with double-underscores at each end? Well, ctypes doesn't follow it. [...] > and make the call like this > > FrameRate = c_float(0) > FrameFormat = LUCAM_FRAME_FORMAT() > > FrameFormat.xOffset = 0 > FrameFormat.yOffset = 0 > FrameFormat.width = 0 > FrameFormat.width = 0 > FrameFormat.height = 0 > FrameFormat.pixelFormat = 0 > FrameFormat.XUnion = 0 > FrameFormat.flagsX = 0 > FrameFormat.YUnion = 0 > FrameFormat.flagsY = 0 Which gives your FrameRate object some new attributes, completely unrelated to the _fields_ that ctypes uses to lay out a struct. Rhodri James pointed out that you want: FrameFormat.XUnion.subSample = 0 or FrameFormat.XUnion.binning = 0 And same for FrameFormat.YUnion. If you spell _fields_ as ctypes requires, it will complain about your assignments, in that you are trying to assign an in to a union. As your code is, those assignments just make a new attribute to which you can assign anything. -- --Bryan From yehrayyeh at gmail.com Thu Jun 3 22:05:07 2010 From: yehrayyeh at gmail.com (ray) Date: Thu, 3 Jun 2010 19:05:07 -0700 (PDT) Subject: How to generate execute file that include enthought.traits.api , enthought.traits.ui.api ? Message-ID: <57d9c5c4-c512-4619-ac10-c381cc13d0f1@k17g2000pro.googlegroups.com> Hi all, I code the program that using enthought.traits.api , enthought.traits.ui.api. I want to genereate execute file.I try PY2EXE,bb- freeze,cx_freeze,Pyinstaller ,but the execute files can not run successful. The attach file is my source code. My environment : 1.Python 2.6.2 2. OS platform is MS Windows XP. Anybody can share the experience ? -Here is my source code: from enthought.traits.api import * from enthought.traits.ui.api import * from enthought.traits.ui.menu import * import binhex,binascii,base64 """ Using Base64 to decode / encode message it will depening on your VISA/MCD ,to assemble CVV value Author: Ray Yeh 2008/12/02""" class Base64(HasTraits): option= Enum('D','E') card_type=Enum('V','M') input_text=Str display=Str intro= Str code_button=Button() decode_result='' ct_value =Str view1=View(Group(Item('option',label='Choice your function, [E]Encode, [D]Decode:'), Item('card_type',label='Select your CAVV [V]isa ,[M]asterCard:'), Item('input_text',label='Type your message',style='custom'), Item('display',style='custom'), Group(Item('code_button',label="Encode/ Decode")), label='Test Base64 tools', show_border=True ), kind='live', buttons=OKCancelButtons, width=800,height=600, resizable=True, title='Base64 Encoder tool' ) def dec2hex(self,n): """return the hexadecimal string representation of integer n""" return "%X" % n def hex2dec(self,s): """return the integer value of a hexadecimal string s""" return int(s, 16) def mcd(self): self.ct_value=str(self.hex2dec(self.decode_result[0:2])) self.display="----- MasterCard Base64 Decoding message ---\n \ 1.Control_type %s \n\ 2.HMAC= %s \n\ 3.ACS identify= %s\n\ 4.Auth-Method= %s \n\ 5.Bin-identify= %s\n\ 6.Transaction-seq=%s\n\ 7.MAC= %s\n\ 8.Expire-date(yymm)= %s\n\ 9.Cvv = %s\n\ 10.Service-Code= %s\n\ 11.Decode message=%s"\ %(self.decode_result[0:2],self.decode_result[2:18],\ self.decode_result[18:20],self.decode_result[20:21],\ self.decode_result[21:22],self.decode_result[22:30],\ self.decode_result[30:40],self.hex2dec(self.decode_result[26:30]),\ self.decode_result[31:34],self.decode_result[20:21]+self.ct_value[1:], \ self.decode_result) def visa(self): self.display= '----- VISA Base64 Decoding message ---\n\ 1.3D Secure Authentication Results Code= %s\n\ 2.Second Factor Authentication Code= %s\n\ 3.CAVV Key Indicator= %s\n\ 4.CVV output= %s\n\ 5.Unpredicactable number=%s\n\ 6.Authencation Tracking Number=%s\n\ 7.Expire-date(yymm)=%s\n\ 8.Cvv = %s\n\ 9.Service-Code=%s\n\ 10.Decode message=%s'\ %(self.decode_result[0:2],self.decode_result[2:4],\ self.decode_result[4:6],self.decode_result[6:8],\ self.decode_result[10:14],self.decode_result[14:30],\ self.decode_result[10:14],self.decode_result[7:10],\ self.decode_result[1:4],self.decode_result) def _code_button_changed(self): if self.option in ['E']: self.even=divmod(len(self.input_text),2) if self.even[1] <> 0: self.display = "Len of Encode message is not EVEN" elif self.input_text.isalnum() == False: self.display = "Encode message MUST alphanumeric" else: self.display=binascii.b2a_base64(binascii.a2b_hex(self.input_text)) elif self.option in ['D']: self.even=divmod(len(self.input_text),2) if self.even[1] <> 0: self.display = "Len of Decode message is not EVEN" else: self.decode_result=binascii.b2a_hex(binascii.a2b_base64(self.input_text)) if self.card_type in ['V']: self.visa() elif self.card_type in ['M']: self.mcd() if __name__ == '__main__': a=Base64() a.configure_traits(view='view1') From johannes.black at gmail.com Thu Jun 3 22:21:17 2010 From: johannes.black at gmail.com (joblack) Date: Thu, 3 Jun 2010 19:21:17 -0700 (PDT) Subject: questions about how to parse a string and put it in a dictionary Message-ID: I've got a string which (without any CR or LF) consists of 'attribute1=attribute_value;attribute2=attribute_value2; ...' and I want them to read in a dictionary so that the attribute name is the key and the attribute value is the data. Any ideas for an implementation? Greetings and thanks jb From benjamin.kaplan at case.edu Thu Jun 3 22:34:46 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 3 Jun 2010 19:34:46 -0700 Subject: questions about how to parse a string and put it in a dictionary In-Reply-To: References: Message-ID: On Thu, Jun 3, 2010 at 7:21 PM, joblack wrote: > I've got a string which (without any CR or LF) consists of > > 'attribute1=attribute_value;attribute2=attribute_value2; ...' > > and I want them to read in a dictionary so that the attribute name is > the key and the attribute value is the data. > > Any ideas for an implementation? > > Greetings and thanks > jb > -- If you can guarantee that the attributes and values don't have semicolons or equal signs in them, you can just split it for pair in your_string.split(';') : key, value = pair.split('=') your_dict[key] = value From python at mrabarnett.plus.com Thu Jun 3 22:43:11 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 04 Jun 2010 03:43:11 +0100 Subject: questions about how to parse a string and put it in a dictionary In-Reply-To: References: Message-ID: <4C08683F.6040707@mrabarnett.plus.com> joblack wrote: > I've got a string which (without any CR or LF) consists of > > 'attribute1=attribute_value;attribute2=attribute_value2; ...' > > and I want them to read in a dictionary so that the attribute name is > the key and the attribute value is the data. > > Any ideas for an implementation? > > Greetings and thanks > Split the string on the semicolons, then split each resulting string on the equals, then pass the result to dict. You can use a generator expression for this (or a list comprehension if it's an old version of Python). If the string has a trailing semicolon then you should strip that off first. This all assumes that the values themselves don't contain semicolons or equals. From bryanjugglercryptographer at yahoo.com Thu Jun 3 22:54:35 2010 From: bryanjugglercryptographer at yahoo.com (Bryan) Date: Thu, 3 Jun 2010 19:54:35 -0700 (PDT) Subject: CTYPES structure passing References: <18124e50-30c9-4963-a194-f96bf309dd25@c7g2000vbc.googlegroups.com> Message-ID: Correction/addendum: I wrote: > try to to > be to upset when you find out how your three days were wasted... Of course that's, "try not to be too upset..." [...] > You're probably familiar with the Python > convention of special member names with double-underscores at each > end? Well, ctypes doesn't follow it. The double-ended-double-underscore convention is for names defined by the Python language. As a library module, ctypes is technically right not to use it. It's still a diabolical gotcha. [...] > If you spell _fields_ as ctypes > requires, it will complain about your assignments, in that you are > trying to assign an in to a union. Obviously a typo, for "trying to assign an int to a union." Come to think of it, I bet initially Peter West had that bit right. Because of the _fields_ issue, the correct assignment failed: FrameFormat.XUnion.subSample = 0 Without _fields_, ctypes did not create a FrameFormat.XUnion member, so the assignment fails with "AttributeError: 'LUCAM_FRAME_FORMAT' object has no attribute 'XUnion'". -- --Bryan Olson From zyzhu2000 at gmail.com Thu Jun 3 22:54:40 2010 From: zyzhu2000 at gmail.com (GZ) Date: Thu, 3 Jun 2010 19:54:40 -0700 (PDT) Subject: Diff of Text Message-ID: Hi All, I am looking for an algorithm that can compare to source code files line by line and find the minimum diff. I have looked at the difflib included in python. The problem is that it is designed to make the diff results easier for humans to read, instead of minimize the size of the output differencial. I would like an algorithm implementation that gives the absolute minimum difference between the two files. Can you help me? Thanks, gz From johannes.black at gmail.com Thu Jun 3 23:05:47 2010 From: johannes.black at gmail.com (joblack) Date: Thu, 3 Jun 2010 20:05:47 -0700 (PDT) Subject: great References: Message-ID: Great - it works. Thanks a lot. From livibetter at gmail.com Thu Jun 3 23:20:39 2010 From: livibetter at gmail.com (livibetter) Date: Thu, 3 Jun 2010 20:20:39 -0700 (PDT) Subject: Plain simple unix timestamp with an HTTP GET References: <83cc363b-77f0-487d-901c-d15b275e43e5@y21g2000vba.googlegroups.com> Message-ID: This? hwclock --utc --set --date="$(datestr="$(curl http://208.66.175.36:13/ 2>/dev/null | cut -d \ -f 2-3)" ; echo ${datestr//-//})" Only hwclock, curl, cut, and Bash. PS. I didn't know I can set the time via hwclock, learned from Paul's post, but still didn't try to see if it does work. On Jun 4, 8:57?am, Ross wrote: > No - it's not really a python specific need, it's just what I'm using > just now, and can't think of where else to ask. It's also my fav test- > bed, as it's so easy. > > Your curl example is using grep and date which I don't have available. > I have no fancy libraries, just core parsing capability. > > I found that NIST has some capability on various servers. > > RFC 868 and 867. ?I can get this > > > curlhttp://208.66.175.36:13/ > > 55351 10-06-04 00:24:46 50 0 0 ? 8.3 UTC(NIST) * > > But I'd have a lot of parsing to pull it together. > > Apparently RFC868 provides a 32bit unformated binary response, but I > can't make much out of it. I think my TCP client library is expecting > chars and is screwed by bit-boundary expectations. > The number is supposed to be seconds since 1900, which is just as good > as seconds since 1970. > > Still hunting. Tho' maybe getting a bit off topic for a python msg > board :) > > On Jun 3, 8:36?pm, livibetter wrote: > > > > > I don't know what tools do you have on embedded system, but I really > > don't think this has to be using Python. > > > Here is what I would do on a normal desktop using your unique way to > > set up time: > > > ? date -s "$(curl -s -Ihttp://example.com|grep Date | cut -d \ ?-f > > 2-)" From livibetter at gmail.com Thu Jun 3 23:22:16 2010 From: livibetter at gmail.com (livibetter) Date: Thu, 3 Jun 2010 20:22:16 -0700 (PDT) Subject: Plain simple unix timestamp with an HTTP GET References: <83cc363b-77f0-487d-901c-d15b275e43e5@y21g2000vba.googlegroups.com> Message-ID: I forgot to mention I redirect stderr to /dev/null, because curl returns error code 56 to me with this message "curl: (56) Failure when receiving data from the peer" On Jun 4, 11:20?am, livibetter wrote: > This? > > hwclock --utc --set --date="$(datestr="$(curlhttp://208.66.175.36:13/ > 2>/dev/null | cut -d \ ?-f 2-3)" ; echo ${datestr//-//})" > > Only hwclock, curl, cut, and Bash. > > PS. I didn't know I can set the time via hwclock, learned from Paul's > post, but still didn't try to see if it does work. > > On Jun 4, 8:57?am, Ross wrote: > > > > > No - it's not really a python specific need, it's just what I'm using > > just now, and can't think of where else to ask. It's also my fav test- > > bed, as it's so easy. > > > Your curl example is using grep and date which I don't have available. > > I have no fancy libraries, just core parsing capability. > > > I found that NIST has some capability on various servers. > > > RFC 868 and 867. ?I can get this > > > > curlhttp://208.66.175.36:13/ > > > 55351 10-06-04 00:24:46 50 0 0 ? 8.3 UTC(NIST) * > > > But I'd have a lot of parsing to pull it together. > > > Apparently RFC868 provides a 32bit unformated binary response, but I > > can't make much out of it. I think my TCP client library is expecting > > chars and is screwed by bit-boundary expectations. > > The number is supposed to be seconds since 1900, which is just as good > > as seconds since 1970. > > > Still hunting. Tho' maybe getting a bit off topic for a python msg > > board :) > > > On Jun 3, 8:36?pm, livibetter wrote: > > > > I don't know what tools do you have on embedded system, but I really > > > don't think this has to be using Python. > > > > Here is what I would do on a normal desktop using your unique way to > > > set up time: > > > > ? date -s "$(curl -s -Ihttp://example.com|grep Date | cut -d \ ?-f > > > 2-)" From michele.simionato at gmail.com Thu Jun 3 23:28:20 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 3 Jun 2010 20:28:20 -0700 (PDT) Subject: plac, the easiest command line arguments parser in the world References: <1d09462d-3de1-4e40-8cc7-c45e18cf0ffd@m4g2000vbl.googlegroups.com> Message-ID: <3421135a-2089-410a-b24b-508fc64e4ae8@i28g2000yqa.googlegroups.com> On Jun 2, 6:37?am, Michele Simionato wrote: > I would like to announce to the world the first public release of > plac: > > ?http://pypi.python.org/pypi/plac The second release is out. I have added the recognition of keyword arguments, improved the formatting of the help message, and added many tests. From bryanjugglercryptographer at yahoo.com Thu Jun 3 23:29:01 2010 From: bryanjugglercryptographer at yahoo.com (Bryan) Date: Thu, 3 Jun 2010 20:29:01 -0700 (PDT) Subject: questions about how to parse a string and put it in a dictionary References: Message-ID: joblack wrote: > I've got a string which (without any CR or LF) consists of > > 'attribute1=attribute_value;attribute2=attribute_value2; ...' Technically that's short of a rigorous specification, but it sure looks like a standard web "query string", the content type known as "application/x-www-form-urlencoded". See: http://en.wikipedia.org/wiki/Query_string > and I want them to read in a dictionary so that the attribute name is > the key and the attribute value is the data. > > Any ideas for an implementation? Parsing query strings is already implemented (more than once) in Python's standard library. In current Python 2.x, you might use urlparse.parse_qs(). As in: >>> from urlparse import parse_qs >>> >>> parse_qs('attribute1=attribute_value;attribute2=attribute_value2') {'attribute2': ['attribute_value2'], 'attribute1': ['attribute_value']} You'll note the values are lists, to handle the cases where a name is equated to more than one simple value. -- --Bryan Olson From steve at REMOVE-THIS-cybersource.com.au Fri Jun 4 00:54:13 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jun 2010 04:54:13 GMT Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <1275560120.8775.6.camel@linux-yu4c.site> Message-ID: <4c0886f5$0$28659$c3e8da3@news.astraweb.com> On Thu, 03 Jun 2010 15:43:58 +0000, Monte Milanuk wrote: > Decent NNTP access is harder to find. Not impossible, but no longer a > 'free' part of most standard ISP access any more. I disagree. Since I've been on the Internet, over a decade now (what can I say? I was a slow starter), I've had three ISPs, and all three of them have provided NNTP access as a standard. One of them tried to cancel access to *binary* newsgroups, but they reversed that after customer complaints. I don't know what rubbish ISPs you're dealing with, or what country you're in, but not all ISPs in all countries are rubbish. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jun 4 01:03:13 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jun 2010 05:03:13 GMT Subject: An empty object with dynamic attributes (expando) References: Message-ID: <4c088911$0$28659$c3e8da3@news.astraweb.com> On Thu, 03 Jun 2010 14:00:11 -0700, dmtr wrote: > How can I create an empty object with dynamic attributes? It should be > something like: > >>>> m = object() >>>> m.myattr = 1 > > But this doesn't work. And I have to resort to: > >>>> class expando(object): pass >>>> m = expando() >>>> m.myattr = 1 > > Is there a one-liner that would do the thing? Why does it have to be a one-liner? Is the Enter key on your keyboard broken? You have a perfectly good solution: define a class, then instantiate it. But if you need a one-liner (perhaps to win a game of code golf), then this will work: >>> m = type('', (), {})() >>> m.attribute = 2 >>> -- Steven From phlip2005 at gmail.com Fri Jun 4 01:05:19 2010 From: phlip2005 at gmail.com (Phlip) Date: Thu, 3 Jun 2010 22:05:19 -0700 (PDT) Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <1275560120.8775.6.camel@linux-yu4c.site> <4c0886f5$0$28659$c3e8da3@news.astraweb.com> Message-ID: On Jun 3, 9:54?pm, Steven D'Aprano wrote: > I don't know what rubbish ISPs you're dealing with You've heard of a little fly-by-night outfit called AT&T? From clp2 at rebertia.com Fri Jun 4 01:07:25 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 3 Jun 2010 22:07:25 -0700 Subject: Python Forum In-Reply-To: <4c0886f5$0$28659$c3e8da3@news.astraweb.com> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <1275560120.8775.6.camel@linux-yu4c.site> <4c0886f5$0$28659$c3e8da3@news.astraweb.com> Message-ID: On Thu, Jun 3, 2010 at 9:54 PM, Steven D'Aprano wrote: > On Thu, 03 Jun 2010 15:43:58 +0000, Monte Milanuk wrote: >> Decent NNTP access is harder to find. ?Not impossible, but no longer a >> 'free' part of most standard ISP access any more. > > I disagree. Since I've been on the Internet, over a decade now (what can > I say? I was a slow starter), I've had three ISPs, and all three of them > have provided NNTP access as a standard. One of them tried to cancel > access to *binary* newsgroups, but they reversed that after customer > complaints. > > I don't know what rubbish ISPs you're dealing with, or what country > you're in, but not all ISPs in all countries are rubbish. The US high-speed consumer ISP market isn't very competitive and some players in the oligopoly are indeed rubbish WRT newsgroups. Case in point: http://www.comcast.net/newsgroups/ Cheers, Chris -- Not that I care. Mailinglists seem about as good anyway. http://blog.rebertia.com From steve at REMOVE-THIS-cybersource.com.au Fri Jun 4 01:11:16 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jun 2010 05:11:16 GMT Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87zkzccx3q.fsf@benfinney.id.au> <88192331-3301-47f8-8742-0a26eb9a65f0@j9g2000vbp.googlegroups.com> Message-ID: <4c088af3$0$28659$c3e8da3@news.astraweb.com> On Thu, 03 Jun 2010 03:16:03 -0700, Pierre Quentel wrote: > So the OP's initiative should be an incentive to think on the format of > the interaction between all the range of Python users, from newbees to > gurus. We are in the 2.0 era, with social networks all over the place > using a pleasant interface, Really? I can't think of any 2.0 era social networks using pleasant interfaces. All the ones I've seen or used start with mediocre interfaces and get worse from there. > while c.l.p has a rather austere look and feel, with text only, Thank goodness for that! > no way to present code snippets in a different > font / background than discussions, If somebody can't distinguish code from comments in a post by the context, they aren't cut out to be a programmer and should probably stick to posting "OMG LOL" on a social networking site. > and even an unintuitive way of entering links... Pasting or typing a URL is unintuitive? If somebody can't take the time and effort to post a URL in a form that is not broken, well, that doesn't say much for their skills as a coder does it? If you can't handle the fact that URLs can't be broken over multiple lines in email and news posts, how do you expect to handle even more vigorous requirements while programming? > I'm not saying that pythonforum.org is the best solution but it > certainly looks more attractive than c.l.p. to the new generation of > Python users I get: While trying to retrieve the URL: http://pythonforum.org/ The following error was encountered: Connection to 173.83.46.254 Failed The system returned: (111) Connection refused Oops. Looks like they can't handle the millions of new users joining up. Despite my sarcasm, I actually do wish them the best. I'm not too worried about fragmenting the community -- the community is already fragmented, and that's a *good thing*. There are forums for newbies, for development *of* Python (rather than development *in* Python), for numeric work in Python, for Italian-speakers, for game development, etc. This is the way it should be, and I don't fear a competing general Python forum or forums. If they're better than comp.lang.python, they will attract more users and become the place to be, and if they're not, they won't. -- Steven From debatem1 at gmail.com Fri Jun 4 01:31:01 2010 From: debatem1 at gmail.com (geremy condra) Date: Fri, 4 Jun 2010 01:31:01 -0400 Subject: Python Forum In-Reply-To: References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <1275560120.8775.6.camel@linux-yu4c.site> <4c0886f5$0$28659$c3e8da3@news.astraweb.com> Message-ID: On Fri, Jun 4, 2010 at 1:05 AM, Phlip wrote: > On Jun 3, 9:54?pm, Steven D'Aprano cybersource.com.au> wrote: > >> I don't know what rubbish ISPs you're dealing with > > You've heard of a little fly-by-night outfit called AT&T? They were my ISP as of three weeks ago. Has something changed since then? Geremy Condra From steve at REMOVE-THIS-cybersource.com.au Fri Jun 4 01:41:17 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jun 2010 05:41:17 GMT Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> Message-ID: <4c0891fc$0$28659$c3e8da3@news.astraweb.com> On Thu, 03 Jun 2010 06:15:20 -0400, Adam Tauno Williams wrote: > So? NNTP is the living dead. Time to let it go. So you say. I think the millions of posts on Usenet say different. According to Wikipedia, the average number of all text posts in the Big-8 newsgroups is 1,800 new messages every hour. That excludes binary groups, where the amount of traffic is much, much bigger. Sure, a lot of those 1,800 posts are spam, but the spammers wouldn't waste their time if they didn't think there were people still on Usenet. > Most people use this list via e-mail, How do you know? Do you have evidence for this, or are you just making it up? In a later post, you claimed the evidence is: "Scan through a bunch of threads with show-headers. Watch the User-Agent value (set by the senders client). The results become obvious pretty quickly." Or in other words, a non-random selection of posts followed by an error- prone and subjective test. I've picked seven posts from this thread, from seven different users, and I get these User Agents: User-Agent Count Mail or News? none 1 unknown Mozilla/5.0 1 Both Gnus/5.13 2 Both G2/1.0 2 Web (interface to News) Thunderbird 1 Both I happen to know at least one of the Gnus users is using News, so that's 1 definite News, 2 Web, 4 either News or email, and no definite email. -- Steven From vinay_sajip at yahoo.co.uk Fri Jun 4 01:50:46 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Thu, 3 Jun 2010 22:50:46 -0700 (PDT) Subject: Vote to Add Python Package "pubsub" to the Python Standard Library References: <6b9d2898-4166-40b4-9016-dc55dee77d00@q33g2000vbt.googlegroups.com> <8799a47b-9d16-4187-8862-31570c9d9b11@v25g2000yqv.googlegroups.com> <700eca3d-06f2-4672-8741-549ddb722d88@k39g2000yqd.googlegroups.com> Message-ID: On Jun 4, 1:03?am, Carl Banks wrote: > Which is an implementation of publish-subscribe pattern. ?I didn't say > or imply it was general purpose. ?And it doesn't have to be to make a > case for inclusion of a general-purpose implementation in the standard > library. It's analogous, but it's not messaging. And I didn't give that as a reason why there should or shouldn't be a pub/sub module in the stdlib; my other comments were more relevant in that debate. Regards, Vinay Sajip From steve at REMOVE-THIS-cybersource.com.au Fri Jun 4 02:08:18 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Jun 2010 06:08:18 GMT Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <1275560120.8775.6.camel@linux-yu4c.site> <4c0886f5$0$28659$c3e8da3@news.astraweb.com> Message-ID: <4c089852$0$28659$c3e8da3@news.astraweb.com> On Thu, 03 Jun 2010 22:05:19 -0700, Phlip wrote: > On Jun 3, 9:54?pm, Steven D'Aprano cybersource.com.au> wrote: > >> I don't know what rubbish ISPs you're dealing with > > You've heard of a little fly-by-night outfit called AT&T? Yes I have. Aren't they the people who were engaged in a long-running criminal conspiracy to break the law and commit illegal warrantless surveillance of American citizens? If you look at the reviews here: http://www.dslreports.com/gbu/ they are a distinct second-class ISP, with average B scores. Perhaps that's better than "rubbish", but it's nothing to be proud about when you are a company the size of AT&T. When you have that many resources, anything less than straight A+ is a failure. And that's not even mentioning their lack of News access, their ham- fisted and clueless blocking of 4chan (whether in legitimate self-defence or not), or their stance on net neutrality. But the really sad thing is that you think that "bigger" automatically equals "better". -- Steven From gagsl-py2 at yahoo.com.ar Fri Jun 4 02:21:31 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 3 Jun 2010 23:21:31 -0700 (PDT) Subject: changing format of time duration. References: <11191764-f704-4f1e-9a0e-1fb9d174afa1@l6g2000vbo.googlegroups.com> Message-ID: <16748e83-2b7e-44f2-a581-d9a540365a84@k39g2000yqd.googlegroups.com> On 3 jun, 17:24, dave wrote: > Quick question. I have to time stamps (now and now2). > > now = datetime.datetime.now(); > now2 = datetime.datetime.now(); > > now2-now1 yields me a result in 0:00:00.11221 (H:MM:SS.ssss) > > I wanted to know if there is a standard python method or a quick hack > to add an extra zero in the beginning. > > So the result I am looking for would be 00:00:00.11221 Try the strptime method with a suitable format, like this (untested): delta = now2-now1 delta.strftime('%H:%M:%S.%f') http://docs.python.org/library/datetime.html#strftime-strptime-behavior -- Gabriel Genellina From darcy at druid.net Fri Jun 4 02:29:58 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 4 Jun 2010 02:29:58 -0400 Subject: Python Forum In-Reply-To: <4c0891fc$0$28659$c3e8da3@news.astraweb.com> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <4c0891fc$0$28659$c3e8da3@news.astraweb.com> Message-ID: <20100604022958.aad18ca8.darcy@druid.net> On 04 Jun 2010 05:41:17 GMT Steven D'Aprano wrote: > Sure, a lot of those 1,800 posts are spam, but the spammers wouldn't > waste their time if they didn't think there were people still on Usenet. Kidding, right? Cost to spam is virtually zero so the ROI is pretty close to infinite no matter how many people they reach. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From payal-python at scriptkitchen.com Fri Jun 4 02:31:53 2010 From: payal-python at scriptkitchen.com (Payal) Date: Thu, 3 Jun 2010 23:31:53 -0700 Subject: queries about exceptions(newbie) Message-ID: <20100604063153.GA19876@scriptkitchen.com> Hi all, I am trying to learn exceptions and have few small doubts from http://docs.python.org/tutorial/errors.html There are many statements there of the form, ... except Exception as inst: do something ... except ZeroDivisionError as detail: do something ... except MyError as e: do something My questions are, what are these "inst", "detail", "e" etc. Are they special words? what does the word "as" do? Thanks a lot in advance. With warm regards, -Payal -- From clp2 at rebertia.com Fri Jun 4 02:42:16 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 3 Jun 2010 23:42:16 -0700 Subject: queries about exceptions(newbie) In-Reply-To: <20100604063153.GA19876@scriptkitchen.com> References: <20100604063153.GA19876@scriptkitchen.com> Message-ID: On Thu, Jun 3, 2010 at 11:31 PM, Payal wrote: > Hi all, > I am trying to learn exceptions and have few small doubts from > http://docs.python.org/tutorial/errors.html > There are many statements there of the form, > > ... except Exception as inst: > ? ? ? ?do something > > ... except ZeroDivisionError as detail: > ? ? ? ?do something > > ... except MyError as e: > ? ? ? ?do something > > My questions are, > what are these "inst", "detail", "e" etc. Are they special words? No, just arbitrary variable names. > what does the word "as" do? If there's an exception of the specified type, the instanciated exception object will be bound to the specified variable before the body of the `except` statement executes. "as" is used when you want to inspect/manipulate the exception that was thrown. For example: >>> x = [] >>> x[1] Traceback (most recent call last): File "", line 1, in IndexError: list index out of range >>> >>> try: ... x[1] ... except IndexError as e: ... print "Got error:", e.args[0] # grab the error message ... Got error: list index out of range If you don't care about the actual exception object, you can of course omit the "as" part of the except clause. Cheers, Chris -- http://blog.rebertia.com From nagle at animats.com Fri Jun 4 02:43:28 2010 From: nagle at animats.com (John Nagle) Date: Thu, 03 Jun 2010 23:43:28 -0700 Subject: Python Forum In-Reply-To: <4c088af3$0$28659$c3e8da3@news.astraweb.com> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87zkzccx3q.fsf@benfinney.id.au> <88192331-3301-47f8-8742-0a26eb9a65f0@j9g2000vbp.googlegroups.com> <4c088af3$0$28659$c3e8da3@news.astraweb.com> Message-ID: <4c089a9f$0$1623$742ec2ed@news.sonic.net> Steven D'Aprano wrote: > On Thu, 03 Jun 2010 03:16:03 -0700, Pierre Quentel wrote: > >> So the OP's initiative should be an incentive to think on the format of >> the interaction between all the range of Python users, from newbees to >> gurus. We are in the 2.0 era, with social networks all over the place >> using a pleasant interface, > > Really? I can't think of any 2.0 era social networks using pleasant > interfaces. All the ones I've seen or used start with mediocre interfaces > and get worse from there. > > >> while c.l.p has a rather austere look and feel, with text only, > > Thank goodness for that! > > >> no way to present code snippets in a different >> font / background than discussions, > > If somebody can't distinguish code from comments in a post by the > context, they aren't cut out to be a programmer and should probably stick > to posting "OMG LOL" on a social networking site. > >> and even an unintuitive way of entering links... > > Pasting or typing a URL is unintuitive? > > If somebody can't take the time and effort to post a URL in a form that > is not broken, well, that doesn't say much for their skills as a coder > does it? If you can't handle the fact that URLs can't be broken over > multiple lines in email and news posts, how do you expect to handle even > more vigorous requirements while programming? > > >> I'm not saying that pythonforum.org is the best solution but it >> certainly looks more attractive than c.l.p. to the new generation of >> Python users > > I get: > > While trying to retrieve the URL: http://pythonforum.org/ > The following error was encountered: > Connection to 173.83.46.254 Failed > The system returned: > (111) Connection refused > > > Oops. Looks like they can't handle the millions of new users joining up. > > Despite my sarcasm, I actually do wish them the best. I'm not thrilled about having to deal with yet another forum system This one is at best mediocre. It took 14 seconds to deliver its home page. It wants me to "register". Which probably means I'll be spammed. Forum Software Review gives "Informer Technologies" a 2 out of 5 on their system. I know USENET is obsolete, but the alternatives are worse. If we're going to have a forum system, it probably should be on "Python.org", which already has mailing lists, a wiki, an IRC server, and a way to order T-shirts. John Nagle From bv.tryton at gmail.com Fri Jun 4 03:20:05 2010 From: bv.tryton at gmail.com (B.V.) Date: Fri, 4 Jun 2010 00:20:05 -0700 (PDT) Subject: Mixing Decimal and float References: <4c06e51b$0$14161$c3e8da3@news.astraweb.com> Message-ID: On Jun 3, 2:00?am, Chris Rebert wrote: > On Wed, Jun 2, 2010 at 4:11 PM, Steven D'Aprano > > wrote: > > On Wed, 02 Jun 2010 17:17:11 -0400, Nathan Rice wrote: > >> My apologies if someone already mentioned this and I missed it but... > > >> class.__instancecheck__(self,?instance) - Return true if?instance should > >> be considered a (direct or indirect) instance of?class. If defined, > >> called to implement?isinstance(instance,?class). > > >> class.__subclasscheck__(self,?subclass) - Return true if?subclass should > >> be considered a (direct or indirect) subclass of?class. If defined, > >> called to implement?issubclass(subclass,?class). > > > The original poster needs to support Python 2.5 and 2.6, but > > __instancecheck__ and __subclasscheck__ are only supported in 2.6 or > > higher, so this doesn't help. > > Even in 2.6+, good luck trying to define new methods on class `type` > (the metaclass of float and Decimal). > > Cheers, > Chris > --http://blog.rebertia.com You mean it! I have spent two hours trying it, with no success. I think we manage to find another solution to our problem. Thank you for helping. B. From bv.tryton at gmail.com Fri Jun 4 03:29:36 2010 From: bv.tryton at gmail.com (B.V.) Date: Fri, 4 Jun 2010 00:29:36 -0700 (PDT) Subject: Mixing Decimal and float References: <413efca9-ec02-4f84-8bef-688d50a65953@f14g2000vbn.googlegroups.com> <4322c313-d32a-4c3f-bd91-a0f1694693cf@o12g2000vba.googlegroups.com> <4c06c0a6$1@news.x-privat.org> Message-ID: On Jun 2, 10:35?pm, I V wrote: > On Wed, 02 Jun 2010 05:17:11 -0700, B.V. wrote: > > But trying to be open to other languages, the server implements also an > > XMLRPC interface (and also a JSONRPC-like interface). That's the key > > point: Decimal is python specific. So in an application, you can't rely > > on the value received from a client, because depending on the protocol, > > the type of the value is different. So the idea was to create a class > > that can behave like a Decimal or a float depending on the context, and > > set xmlrpclib.Unmarshaller.dispatch["double"] to a function that return > > a Float instance. > > Looking at the Tryton docs, it seems that it already supports field types > that can't be directly represented in XMLRPC or JSON, like BigInteger or > Selection. How are these serialized over the non-python RPC mechanisms? > Could you not do the same for Decimals? > That's what was done first, it works for data sent by the server. But when the server receives data, it's always float. How guess that a float has to stay a float or became a Decimal ? Well, Selection are just strings, no problem over any RPC mechanisms. For the BigInteger, good question. Maybe there's a problem with, because AFAIK it's not used in any of the classes. I think I give it a try and who knows, maybe find a new bug ... B. From kaerbuhez at gmail.com Fri Jun 4 03:40:58 2010 From: kaerbuhez at gmail.com (kaer) Date: Fri, 4 Jun 2010 00:40:58 -0700 (PDT) Subject: Parse and clean odt docs: with lxml ? hints to start ? Message-ID: Basically, I have to upgrade a website with a lot of new content. I received those docs in the openoffice format. If I open and save one of those documents in the html format, I can cut and paste the result in the html page, it's not that bad as a start but I need to clean that html (remove tags, remove or change attributes, ...). My first idea is to use lxml for that. My questions: - is there a better way ? - is lxml the right tool for that ? - some examples of code for doing that ? Have a nice day. From mail at timgolden.me.uk Fri Jun 4 03:46:18 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 04 Jun 2010 08:46:18 +0100 Subject: Windows and My Documents In-Reply-To: <2010060310502875249-bob@passcalnmtedu> References: <2010060309393816807-bob@passcalnmtedu> <2010060310502875249-bob@passcalnmtedu> Message-ID: <4C08AF4A.6030909@timgolden.me.uk> On 03/06/2010 17:50, Bob Greschke wrote: > On 2010-06-03 09:57:11 -0600, Tim Golden said: > >> On 03/06/2010 16:39, Bob Greschke wrote: >>> How do I do a "listdir" (or whatever I need to use) of the Desktop on a >>> Windows machine and have "folders" like My Documents show up in the >>> result? >>> >>> I'm specifically trying to get a link to VMWare Shared Folders to show >>> up so I can navigate to files in OSX from WinXP running in VMWare, but >>> My Documents doesn't show up, either. >>> >>> The docs for listdir says it doesn't follow links and I don't think I >>> want to tell os.walk to followlinks as that could be zillions of files. >> >> Depends exactly what '"folders" like My Documents' means (since I'm >> unfamiliar >> with VMWare Shared Folders) but you almost certainly want to use the >> Shell >> functions to walk the shell from the Desktop root. There was a short >> thread >> recently about it which I'll try to dig up (digs...): >> >> http://mail.python.org/pipermail/python-win32/2010-May/010475.html >> >> TJG > > Well, My Documents is not a normal folder. It's not the same as > right-clicking and creating a new folder. I don't know what it is, > exactly. It's a shell folder. Which is what the code I pointed to deals with. VMWare Shared Folders seems to be a normal sort of link to > '\\.host\Share Folders', but not quite, however, beyond that I'm not > sure what it is. This would be the official starting point for reading up on the matter if you were motivated enough: http://msdn.microsoft.com/en-us/library/bb773177%28VS.85%29.aspx Basically, Windows has two "file systems" running in parallel and mostly, but not always, overlapping: the normal NTFS file system; and the Shell system. The NTFS file system starts from, say, c:\ and goes down from there. The Shell starts from the desktop and goes down from there. Obviously, under the covers, all shell objects have to be stored in some way on the file system. All NTFS files are represented within the Shell system; not all Shell objects are straightforwardly represented within the NTFS filesystem. If I create Shortcuts to My Documents and VSF those > show up with listdir, but I cannot follow them; Python does not think > they are directories, which they aren't (they show up from listdir as > 'Shortcut to My Documents.lnk', for example). Now you're talking about something slightly different. Windows has had Shortcuts since pretty much forever. They also are Shell objects and the shortcut-ness is only interpreted by the Shell, not by the filesystem. NTFS has had junctions and hardlinks since Win2K and now has symbolic links (which are implemented, I think, on the top of the uber-flexible Reparse Points) from Vista onwards. Both the Shell and the filesystem will follow these. Indeed you have to go out of your way *not* to follow them. Hopefully that explanation has helped (where it hasn't confused!). You might want to look at my winshell module (long overdue for an upgrade): http://timgolden.me.uk/python/winshell.html and at some of the articles on Mike Driscoll's Blog: http://www.blog.pythonlibrary.org/2010/02/25/creating-windows-shortcuts-with-python-part-ii/ TJG From gd.usenet at spamfence.net Fri Jun 4 05:14:21 2010 From: gd.usenet at spamfence.net (=?UTF-8?Q?G=C3=BCnther?= Dietrich) Date: Fri, 04 Jun 2010 11:14:21 +0200 Subject: changing format of time duration. References: <11191764-f704-4f1e-9a0e-1fb9d174afa1@l6g2000vbo.googlegroups.com> <16748e83-2b7e-44f2-a581-d9a540365a84@k39g2000yqd.googlegroups.com> Message-ID: Gabriel Genellina wrote: >Try the strptime method with a suitable format, like this (untested): >delta = now2-now1 >delta.strftime('%H:%M:%S.%f') Throws an exception: |Traceback (most recent call last): | File "", line 1, in |AttributeError: 'datetime.timedelta' object has no attribute 'strftime' What seems logical, since the documentation doesn't mention an strftime method for timedelta. Regards, G?nther From giacomo.boffi at polimi.it Fri Jun 4 05:22:44 2010 From: giacomo.boffi at polimi.it (Giacomo Boffi) Date: Fri, 04 Jun 2010 11:22:44 +0200 Subject: if, continuation and indentation References: Message-ID: <86fx13rw2j.fsf@aiuole.stru.polimi.it> HH writes: > if (width == 0 and > height == 0 and > color == 'red' and > emphasis == 'strong' or > highlight > 100): > raise ValueError("sorry, you lose") if (width == 0 and height == 0 and color == 'red' and emphasis == 'strong' or highlight > 100): raise ValueError("sorry, you lose") -- compro mobili vecchi - vendo mobili antichi From payal-python at scriptkitchen.com Fri Jun 4 05:52:50 2010 From: payal-python at scriptkitchen.com (Payal) Date: Fri, 4 Jun 2010 02:52:50 -0700 Subject: queries about exceptions(newbie) In-Reply-To: References: <20100604063153.GA19876@scriptkitchen.com> Message-ID: <20100604095250.GA21544@scriptkitchen.com> On Thu, Jun 03, 2010 at 11:42:16PM -0700, Chris Rebert wrote: > >>> try: > ... x[1] > ... except IndexError as e: > ... print "Got error:", e.args[0] # grab the error message > ... > Got error: list index out of range Thanks a lot. This example solved what the tutorial could not. With warm regards, -Payal -- From alanwilter at gmail.com Fri Jun 4 06:01:29 2010 From: alanwilter at gmail.com (Alan) Date: Fri, 4 Jun 2010 11:01:29 +0100 Subject: threading and atexit: different behaviour in python2.6 from 2.5 Message-ID: Hi there, That's another try to get help about this issue I am facing. To help you to help me here goes a simple example. This is a very simplification of a very complex code. -------------------- thread_ping.py -------------------- begin import time import sys import atexit from threading import Thread class testit(Thread): def __init__ (self,ip): Thread.__init__(self) self.ip = ip self.status = 0 def run(self): pingaling = os.popen("ping -q -c2 "+self.ip,"r") while 1: line = pingaling.readline() if not line: break igot = re.findall(testit.lifeline,line) if igot: self.status = int(igot[0]) def goodbye(t, report): print 'Goodbye' print "Status from ",t.ip,"is",report[t.status] testit.lifeline = re.compile(r"(\d) packets received") report = ("No response","Partial Response","Alive") ip = "209.85.227.104" # www.google.com # try with a failing IP if you want the test to last a bit longer t = testit(ip) atexit.register(goodbye, t, report) t.start() exit() -------------------- thread_ping.py -------------------- end If one runs like: amadeus[2579]:~/TMP% time python2.6 thread_ping.py Goodbye Status from 209.85.227.104 is Alive python2.6 thread_ping.py 0.02s user 0.02s system 3% cpu 1.056 total (i.e., python2.6 wait till the thread finishes and leave... I don't want this behaviour, see below) and amadeus[2580]:~/TMP% time python2.5 thread_ping.py Goodbye Status from 209.85.227.104 is No response python2.5 thread_ping.py 0.01s user 0.01s system 90% cpu 0.030 total (i.e., python2.5 promptly quit, as desired) Could someone tell me how to get python2.6 to have the same behaviour I see with python2.5 for this example code? Any hint would be very much appreciated indeed. Many thanks in advance. Alan -- Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate Department of Biochemistry, University of Cambridge. 80 Tennis Court Road, Cambridge CB2 1GA, UK. >>http://www.bio.cam.ac.uk/~awd28<< -------------- next part -------------- An HTML attachment was scrubbed... URL: From payal-python at scriptkitchen.com Fri Jun 4 06:10:20 2010 From: payal-python at scriptkitchen.com (Payal) Date: Fri, 4 Jun 2010 03:10:20 -0700 Subject: one more exception newbie query Message-ID: <20100604101020.GB21544@scriptkitchen.com> Hi all, In http://docs.python.org/tutorial/errors.html#handling-exceptions it says, | >>> try: | ... raise Exception('spam', 'eggs') Why would I want to use a class for exception? I could simply use raise w/o it? Also the help() says, class Exception(BaseException) But we have used 'spam' and 'eggs'. Why? | ... except Exception as inst: Now what does "as inst" do here? (Is it making an instance, but how? Aren't instances made with this, inst = Klass() ?) Thanks a lot in advance. With warm regards, -Payal -- From clp2 at rebertia.com Fri Jun 4 06:22:35 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 4 Jun 2010 03:22:35 -0700 Subject: one more exception newbie query In-Reply-To: <20100604101020.GB21544@scriptkitchen.com> References: <20100604101020.GB21544@scriptkitchen.com> Message-ID: On Fri, Jun 4, 2010 at 3:10 AM, Payal wrote: > Hi all, > In http://docs.python.org/tutorial/errors.html#handling-exceptions it > says, > > | >>> try: > | ... ? ?raise Exception('spam', 'eggs') > > Why would I want to use a class for exception? I could simply use raise > w/o it? `raise Foo, "whatever"` and `raise Foo("whatever")` do the same thing; the former is deprecated though as it's been removed from Python 3.x > Also the help() says, > class Exception(BaseException) That's *not* a constructor method signature. It's a class declaration saying Exception is a subclass of the class BaseException. > But we have used 'spam' and 'eggs'. Why? > > | ... except Exception as inst: > > Now what does "as inst" do here? (Is it making an instance, but how? > Aren't instances made with this, inst = Klass() ?) It's as I explained it before. Another example: >>> class FooError(BaseException): ... def __init__(self, x): ... self.x = x ... >>> try: ... raise FooError(42) ... except FooError as e: ... print "x =", e.x ... x = 42 The "e" from the "as" is the FooError exception that was raise-d. I would suggest addressing further questions to the newbie-specific Python mailinglist, python-tutor: http://mail.python.org/mailman/listinfo/tutor Cheers, Chris -- http://blog.rebertia.com From john_re at fastmail.us Fri Jun 4 06:47:04 2010 From: john_re at fastmail.us (giovanni_re) Date: Fri, 04 Jun 2010 03:47:04 -0700 Subject: BerkeleyTIP Join June Global Free SW HW Culture Mtgs via VOIP or in Berkeley Message-ID: <1275648424.6407.1378441381@webmail.messagingengine.com> Video: Scientific data visualization using Mayavi2, Gael Varoquaux, Python4ScienceUCB ===== You're invited to join in with the friendly people at the BerkeleyTIP global meeting - newbie to Ph.D. - everyone is invited. Get a headset & join using VOIP online, or come to Berkeley. 1st step: Join the mailing list: http://groups.google.com/group/BerkTIPGlobal Watch the videos. Discuss them on VOIP. 8 great videos/talks this month - see below. Starting off year 3 of BerkeleyTIP :) Join with us at the LOCATION TO BE DETERMINED at the University of California at Berkeley, or join from your home via VOIP, or send this email locally, create a local meeting, & join via VOIP: Tip: a wifi cafe is a great place to meet. :) JUNE 5 & 20 AT UCB MEETING LOCATIONS TO BE DETERMINED. PLEASE VIEW THE BTIP WEBSITE & MAILING LIST PAGES FOR THE LATEST DETIALS. http://sites.google.com/site/berkeleytip http://groups.google.com/group/BerkTIPGlobal BerkeleyTIP - Educational, Productive, Social For Learning about, Sharing, & Producing, All Free SW HW & Culture. TIP == Talks, Installfest, Project & Programming Party http://sites.google.com/site/berkeleytip ===== CONTENTS: 1) 2010 JUNE VIDEOS; 2) 2010 JUNE MEETING DAYS, TIMES, LOCATIONS; 3) LOCAL MEETING AT U. C. Berkeley LOCATION TO BE DETERMINED; 4) HOT TOPICS; 5) PLEASE RSVP PROBABILISTICALLY, THANKS :) ; 6) INSTALLFEST; SPECIAL: FREE 7th Annual BERKELEY WORLD MUSIC FESTIVAL June 5 Sat; 7) ARRIVING FIRST AT THE MEETING: MAKE A "BerkeleyTIP" SIGN; 8) IRC: #berkeleytip on irc.freenode.net; 9) VOIP FOR GLOBAL MEETING; 10) VOLUNTEERING, TO DOs; 11) MAILING LISTS: BerkeleyTIP-Global, LocalBerkeley, Announce; 12) ANYTHING I FORGOT TO MENTION?; 13) FOR FORWARDING ======================================================================= ===== 1) 2010 JUNE VIDEOS Super Computing for Business, Brian Modra, CLUG State of the Linux Union 2010, Jim Zemlin, Linux Foundation Journaled Soft-Updates, Dr. Kirk McKusick, BSDCan 2010 Scientific data visualization using Mayavi2, Gael Varoquaux, Python4ScienceUCB Bringing OLPC to children in Afghanistan, Carol Ruth Silver, OLPC-SF Text-to-Speech in Ubuntu with Kttsd Kmouth Festival, blip.tv Rabbi Rabbs, the UnixRabbi, leads a group of Unix geeks, Comedy, UUASC, BS"D, 2003 The Great Debate - Are We Alone?, Geoff Marcy and Dan Werthimer, SETI at UC Berkeley Thanks to all the speakers, organizations, & videographers. :) [Please alert the speakers that their talks are scheduled for June for BTIP (if you are with the group that recorded their talk), because I may not have time to do that. Thanks. :) ] URLs for video download & full details: http://sites.google.com/site/berkeleytip/talk-videos Download & watch these talks before the BTIP meetings. Discuss at the meeting. Email the mailing list, tell us what videos you'll watch & want to discuss: http://groups.google.com/group/BerkTIPGlobal Know any other video sources? - please email me. _Your_ group should video record & post online your meeting's talks! ===== 2) 2010 JUNE MEETING DAYS, TIMES, LOCATIONS In person meetings on 1st Saturday & 3rd Sunday, every month. June 5 & 20, 12N-3P USA-Pacific time, Saturday, Sunday Online only meeting using VOIP: June 14 & 29, 5-6P USA-Pacific time, Monday, Tuesday Mark your calendars. 5 Sat 12N-3P PDST = 3-6P EDST = 19-22 UTC 14 Mon 5-6P PDST = 8-9P EDST = 0- 1 UTC Tues 15 20 Sun 12N-3P PDST = 3-6P EDST = 19-22 UTC 29 Tues 5-6P PDST = 8-9P EDST = 0- 1 UTC Wed 30 USA-PacificDaylightSavingsTime is -7 hours UTC, due to daylight savings currently. Times listed above should be double checked by you for accuracy. ===== 3) LOCAL MEETING AT U. C. BERKELEY - LOCATION TO BE DETERMINED http://sites.google.com/site/berkeleytip/directions RSVP please. See below. It greatly helps my planning. But, _do_ come if you forgot to RSVP. THE JUNE 5 & 20 ON CAMPUS MEETING LOCATIONS ARE CURRENTLY TO BE DETERMINED. HOPEFULLY KNOW ON FRIDAY JUNE 4. PLEASE VIEW THE BTIP WEBSITE & MAILING LIST FOR THE FINALIZED LOCATION. THANK YOU. ALWAYS BE SURE TO CHECK THE BTIP WEBSITE _&_ MAILING LIST FOR THE LATEST LAST MINUTE DETAILS & CHANGES, BEFORE COMING TO THE MEETING! :) http://sites.google.com/site/berkeleytip http://groups.google.com/group/BerkTIPGlobal DO BRING A VOIP HEADSET, available for $10-30 at most electronics retail stores, & a laptop computer, so you are able to communicate with the global BTIP community via VOIP. It is highly recommended that you have a voip headset, & not rely on a laptop's built in microphone & speakers, because the headphones keep the noise level down. Bringing a headset is not required, but is a great part of the being able to communicate with the global community. :) Clothing: Typically 55-80 degrees F. Weather: http://www.wunderground.com/auto/sfgate/CA/Berkeley.html Other location local meeting possibilities: http://sites.google.com/site/berkeleytip/local-meetings Create a local meeting in your town. ===== 4) HOT TOPICS Oracle owns Sun - Free SW implications? OpenOffice? OpenOffice - Ready for college Fall 2010? MakerBot, RepRap - Personal Making - Like where PCs were in 1975? Android phones - Besting iPhone? worthwhile? How knowable is the hw? - Can BSD be run on Android phones? iPad, iPhone & iPod- rooting & running GNU(Linux) & BSD ===== 5) PLEASE RSVP PROBABILISTICALLY, THANKS :) If you think there is a >70% chance ("likely") you'll come to the in person meeting in Berkeley, please RSVP to me. Thanks. It helps my planning. Please _do_ come even if you haven't RSVP'd, it's not required. Better yet, join the BerkeleyTIP-Global mailing list, send the RSVP there, & tell us what things you're interested in, or what videos you'll try to watch - so we can know what videos are popular, & we might watch them too. :) http://groups.google.com/group/BerkTIPGlobal ===== 6) INSTALLFEST Get help installing & using Free Software, Hardware & Culture. Laptops only, typically. There isn't easy access for physically bringing desktop boxes here. RSVP _HIGHLY RECOMMENDED_ if you want installfest help. Please RSVP to me, Giovanni, at the from address for this announcement, or better, join & send email to the BTIP-Global mailing list telling us what you'd like help with. This way we can be better prepared to help you, & you might get valuable advice from the mailing list members. If you are new to using free software, an excellent system would be the KUbuntu GNU(Linux) software. It is very comprehensive, fairly easy to use (similar to Windows or Mac), & suitable for personal, home, university, or business use. We are also glad to try to help people with software who join via VOIP. Please email the mailing list with requests that you want help with, so we can try to be prepared better to help you. Installfest volunteers/helpers always welcome, in person, or via VOIP. :) ===== SPECIAL - MUSIC IN BERKELEY JUNE 5 SATURDAY ===== Also June 5 Sat in Berkeley, after BTIP: ===== FREE 7th Annual BERKELEY WORLD MUSIC FESTIVAL ===== Telegraph Avenue 12 Noon - 9 pm "Berkeley World Music Fest... has some of our best world musicians who call East Bay home...a wonderful event, and intimate, mix of outdoor performances in cafes and shops(the best music People's Park gets each year along Telegraph Ave. (Larry Kelp, KPFA music host)" Continuous music outdoors & in cafes http://www.berkeleyworldmusic.com/entry.asp?PageID=118 ===== 7) ARRIVING FIRST AT THE MEETING: MAKE A "BerkeleyTIP" SIGN If you get to the meeting & don't see a "BerkeleyTIP" sign up yet, please: 1) Make a BTIP sign on an 8x11 paper & put it at your table, 2) Email the mailing list, or join on IRC, & let us know you are there. Ask someone if you could use their computer for a minute to look something up, or send an email. People are usually very friendly & willing to help. We can also email you a temporary guest AirBears account login. We will have wifi guest accounts available for BTIP attendees. Be sure you have wifi capable equipment. Be Prepared: Bring a multi-outlet extension power cord. ===== 8) IRC: #berkeleytip on irc.freenode.net For help with anything, especially how to get VOIP working, & text communication. ===== 9) VOIP FOR GLOBAL MEETING Speak & listen to everyone globally using VOIP. Get a headset! See some VOIP instructions here: http://sites.google.com/site/berkeleytip/voice-voip-conferencing ===== 10) VOLUNTEERING, TO DOs Enjoy doing or learning something(s)? Help out BTIP in that area. Website development, mailing list management, video locating, VOIP server (FreeSwitch, Asterisk) or client (Ekiga, SFLPhone,...), creating a local meeting. Join the mailing list & let us know. Your offers of free help are always welcome here. :) ===== 11) MAILING LISTS: BerkeleyTIP-Global, LocalBerkeley, Announce Everyone should join the BerkeleyTIP-Global list: http://groups.google.com/group/BerkTIPGlobal Say "hi", tell us your interests, & what videos you'll like to watch. Info on all lists here: http://sites.google.com/site/berkeleytip/mailing-lists ===== 12) ANYTHING I FORGOT TO MENTION? Please join & email the BerkeleyTIP-Global mailing list. ===== 13) FOR FORWARDING You are invited to forward this message anywhere it would be appreciated. Better yet, use it to create a local meeting. Invite & get together with your friends locally, & join in with us all globally. :) Looking forward to meeting with you in person, or online. :) Giovanni From emin.shopper at gmail.com Fri Jun 4 07:00:00 2010 From: emin.shopper at gmail.com (Emin.shopper Martinian.shopper) Date: Fri, 4 Jun 2010 07:00:00 -0400 Subject: getting MemoryError with dicts; suspect memory fragmentation In-Reply-To: References: <1d1b48dd-3316-4a72-a8a0-e56d307e5ec7@n37g2000prc.googlegroups.com> Message-ID: On Thu, Jun 3, 2010 at 10:00 PM, dmtr wrote: > I'm still unconvinced that it is a memory fragmentation problem. It's > very rare. You could be right. I'm not an expert on python memory management. But if it isn't memory fragmentation, then why is it that I can create lists which use up 600 more MB but if I try to create a dict that uses a couple more MB it dies? My guess is that python dicts want a contiguous chunk of memory for their hash table. Is there a reason that you think memroy fragmentation isn't the problem? What else could it be? > Can you give more concrete example that one can actually try to > execute? Like: > > python -c "list([list([0]*xxx)+list([1]*xxx)+list([2]*xxx) > +list([3]*xxx) for xxx in range(100000)])" & Well the whole point is that this is a long running process which does lots of allocation and deallocation which I think fragments the memory. Consequently, I can't give a simple example like that. Thanks, -Emin From awilliam at whitemice.org Fri Jun 4 07:03:47 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Fri, 04 Jun 2010 07:03:47 -0400 Subject: Python Forum In-Reply-To: <80f1faae-146d-40b6-9075-613faf38a5f7@g39g2000pri.googlegroups.com> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c0619e7$0$24606$426a74cc@news.free.fr> <80f1faae-146d-40b6-9075-613faf38a5f7@g39g2000pri.googlegroups.com> Message-ID: <1275649427.7613.5.camel@linux-yu4c.site> On Thu, 2010-06-03 at 15:40 -0700, Phlip wrote: > On Jun 3, 3:20 pm, geremy condra wrote: > > > You mean like how I never get answers, to my super-easy GED-level > > > questions, here??! > > I agree. This proves conclusively that a web forum is the right > > place for you. > Ah, so you feel up to my "xsl for xmlrunner.py" question? I do a fair amount of xslt, but I don't have any idea what xmlrunner.py is. It isn't a GED-level question if it involves specific knowledge about a tertiary product/project. -- Adam Tauno Williams LPIC-1, Novell CLA OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba From payal-python at scriptkitchen.com Fri Jun 4 07:17:12 2010 From: payal-python at scriptkitchen.com (Payal) Date: Fri, 4 Jun 2010 04:17:12 -0700 Subject: one more exception newbie query In-Reply-To: References: <20100604101020.GB21544@scriptkitchen.com> Message-ID: <20100604111712.GA22179@scriptkitchen.com> Hi, I will continue this problem here & take the next to the tutor list. On Fri, Jun 04, 2010 at 03:22:35AM -0700, Chris Rebert wrote: > `raise Foo, "whatever"` and `raise Foo("whatever")` do the same thing; > the former is deprecated though as it's been removed from Python 3.x Actually I thought I could do, raise 'any error msg string' Now I know raise is for classes (or instances) only. > That's *not* a constructor method signature. It's a class declaration > saying Exception is a subclass of the class BaseException. Thanks, got it from the example again. Just curious what you meant by, "That's *not* a constructor method signature." Thanks a lot. With warm regards, -Payal -- From jeanmichel at sequans.com Fri Jun 4 07:25:37 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 04 Jun 2010 13:25:37 +0200 Subject: great In-Reply-To: References: Message-ID: <4C08E2B1.1070600@sequans.com> joblack wrote: > Great - it works. > > Thanks a lot. > > Thread of the week :) JM From moura.mario at gmail.com Fri Jun 4 07:32:49 2010 From: moura.mario at gmail.com (macm) Date: Fri, 4 Jun 2010 04:32:49 -0700 (PDT) Subject: [python] pass the name of args Message-ID: <8f424838-f888-416b-9a97-e907d201c627@w31g2000yqb.googlegroups.com> Hi Folks def myDef(x) doSomething x result = x.???? return coolThings --------------------------------- WhatYourName = ('python','is','cool') myDef(WhatYourName) so what I am looking for in myDef result = WhatYourName ---------------------------------- again : IhaveOtherName = ('some','thing') myDef(IhaveOtherName) so what I am looking for in myDef result = IhaveOtherName ---------------------------------- Is it possible with python? Regards macm From python.list at tim.thechases.com Fri Jun 4 08:28:45 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 04 Jun 2010 07:28:45 -0500 Subject: questions about how to parse a string and put it in a dictionary In-Reply-To: References: Message-ID: <4C08F17D.6020109@tim.thechases.com> On 06/03/2010 09:21 PM, joblack wrote: > I've got a string which (without any CR or LF) consists of > > 'attribute1=attribute_value;attribute2=attribute_value2; ...' > > and I want them to read in a dictionary so that the attribute name is > the key and the attribute value is the data. > > Any ideas for an implementation? While I agree with Bryan that this looks suspiciously like a URL query-string (and thus you likely want to use his suggestion for the built-in tools to parse them), I haven't seen the one-liner version float by, so here it is just for fun: s = "hello=world;this=that;foo=bar" results = dict((k,v) for (k,_,v) in (pair.partition('=') for pair in s.split(';'))) As Bryan cautions, URL query-strings can have multiple values for the same key, and your example doesn't address that case: foo=bar;foo=baz;hello=world;this=that so the code examples you're getting don't address it either :) -tkc From alfps at start.no Fri Jun 4 08:32:48 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 04 Jun 2010 14:32:48 +0200 Subject: one more exception newbie query In-Reply-To: References: Message-ID: * Payal, on 04.06.2010 12:10: > Hi all, > In http://docs.python.org/tutorial/errors.html#handling-exceptions it > says, > > |>>> try: > | ... raise Exception('spam', 'eggs') > > Why would I want to use a class for exception? I could simply use raise > w/o it? > Also the help() says, > class Exception(BaseException) > But we have used 'spam' and 'eggs'. Why? > > | ... except Exception as inst: > > Now what does "as inst" do here? (Is it making an instance, but how? > Aren't instances made with this, inst = Klass() ?) These questions are like "why is the door rectangular when sheep are known to dance in the moonlight only on dates divisible by cinnamon?". It's rather difficult to answer. I guess it's back to basics: read up on classes, instances, constructors. Experiment, create a lot of small programs. Don't think about exceptions just yet: you lack the fundamentals. Cheers & hth., - Alf -- blog at From spyder1960 at yahoo.com Fri Jun 4 08:38:36 2010 From: spyder1960 at yahoo.com (Spyder42) Date: Fri, 04 Jun 2010 04:38:36 -0800 Subject: Missing DLL in win98 Message-ID: <0bsh06pilrfls0i3f473unhbee1j71pmbs@4ax.com> I hope this is the right place to ask this, and appologise if it's not. I'm trying to install 2.6.5 in Win98 se final. It says "a required dll could not be run". Do I have to upgrade my whole OS just to install this, or is there a fix I can apply to 98 to make it work. The installer doesn't say what dll is missing, just that it is. Thanks in advance. L8r Spyder From lists at cheimes.de Fri Jun 4 08:50:28 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 04 Jun 2010 14:50:28 +0200 Subject: Missing DLL in win98 In-Reply-To: <0bsh06pilrfls0i3f473unhbee1j71pmbs@4ax.com> References: <0bsh06pilrfls0i3f473unhbee1j71pmbs@4ax.com> Message-ID: Am 04.06.2010 14:38, schrieb Spyder42: > I hope this is the right place to ask this, and appologise if it's > not. I'm trying to install 2.6.5 in Win98 se final. It says "a > required dll could not be run". Do I have to upgrade my whole OS just > to install this, or is there a fix I can apply to 98 to make it work. > The installer doesn't say what dll is missing, just that it is. Python 2.6 is not supported on Windows 98 and earlier. You need at least Windows 2000 with a recent service pack. Christian From clp2 at rebertia.com Fri Jun 4 08:51:04 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 4 Jun 2010 05:51:04 -0700 Subject: [python] pass the name of args In-Reply-To: <8f424838-f888-416b-9a97-e907d201c627@w31g2000yqb.googlegroups.com> References: <8f424838-f888-416b-9a97-e907d201c627@w31g2000yqb.googlegroups.com> Message-ID: On Fri, Jun 4, 2010 at 4:32 AM, macm wrote: > Hi Folks > > def myDef(x) > ? ? ? ?doSomething x > ? ? ? ?result = x.???? > ? ? ? ?return coolThings > --------------------------------- > > WhatYourName = ('python','is','cool') > > myDef(WhatYourName) > > so what I am looking for in myDef > > ? ? ? ?result = WhatYourName > > ---------------------------------- > again : > IhaveOtherName = ('some','thing') > > myDef(IhaveOtherName) > > so what I am looking for in myDef > > ? ? ? ?result = IhaveOtherName > > ---------------------------------- > > Is it possible with python? Not without very evil black-magic hackery. Explain /why/ you want this magic myDef() and someone will probably be able to suggest a better, alternative approach. Cheers, Chris -- http://blog.rebertia.com From quentel.pierre at wanadoo.fr Fri Jun 4 08:56:14 2010 From: quentel.pierre at wanadoo.fr (Pierre Quentel) Date: Fri, 4 Jun 2010 05:56:14 -0700 (PDT) Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87zkzccx3q.fsf@benfinney.id.au> <88192331-3301-47f8-8742-0a26eb9a65f0@j9g2000vbp.googlegroups.com> <4c088af3$0$28659$c3e8da3@news.astraweb.com> Message-ID: On 4 juin, 07:11, Steven D'Aprano wrote: > On Thu, 03 Jun 2010 03:16:03 -0700, Pierre Quentel wrote: > > So the OP's initiative should be an incentive to think on the format of > > the interaction between all the range of Python users, from newbees to > > gurus. We are in the 2.0 era, with social networks all over the place > > using a pleasant interface, > > Really? I can't think of any 2.0 era social networks using pleasant > interfaces. All the ones I've seen or used start with mediocre interfaces > and get worse from there. > > > while c.l.p has a rather austere look and feel, with text only, > > Thank goodness for that! > > > no way to present code snippets in a different > > font / background than discussions, > > If somebody can't distinguish code from comments in a post by the > context, they aren't cut out to be a programmer and should probably stick > to posting "OMG LOL" on a social networking site. They certainly *can* distinguish. But it's so easy to make it more explicit with syntax highlighting, background color, border etc. that most sites about programing languages use it, including the Python home site itself, or the Python cookbook on Active State > > > and even an unintuitive way of entering links... > > Pasting or typing a URL is unintuitive? > > If somebody can't take the time and effort to post a URL in a form that > is not broken, well, that doesn't say much for their skills as a coder > does it? If you can't handle the fact that URLs can't be broken over > multiple lines in email and news posts, how do you expect to handle even > more vigorous requirements while programming? That's 2 different things. When you use a programming language you know you have to adopt the syntax defined by the program. When you write something in a forum, you expect that the editor will be smart enough to know that http://pythonforum.org is a URL > > > I'm not saying that pythonforum.org is the best solution but it > > certainly looks more attractive than c.l.p. to the new generation of > > Python users > > I get: > > While trying to retrieve the URL:http://pythonforum.org/ > ?The following error was encountered: > ?Connection to 173.83.46.254 Failed ? > ?The system returned: > ? ? (111) Connection refused > > Oops. Looks like they can't handle the millions of new users joining up. > > Despite my sarcasm, I actually do wish them the best. I'm not too worried > about fragmenting the community -- the community is already fragmented, > and that's a *good thing*. There are forums for newbies, for development > *of* Python (rather than development *in* Python), for numeric work in > Python, for Italian-speakers, for game development, etc. This is the way > it should be, and I don't fear a competing general Python forum or > forums. If they're better than comp.lang.python, they will attract more > users and become the place to be, and if they're not, they won't. > > -- > Steven From spyder1960 at yahoo.com Fri Jun 4 09:08:03 2010 From: spyder1960 at yahoo.com (Spyder42) Date: Fri, 04 Jun 2010 05:08:03 -0800 Subject: Missing DLL in win98 References: <0bsh06pilrfls0i3f473unhbee1j71pmbs@4ax.com> Message-ID: <1guh06tt177al7rqar55ab0aiif1ibim57@4ax.com> On Fri, 04 Jun 2010 14:50:28 +0200, Christian Heimes wrote: > >Python 2.6 is not supported on Windows 98 and earlier. You need at least >Windows 2000 with a recent service pack. > >Christian So your response is either, you don't know if there is a fix, or 'No way in h377.' You couldn't figure out by my post that I already knew that? From rossgk at gmail.com Fri Jun 4 09:31:27 2010 From: rossgk at gmail.com (Ross) Date: Fri, 4 Jun 2010 06:31:27 -0700 (PDT) Subject: Plain simple unix timestamp with an HTTP GET References: <83cc363b-77f0-487d-901c-d15b275e43e5@y21g2000vba.googlegroups.com> Message-ID: <788d4c94-a462-4958-a2b0-cd2901eb1178@e5g2000yqn.googlegroups.com> On Jun 3, 11:20?pm, livibetter wrote: > This? > > hwclock --utc --set --date="$(datestr="$(curlhttp://208.66.175.36:13/ > 2>/dev/null | cut -d \ ?-f 2-3)" ; echo ${datestr//-//})" > > Only hwclock, curl, cut, and Bash. > > PS. I didn't know I can set the time via hwclock, learned from Paul's > post, but still didn't try to see if it does work. > > Thanks for the info. Yes, I like the port 13 stuff from NIST et al which is RFC 867 formatted, but on the hdwe the parsing is more work. Found a bit of port 37 RFC 868 stuff that sounds interesting. I am able to get a long int from it now I think (e.g. 64.236.96.53:37 in Virginia), though it seems to be a bit mangled, and doesn't work out to the number I'd expect for a 1900 epoch. Still, I think it's usable, and is just a single number. I hear NIST is gradually getting away from RFC868 stuff tho' which is too bad. Some of us don't need pS accuracy. +/- 5min is fine. Thx for the input! From lists at cheimes.de Fri Jun 4 09:32:15 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 04 Jun 2010 15:32:15 +0200 Subject: Missing DLL in win98 In-Reply-To: <1guh06tt177al7rqar55ab0aiif1ibim57@4ax.com> References: <0bsh06pilrfls0i3f473unhbee1j71pmbs@4ax.com> <1guh06tt177al7rqar55ab0aiif1ibim57@4ax.com> Message-ID: > So your response is either, you don't know if there is a fix, or 'No > way in h377.' You couldn't figure out by my post that I already knew > that? Let me paraphrase my answer: You can't run Python 2.6 on Windows 98 because we have dropped support for any Windows older than Windows 2000 SP4. It's documented at http://docs.python.org/whatsnew/2.6.html#port-specific-changes-windows , too. Christian From info at wingware.com Fri Jun 4 09:48:16 2010 From: info at wingware.com (Wingware) Date: Fri, 04 Jun 2010 09:48:16 -0400 Subject: Wing IDE 3.2.8 released: Adds Python 2.7 support Message-ID: <4C090420.6010406@wingware.com> Hi, Wingware has released version 3.2.8 of Wing IDE, an integrated development environment designed specifically for the Python programming language. This release includes the following minor features and improvements: * Support for Python 2.7 * Partially updated French localization of the GUI (thanks to Jean Sanchez) * Avoid hanging up the debugger in some Python code * Fixed VI mode copy/paste, p after yj and dj, and Ctrl-S to save * Correctly analyze 'with' statements and dictionary comprehensions * Fixed help() in the shells under Python 3.x * Reopen project after patch installation at startup * Several other minor bug fixes See the change log at http://wingware.com/pub/wingide/3.2.8/CHANGELOG.txt for details *Downloads* Wing IDE Professional and Wing IDE Personal are commercial software and require a license to run. A free trial license can be obtained directly from the product when launched. Wing IDE 101 can be used free of charge. Wing IDE Pro 3.2.8 http://wingware.com/downloads/wingide/3.2 Wing IDE Personal 3.2.8 http://wingware.com/downloads/wingide-personal/3.2 Wing IDE 101 3.2.8 http://wingware.com/downloads/wingide-101/3.2 *About Wing IDE* Wing IDE is an integrated development environment designed specifically for the Python programming language. It provides powerful editing, testing, and debugging features that help reduce development and debugging time, cut down on coding errors, and make it easier to understand and navigate Python code. Wing IDE can be used to develop Python code for web, GUI, and embedded scripting applications. Wing IDE is available in three product levels: Wing IDE Professional is the full-featured Python IDE, Wing IDE Personal offers a reduced feature set at a low price, and Wing IDE 101 is a free simplified version designed for teaching entry level programming courses with Python. Version 3.2 of Wing IDE Professional includes the following major features: * Professional quality code editor with vi, emacs, and other keyboard personalities * Code intelligence for Python: Auto-completion, call tips, goto-definition, error indicators, smart indent and rewrapping, and source navigation * Advanced multi-threaded debugger with graphical UI, command line interaction, conditional breakpoints, data value tooltips over code, watch tool, and externally launched and remote debugging * Powerful search and replace options including keyboard driven and graphical UIs, multi-file, wild card, and regular expression search and replace * Version control integration for Subversion, CVS, Bazaar, git, Mercurial, and Perforce * Integrated unit testing with unittest, nose, and doctest frameworks * Many other features including project manager, bookmarks, code snippets, OS command integration, indentation manager, PyLint integration, and perspectives * Extremely configurable and may be extended with Python scripts Please refer to the feature list at http://wingware.com/wingide/features for a detailed listing of features by product level. System requirements are Windows 2000 or later, OS X 10.3.9 or later for PPC or Intel (requires X11 Server), or a recent Linux system (either 32 or 64 bit). Wing IDE supports Python versions 2.0.x through 3.1.x and Stackless Python. For more information, see http://wingware.com/products *Purchasing and Upgrading* Wing 3.2 is a free upgrade for all Wing IDE 3.0 and 3.1 users. Version 2.x licenses cost 1/2 the normal price to upgrade. Upgrade a 2.x license: https://wingware.com/store/upgrade Purchase a 3.x license: https://wingware.com/store/purchase -- The Wingware Team Wingware | Python IDE Advancing Software Development www.wingware.com From spyder1960 at yahoo.com Fri Jun 4 09:53:31 2010 From: spyder1960 at yahoo.com (Spyder42) Date: Fri, 04 Jun 2010 05:53:31 -0800 Subject: Missing DLL in win98 References: <0bsh06pilrfls0i3f473unhbee1j71pmbs@4ax.com> <1guh06tt177al7rqar55ab0aiif1ibim57@4ax.com> Message-ID: <851i06p0orm214j35cmt9pkraq7m172mf4@4ax.com> On Fri, 04 Jun 2010 15:32:15 +0200, Christian Heimes wrote: >> So your response is either, you don't know if there is a fix, or 'No >> way in h377.' You couldn't figure out by my post that I already knew >> that? > >Let me paraphrase my answer: > >You can't run Python 2.6 on Windows 98 because we have dropped support >for any Windows older than Windows 2000 SP4. It's documented at >http://docs.python.org/whatsnew/2.6.html#port-specific-changes-windows , >too. > >Christian Yes, I get that. So your answer is... You have no idea as to weather there is a workaround, or a fix, or patch or anything that would help. right? I don't consider buying an OS to be a valid workaround. Thanks Spyder From jf_byrnes at comcast.net Fri Jun 4 09:56:34 2010 From: jf_byrnes at comcast.net (Jim Byrnes) Date: Fri, 04 Jun 2010 08:56:34 -0500 Subject: Python Forum In-Reply-To: <4c089852$0$28659$c3e8da3@news.astraweb.com> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <1275560120.8775.6.camel@linux-yu4c.site> <4c0886f5$0$28659$c3e8da3@news.astraweb.com> <4c089852$0$28659$c3e8da3@news.astraweb.com> Message-ID: <4C090612.4090506@comcast.net> Steven D'Aprano wrote: > On Thu, 03 Jun 2010 22:05:19 -0700, Phlip wrote: > >> On Jun 3, 9:54 pm, Steven D'Aprano> cybersource.com.au> wrote: >> >>> I don't know what rubbish ISPs you're dealing with >> >> You've heard of a little fly-by-night outfit called AT&T? > > Yes I have. Aren't they the people who were engaged in a long-running > criminal conspiracy to break the law and commit illegal warrantless > surveillance of American citizens? > > If you look at the reviews here: > > http://www.dslreports.com/gbu/ > > they are a distinct second-class ISP, with average B scores. Perhaps > that's better than "rubbish", but it's nothing to be proud about when you > are a company the size of AT&T. When you have that many resources, > anything less than straight A+ is a failure. > > And that's not even mentioning their lack of News access, their ham- > fisted and clueless blocking of 4chan (whether in legitimate self-defence > or not), or their stance on net neutrality. > > But the really sad thing is that you think that "bigger" automatically > equals "better". > > > I thought his point was they are big enough to have the resources to offer newsgroups but don't. If I want fast internet I must use Comcast and Comcast doesn't offer newsgroups either. Sadly is seems getting access to newsgroups is getting harder and harder. I much prefer newsgroups or email lists to web forums. Regards, Jim From pruebauno at latinmail.com Fri Jun 4 10:45:20 2010 From: pruebauno at latinmail.com (nn) Date: Fri, 4 Jun 2010 07:45:20 -0700 (PDT) Subject: Missing DLL in win98 References: <0bsh06pilrfls0i3f473unhbee1j71pmbs@4ax.com> <1guh06tt177al7rqar55ab0aiif1ibim57@4ax.com> <851i06p0orm214j35cmt9pkraq7m172mf4@4ax.com> Message-ID: On Jun 4, 9:53?am, Spyder42 wrote: > On Fri, 04 Jun 2010 15:32:15 +0200, Christian Heimes > > wrote: > >> So your response is either, you don't know if there is a fix, or 'No > >> way in h377.' You couldn't figure out by my post that I already knew > >> that? > > >Let me paraphrase my answer: > > >You can't run Python 2.6 on Windows 98 because we have dropped support > >for any Windows older than Windows 2000 SP4. It's documented at > >http://docs.python.org/whatsnew/2.6.html#port-specific-changes-windows, > >too. > > >Christian > > Yes, I get that. So your answer is... You have no idea as to weather > there is a workaround, or a fix, or patch or anything that would help. > right? I don't consider buying an OS to be a valid workaround. > > ? ? ? ? Thanks > ? ? ? ? Spyder Correct. If you use Windows 98, you are stuck at the 2.5 series of Python. As far as I know (Christian might correct me) there is no fix or patch to allow otherwise. The usual volunteers that build the Windows version of Python don't care about the extra work of maintaining Windows 98 support anymore and nobody else has stepped forward to do it or to pay somebody to do so. From cwood1967 at gmail.com Fri Jun 4 10:51:50 2010 From: cwood1967 at gmail.com (Chris W) Date: Fri, 4 Jun 2010 07:51:50 -0700 (PDT) Subject: Missing DLL in win98 References: <0bsh06pilrfls0i3f473unhbee1j71pmbs@4ax.com> <1guh06tt177al7rqar55ab0aiif1ibim57@4ax.com> <851i06p0orm214j35cmt9pkraq7m172mf4@4ax.com> Message-ID: <350a2cea-4078-4a58-8935-75727c610447@x27g2000yqb.googlegroups.com> On Jun 4, 8:53?am, Spyder42 wrote: > On Fri, 04 Jun 2010 15:32:15 +0200, Christian Heimes > > wrote: > >> So your response is either, you don't know if there is a fix, or 'No > >> way in h377.' You couldn't figure out by my post that I already knew > >> that? > > >Let me paraphrase my answer: > > >You can't run Python 2.6 on Windows 98 because we have dropped support > >for any Windows older than Windows 2000 SP4. It's documented at > >http://docs.python.org/whatsnew/2.6.html#port-specific-changes-windows, > >too. > > >Christian > > Yes, I get that. So your answer is... You have no idea as to weather > there is a workaround, or a fix, or patch or anything that would help. > right? I don't consider buying an OS to be a valid workaround. > > ? ? ? ? Thanks > ? ? ? ? Spyder Then the workaround is to use an older version of Python, or use a modern version of a free OS. From python at mrabarnett.plus.com Fri Jun 4 10:52:54 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 04 Jun 2010 15:52:54 +0100 Subject: threading and atexit: different behaviour in python2.6 from 2.5 In-Reply-To: References: Message-ID: <4C091346.7010701@mrabarnett.plus.com> Alan wrote: > Hi there, > > That's another try to get help about this issue I am facing. To help you > to help me here goes a simple example. This is a very simplification of > a very complex code. > > -------------------- thread_ping.py -------------------- begin > import time > import sys > import atexit > from threading import Thread > > class testit(Thread): > def __init__ (self,ip): > Thread.__init__(self) > self.ip = ip > self.status = 0 > def run(self): > pingaling = os.popen("ping -q -c2 "+self.ip,"r") > while 1: > line = pingaling.readline() > if not line: break > igot = re.findall(testit.lifeline,line) > if igot: > self.status = int(igot[0]) > > def goodbye(t, report): > print 'Goodbye' > print "Status from ",t.ip,"is",report[t.status] > > testit.lifeline = re.compile(r"(\d) packets received") > report = ("No response","Partial Response","Alive") > > ip = "209.85.227.104" # www.google.com # try > with a failing IP if you want the test to last a bit longer > > t = testit(ip) > > atexit.register(goodbye, t, report) > > t.start() > > exit() > -------------------- thread_ping.py -------------------- end > > If one runs like: > > amadeus[2579]:~/TMP% time python2.6 thread_ping.py > Goodbye > Status from 209.85.227.104 is Alive > python2.6 thread_ping.py 0.02s user 0.02s system 3% cpu 1.056 total > > (i.e., python2.6 wait till the thread finishes and leave... I don't want > this behaviour, see below) > > and > > amadeus[2580]:~/TMP% time python2.5 thread_ping.py > Goodbye > Status from 209.85.227.104 is No response > python2.5 thread_ping.py 0.01s user 0.01s system 90% cpu 0.030 total > > (i.e., python2.5 promptly quit, as desired) > > Could someone tell me how to get python2.6 to have the same behaviour I > see with python2.5 for this example code? > > Any hint would be very much appreciated indeed. > > Many thanks in advance. > The script won't exit while there are non-daemon threads running. You can make a thread a daemon by setting its 'daemon' attribute to True before starting the thread. If you want the script to be backwards compatible with Python 2.5 then use the 'setDaemon' method instead. I don't know why the script exited in Python 2.5 even though a non-daemon thread was still running. From fordhaivat at gmail.com Fri Jun 4 11:21:56 2010 From: fordhaivat at gmail.com (Someone Something) Date: Fri, 4 Jun 2010 11:21:56 -0400 Subject: parse xml with invalid chars In-Reply-To: <20100604141600.GA14055@localhost.localdomain> References: <20100604141600.GA14055@localhost.localdomain> Message-ID: What d'ya mean hang? On Fri, Jun 4, 2010 at 10:16 AM, Roman Makurin wrote: > Hi all > > Last time i have a big problem, i need parse xml files > which have invalid xml chars outside of CDATA and xml > parser hangs everytime on such files. Is there any way > to parse such files ??? > > thanks > > -- > If you think of MS-DOS as mono, and Windows as stereo, > then Linux is Dolby Digital and all the music is free... > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kirby.urner at gmail.com Fri Jun 4 11:27:17 2010 From: kirby.urner at gmail.com (kirby.urner at gmail.com) Date: Fri, 4 Jun 2010 08:27:17 -0700 (PDT) Subject: weird pickle behavior in Python 3.1.2 + Eclipse 3.5.2 Message-ID: <7184874c-ea70-49e7-bd2c-e519cd0ff2bf@e34g2000pra.googlegroups.com> Here we are in an Eclipse pydev console, running Python 3.1.2. For the most part, everything is working great. However... >>> import sys; print('%s %s' % (sys.executable or sys.platform, sys.version)) C:\Python31\python.exe 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] >>> import pickle >>> class Example: ... def __init__(self): ... self.name = "Hello" ... def __repr__(self): ... return "an Example object named {}".format(self.name) ... ... >>> obj = Example() >>> obj an Example object named Hello Note that I'm opening in binary, like I'm supposed to with this latest protocol: >>> f = open("testpickle.pkl",'wb') Should be able to do this, no problemo: >>> pickle.dump(obj, f) Traceback (most recent call last): File "", line 1, in File "C:\Python31\lib\pickle.py", line 1354, in dump Pickler(file, protocol, fix_imports=fix_imports).dump(obj) _pickle.PicklingError: Can't pickle : attribute lookup builtins.Example failed The above works fine in "naked Python" 3.1.2 by the way. So this could be a problem with Eclipse / Pydev and/or user error. What am I missing? Just normal data structures work: >>> test = [1,2,3] >>> pickle.dump(test,f) >>> f.close() >>> Any other Eclipse users out there who can at least duplicate this weirdness? Kirby Urner in Portland "Keep Portland Weird" Oregon From torriem at gmail.com Fri Jun 4 11:46:36 2010 From: torriem at gmail.com (Michael Torrie) Date: Fri, 04 Jun 2010 09:46:36 -0600 Subject: Python Forum In-Reply-To: <1275560120.8775.6.camel@linux-yu4c.site> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <1275560120.8775.6.camel@linux-yu4c.site> Message-ID: <4C091FDC.9070203@gmail.com> On 06/03/2010 04:15 AM, Adam Tauno Williams wrote: > The best solution I've seen is what is used by the Mono project; > which provides both a "web forum" and a mail list interface. > > > I just checked the archives of mono-list vs the forum and it's apparent that this scheme suffers from the same problem as every other forum solution. The threaded flow of discussion is lost, replaced by a flat, chronological "conversation." Even though the list archive suggests there is still a tree structure to posts, when you check into it you find that it is not a tree at all. Every message to the forum is taken to be a reply to the one before, even though it might not be. The archive web interface simply abandons nesting at 4 levels or so. From robert.kern at gmail.com Fri Jun 4 11:49:14 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 04 Jun 2010 11:49:14 -0400 Subject: How to generate execute file that include enthought.traits.api , enthought.traits.ui.api ? In-Reply-To: <57d9c5c4-c512-4619-ac10-c381cc13d0f1@k17g2000pro.googlegroups.com> References: <57d9c5c4-c512-4619-ac10-c381cc13d0f1@k17g2000pro.googlegroups.com> Message-ID: On 6/3/10 10:05 PM, ray wrote: > Hi all, > I code the program that using enthought.traits.api , > enthought.traits.ui.api. > I want to genereate execute file.I try PY2EXE,bb- > freeze,cx_freeze,Pyinstaller ,but the execute files can not run > successful. > The attach file is my source code. > My environment : > 1.Python 2.6.2 > 2. OS platform is MS Windows XP. > > Anybody can share the experience ? Our GUI components use some dynamic imports to provide the backend implementations. Most of those tools require you to explicitly state some of those backend-specific subpackages since they cannot introspect them directly from the import statements. Specifically, enthought.traits.ui.wx and enthought.pyface.ui.wx (replace "wx" with "qt4" if you are using PyQt). The way you do this is different for each tool; you will have to consult its documentation. You will want to ask future questions about ETS on our mailing list: https://mail.enthought.com/mailman/listinfo/enthought-dev -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From bryanjugglercryptographer at yahoo.com Fri Jun 4 12:06:09 2010 From: bryanjugglercryptographer at yahoo.com (Bryan) Date: Fri, 4 Jun 2010 09:06:09 -0700 (PDT) Subject: getting MemoryError with dicts; suspect memory fragmentation References: <1d1b48dd-3316-4a72-a8a0-e56d307e5ec7@n37g2000prc.googlegroups.com> Message-ID: <0878bb10-c3ff-4d48-85f7-cbcdbe696daf@z13g2000prh.googlegroups.com> Emin.shopper wrote: > dmtr wrote: > > I'm still unconvinced that it is a memory fragmentation problem. It's > > very rare. > > You could be right. I'm not an expert on python memory management. But > if it isn't memory fragmentation, then why is it that I can create > lists which use up 600 more MB but if I try to create a dict that uses > a couple more MB it dies? My guess is that python dicts want a > contiguous chunk of memory for their hash table. Is there a reason > that you think memroy fragmentation isn't the problem? Your logic makes some sense. You wrote that you can create a dict with 1300 items, but not 1400 items. If my reading of the Python source is correct, the dict type decides it's overloaded when 2/3 full, and enlarges by powers of two, so the 1366'th item will trigger allocation of an array of 4096 PyDictEntry's. http://svn.python.org/view/python/branches/release25-maint/Objects/dictnotes.txt?view=markup http://svn.python.org/view/python/branches/release25-maint/Objects/dictobject.c?view=markup On the other hand PyDictEntry is 12 bytes (on 32-bit Python), so the memory chunk needed is just 48 K. It doesn't seem plausible that you have have hundreds of megabytes available but can't allocate 48K in one chunk. Plus, unless I'm misreading the code, a Python list also uses one contiguous chunk of memory to store all the item references. I'm looking at PyList_New() and list_resize() in: http://svn.python.org/view/python/branches/release25-maint/Objects/listobject.c?view=markup and the memory allocators in: http://svn.python.org/view/python/branches/release25-maint/Include/pymem.h?view=markup > What else could it be? Unfortunately several things, most of them hard to diagnose. I'd suggest checking easy stuff first. Make sure 'dict' is still . If you can test again in the debugger in the error case, see how large a set you can make, as the set implementation is similar to dict except the hash table entries are one pointer shorter at 8 bytes. -- --Bryan Olson From philip at semanchuk.com Fri Jun 4 12:21:35 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 4 Jun 2010 12:21:35 -0400 Subject: getting MemoryError with dicts; suspect memory fragmentation In-Reply-To: <0878bb10-c3ff-4d48-85f7-cbcdbe696daf@z13g2000prh.googlegroups.com> References: <1d1b48dd-3316-4a72-a8a0-e56d307e5ec7@n37g2000prc.googlegroups.com> <0878bb10-c3ff-4d48-85f7-cbcdbe696daf@z13g2000prh.googlegroups.com> Message-ID: <274DBF4D-4571-43F3-9CED-4CFD772F5B7F@semanchuk.com> On Jun 4, 2010, at 12:06 PM, Bryan wrote: > Emin.shopper wrote: >> dmtr wrote: >>> I'm still unconvinced that it is a memory fragmentation problem. >>> It's >>> very rare. >> >> You could be right. I'm not an expert on python memory management. >> But >> if it isn't memory fragmentation, then why is it that I can create >> lists which use up 600 more MB but if I try to create a dict that >> uses >> a couple more MB it dies? My guess is that python dicts want a >> contiguous chunk of memory for their hash table. Is there a reason >> that you think memroy fragmentation isn't the problem? > > Your logic makes some sense. You wrote that you can create a dict with > 1300 items, but not 1400 items. If my reading of the Python source is > correct, the dict type decides it's overloaded when 2/3 full, and > enlarges by powers of two, so the 1366'th item will trigger allocation > of an array of 4096 PyDictEntry's. At PyCon 2010, Brandon Craig Rhodes presented about how dictionaries work under the hood: http://python.mirocommunity.org/video/1591/pycon-2010-the-mighty-dictiona I found that very informative. There's also some slides if you don't like the video; I haven't looked at 'em myself. http://us.pycon.org/2010/conference/schedule/event/12/ Cheers Philip From emile at fenx.com Fri Jun 4 12:28:23 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 04 Jun 2010 09:28:23 -0700 Subject: Python Forum In-Reply-To: <4c0891fc$0$28659$c3e8da3@news.astraweb.com> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <4c0891fc$0$28659$c3e8da3@news.astraweb.com> Message-ID: On 6/3/2010 10:41 PM Steven D'Aprano said... > On Thu, 03 Jun 2010 06:15:20 -0400, Adam Tauno Williams wrote: >> Most people use this list via e-mail, > > How do you know? Do you have evidence for this, or are you just making it > up? > Is there now a non-email method of posting to this list? Emile From __peter__ at web.de Fri Jun 4 12:47:47 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 04 Jun 2010 18:47:47 +0200 Subject: weird pickle behavior in Python 3.1.2 + Eclipse 3.5.2 References: <7184874c-ea70-49e7-bd2c-e519cd0ff2bf@e34g2000pra.googlegroups.com> Message-ID: kirby.urner at gmail.com wrote: > Here we are in an Eclipse pydev console, running Python 3.1.2. For > the most part, everything is working great. > > However... > >>>> import sys; print('%s %s' % (sys.executable or sys.platform, >>>> sys.version)) > C:\Python31\python.exe 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC > v.1500 32 bit (Intel)] > >>>> import pickle >>>> class Example: > ... def __init__(self): > ... self.name = "Hello" > ... def __repr__(self): > ... return "an Example object named {}".format(self.name) > ... > ... >>>> obj = Example() >>>> obj > an Example object named Hello > > Note that I'm opening in binary, like I'm supposed to with this > latest protocol: > >>>> f = open("testpickle.pkl",'wb') > > Should be able to do this, no problemo: > >>>> pickle.dump(obj, f) > Traceback (most recent call last): > File "", line 1, in > File "C:\Python31\lib\pickle.py", line 1354, in dump > Pickler(file, protocol, fix_imports=fix_imports).dump(obj) > _pickle.PicklingError: Can't pickle : attribute > lookup builtins.Example failed > > The above works fine in "naked Python" 3.1.2 by the way. > So this could be a problem with Eclipse / Pydev and/or > user error. What am I missing? > > Just normal data structures work: > >>>> test = [1,2,3] >>>> pickle.dump(test,f) >>>> f.close() >>>> > > Any other Eclipse users out there who can at least duplicate this > weirdness? I can provoke the error in "naked" Python 3 by changing the Example.__module__ attribute: Python 3.1.1+ (r311:74480, Nov 2 2009, 15:45:00) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import pickle >>> class Example: ... pass ... >>> pickle.dumps(Example()) b'\x80\x03c__main__\nExample\nq\x00)\x81q\x01}q\x02b.' >>> Example.__module__ = "builtins" >>> pickle.dumps(Example()) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.1/pickle.py", line 1358, in dumps Pickler(f, protocol, fix_imports=fix_imports).dump(obj) _pickle.PicklingError: Can't pickle : attribute lookup builtins.Example failed What's the value of __module__ when you run your code in Eclipse? Peter From brfredericks at gmail.com Fri Jun 4 12:54:11 2010 From: brfredericks at gmail.com (bfrederi) Date: Fri, 4 Jun 2010 09:54:11 -0700 (PDT) Subject: Issue with xml iterparse References: <9c6bfe72-fae0-4cba-94b2-8687f33e3780@5g2000yqz.googlegroups.com> Message-ID: On Jun 3, 4:13?pm, bfrederi wrote: > On Jun 3, 3:59?pm, Chris Rebert wrote: > > > > > On Thu, Jun 3, 2010 at 1:44 PM, bfrederi wrote: > > > I am using lxml iterparse and running into a very obscure error. When > > > I run iterparse on a file, it will occasionally return an element that > > > has a element.text == None when the element clearly has text in it. > > > > I copy and pasted the problem xml into a python string, used StringIO > > > to create a file-like object out of it, and ran a test using iterparse > > > with expected output, and it ran perfectly fine. So it only happens > > > when I try to run iterparse on the actual file. > > > > So then I tried opening the file, reading the data, turning that data > > > into a file-like object using StringIO, then running iterparse on it, > > > and the same problem (element.text == None) occurred. > > > > I even tried this: > > > f = codecs.open(abbyy_filename, 'r', encoding='utf-8') > > > file_data = f.read() > > > file_like_object = StringIO.StringIO(file_data) > > > for event, element in iterparse(file_like_object, events=("start", > > > "end")): > > > IIRC, XML parsers operate on bytes directly (since they have to > > determine the encoding themselves anyway), not pre-decoded Unicode > > characters, so I think your manual UTF-8 decoding could be the > > problem. > > Have you tried simply: > > > f = open(abbyy_filename, 'r') > > for event, element in iterparse(f, events=("start", "end")): > > ? ? #whatever > > > ? > > > Apologies if you already have, but since you didn't include the > > original, albeit probably trivial, error-causing code, this relatively > > simple error couldn't be ruled out. > > > Cheers, > > Chris > > --http://blog.rebertia.com > > Sorry for not mentioning it, but I tried that as well and it failed. > Here is the relevant class. AbbyyLine and Abbyyword just take the > element's text and writes it to a file/file-like object. parse_doc is > where I use iterparse. The relevant part is very minimal and there is > a lot of fluff to ignore, so I didn't initially post it: > > class AbbyyDocParse(object): > > ? ? """Takes an abbyy filename and parses the contents""" > ? ? def __init__(self, abbyy_filename, extension=DEFAULT_ABBYY_EXT, > ? ? ? ? format_list=OUTPUT_TYPES, string_only=False): > ? ? ? ? self.extension = extension > ? ? ? ? self.format_list = format_list > ? ? ? ? #Create the file handles for the output files > ? ? ? ? self.create_filehandles(abbyy_filename, string_only) > ? ? ? ? #Parse the document > ? ? ? ? self.parse_doc(abbyy_filename) > ? ? ? ? #Close the output filehandles > ? ? ? ? self.close_filehandles(abbyy_filename, string_only) > > ? ? def create_filehandles(self, abbyy_filename, string_only): > ? ? ? ? """Create output filehandles""" > ? ? ? ? #if output goes to a file > ? ? ? ? if not string_only: > ? ? ? ? ? ? #Make sure the file is an abbyy file > ? ? ? ? ? ? if not abbyy_filename.endswith(self.extension): > ? ? ? ? ? ? ? ? raise ParserException, "Bad abbyy filename given: %s" > \ > ? ? ? ? ? ? ? ? ? ? % (abbyy_filename) > ? ? ? ? ? ? #get the base path and filename for output files > ? ? ? ? ? ? filename = abbyy_filename.replace(self.extension, '') > ? ? ? ? #Loop through the different formats > ? ? ? ? for format_type in self.format_list: > ? ? ? ? ? ? #if output goes to a file > ? ? ? ? ? ? if not string_only: > ? ? ? ? ? ? ? ? #Create output filename > ? ? ? ? ? ? ? ? out_file = "%s%s" % (filename, > OUTPUT_EXTENSIONS.get(format_type)) > ? ? ? ? ? ? ? ? #Opens the format type filehandle > ? ? ? ? ? ? ? ? try: > ? ? ? ? ? ? ? ? ? ? setattr(self, "%s_handle" % (format_type), > open(out_file,'w')) > ? ? ? ? ? ? ? ? except: > ? ? ? ? ? ? ? ? ? ? raise IOError, "Could not open file: %s" % > (out_file) > ? ? ? ? ? ? #if output goes to a string > ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? #Opens the format type StringIO > ? ? ? ? ? ? ? ? try: > ? ? ? ? ? ? ? ? ? ? setattr(self, "%s_handle" % (format_type), > StringIO.StringIO()) > ? ? ? ? ? ? ? ? except: > ? ? ? ? ? ? ? ? ? ? raise IOError, "Could not open string output: %s" > % (out_file) > > ? ? def parse_doc(self, abbyy_filename): > ? ? ? ? """Parses the abbyy document""" > ? ? ? ? #Write the first line of the xml doc, if specified > ? ? ? ? if getattr(self, 'xml_handle', None): > ? ? ? ? ? ? self.xml_handle.write(' encoding="utf-8"?>\n') > ? ? ? ? #Memory efficient iterparse opens file and loops through > content > ? ? ? ? for event, element in iterparse(abbyy_filename, > events=("start", "end")): > ? ? ? ? ? ? #ignore the namespace, if it has one > ? ? ? ? ? ? if NAMESPACE_REGEX.search(element.tag, 0): > ? ? ? ? ? ? ? ? element_tag = NAMESPACE_REGEX.search(element.tag, > 0).group(1) > ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? element_tag = element.tag > ? ? ? ? ? ? #if this is the page element > ? ? ? ? ? ? if element_tag == 'page': > ? ? ? ? ? ? ? ? self.write_page(event, element) > ? ? ? ? ? ? #If at the beginning of the line > ? ? ? ? ? ? elif element_tag == 'line' and event == 'start': > ? ? ? ? ? ? ? ? #Create the line > ? ? ? ? ? ? ? ? line = AbbyyLine(element) > ? ? ? ? ? ? ? ? #Instantiate first word > ? ? ? ? ? ? ? ? word = AbbyyWord(line) > ? ? ? ? ? ? #If at the end of the line, and an output text file exists > ? ? ? ? ? ? if element_tag == 'line' and event == 'end' and \ > ? ? ? ? ? ? ? ? getattr(self, 'text_handle', None): > ? ? ? ? ? ? ? ? #output line data to text file > ? ? ? ? ? ? ? ? line.write_line(self.text_handle) > ? ? ? ? ? ? #If at the end of the line, and an output text file exists > ? ? ? ? ? ? if element_tag == 'line' and event == 'end' and \ > ? ? ? ? ? ? ? ? getattr(self, 'xml_handle', None): > ? ? ? ? ? ? ? ? #output line data to text file > ? ? ? ? ? ? ? ? word.write_word(self.xml_handle) > ? ? ? ? ? ? #if outputting to an xml file, create word data > ? ? ? ? ? ? if getattr(self, 'xml_handle', None) and \ > ? ? ? ? ? ? ? ? element_tag == 'charParams' and event == 'start': > ? ? ? ? ? ? ? ? #Insert character into word > ? ? ? ? ? ? ? ? word.insert_char(element, self.xml_handle) > ? ? ? ? ? ? #if outputting to a text file, create line data > ? ? ? ? ? ? if getattr(self, 'text_handle', None) and \ > ? ? ? ? ? ? ? ? element_tag == 'charParams' and event == 'start': > ? ? ? ? ? ? ? ? #Insert character into line > ? ? ? ? ? ? ? ? line.insert_char(element) > > ? ? def write_page(self, event, element): > ? ? ? ? """Parse the page contents""" > ? ? ? ? #page open tag event > ? ? ? ? if event == 'start': > ? ? ? ? ? ? #Write page info to xml file > ? ? ? ? ? ? if getattr(self, 'xml_handle', None): > ? ? ? ? ? ? ? ? #Get the page info > ? ? ? ? ? ? ? ? x_dim = element.get('width') > ? ? ? ? ? ? ? ? y_dim = element.get('height') > ? ? ? ? ? ? ? ? resolution = element.get('resolution') > ? ? ? ? ? ? ? ? #Write the page info to the file > ? ? ? ? ? ? ? ? self.xml_handle.write('\n') > ? ? ? ? ? ? ? ? self.xml_handle.write('\n') > ? ? ? ? ? ? ? ? self.xml_handle.write('\n') > ? ? ? ? ? ? ? ? self.xml_handle.write("%s\n" % (x_dim)) > ? ? ? ? ? ? ? ? self.xml_handle.write("%s\n" % (y_dim)) > ? ? ? ? ? ? ? ? self.xml_handle.write("%s\n" > % (resolution)) > ? ? ? ? ? ? ? ? self.xml_handle.write('\n') > ? ? ? ? ? ? ? ? self.xml_handle.write('\n') > ? ? ? ? #page close tag event > ? ? ? ? elif event == 'end': > ? ? ? ? ? ? #Write page info to xml file > ? ? ? ? ? ? if getattr(self, 'xml_handle', None): > ? ? ? ? ? ? ? ? #Write closing tags to file > ? ? ? ? ? ? ? ? self.xml_handle.write('\n') > ? ? ? ? ? ? ? ? self.xml_handle.write('') > > ? ? def write_line(self, event, element): > ? ? ? ? """Parse the line contents""" > ? ? ? ? #line open tag event > ? ? ? ? if event == 'start': > ? ? ? ? ? ? pass > ? ? ? ? #page close tag event > ? ? ? ? elif event == 'end': > ? ? ? ? ? ? pass > > ? ? def write_word(self, event, element): > ? ? ? ? """Parse the charParams contents""" > ? ? ? ? pass > > ? ? def close_filehandles(self, abbyy_filename, string_only): > ? ? ? ? """Close the open filehandles""" > ? ? ? ? #if the files exist > ? ? ? ? if not string_only: > ? ? ? ? ? ? #Loop through the different formats > ? ? ? ? ? ? for format_type in self.format_list: > ? ? ? ? ? ? ? ? #Opens the format type filehandle > ? ? ? ? ? ? ? ? try: > ? ? ? ? ? ? ? ? ? ? getattr(self, "%s_handle" % (format_type)).close() > ? ? ? ? ? ? ? ? except: > ? ? ? ? ? ? ? ? ? ? raise IOError, "Could not close format type: %s > for file: %s" \ > ? ? ? ? ? ? ? ? ? ? ? ? % (format_type, abbyy_filename) I think this is a bug with iterparse. I switched to using regular parse for the parse_doc function, and it worked just fine: def parse_doc(self, abbyy_filename): """Parses the abbyy document""" #Write the first line of the xml doc, if specified if getattr(self, 'xml_handle', None): self.xml_handle.write(' \n') #Try to open the abbyy file try: f = open(abbyy_filename, "r") #abbyy_filename is already and instance of a file-like object except: #parse the abbyy file tree = parse(abbyy_filename) #parse the open abbyyfile else: tree = parse(f) f.close() root = tree.getroot() line = None for element in root.iter("*"): #ignore the namespace, if it has one if NAMESPACE_REGEX.search(element.tag, 0): element_tag = NAMESPACE_REGEX.search(element.tag, 0).group(1) else: element_tag = element.tag #if this is the page element if element_tag == 'page': self.write_page('start', element) #If at the beginning of the new line elif element_tag == 'line': #if a line already existed, and there is an output text file if line != None: if getattr(self, 'text_handle', None): #output line data to text file line.write_line(self.text_handle) elif getattr(self, 'xml_handle', None): #output line data to xml file word.write_word(self.xml_handle) #Create the line line = AbbyyLine(element) #Instantiate first word word = AbbyyWord(line) #if outputting to an xml file, create word data if getattr(self, 'xml_handle', None) and element_tag == 'charParams': #Insert character into word word.insert_char(element, self.xml_handle) #if outputting to a text file, create line data if getattr(self, 'text_handle', None) and element_tag == 'charParams': #Insert character into line line.insert_char(element) #if a line already existed, and there is an output text file if line != None: if getattr(self, 'text_handle', None): #output line data to text file line.write_line(self.text_handle) elif getattr(self, 'xml_handle', None): #output line data to xml file word.write_word(self.xml_handle) self.write_page('end', element) From uriaheisenstein at gmail.com Fri Jun 4 13:22:44 2010 From: uriaheisenstein at gmail.com (Uriah Eisenstein) Date: Fri, 4 Jun 2010 19:22:44 +0200 Subject: General questions - where & how Message-ID: Hi all, I'm relatively new to Python and have a few questions. Frankly, it took me a while to find on python.org what seems like a suitable place to post my questions. However, I'd like to check the archives and see if they haven't been discussed already... But I don't find a Search function. Is there such a thing? TIA, Uriah -------------- next part -------------- An HTML attachment was scrubbed... URL: From wolfgang.lipp at gmail.com Fri Jun 4 13:31:00 2010 From: wolfgang.lipp at gmail.com (_wolf) Date: Fri, 4 Jun 2010 10:31:00 -0700 (PDT) Subject: strange syntax error Message-ID: this may not be an earth-shattering deficiency of python, but i still wonder about the rationale behind the following behavior: when i run :: source = """ print( 'helo' ) if __name__ == '__main__': print( 'yeah!' ) #""" print( compile( source, '', 'exec' ) ) i get :: File "", line 6 # ^ SyntaxError: invalid syntax i can avoid this exception by (1) deleting the trailing ``#``; (2) deleting or outcommenting the ``if __name__ == '__main__':\n print( 'yeah!' )`` lines; (3) add a newline to very end of the source. moreover, if i have the source end without a trailing newline right behind the ``print( 'yeah!' )``, the source will also compile without error. i could also reproduce this behavior with python 2.6, so it?s not new to the 3k series. i find this error to be highly irritating, all the more since when i put above source inside a file and execute it directly or have it imported, no error will occur?which is the expected behavior. a ``#`` (hash) outside a string literal should always represent the start of a (possibly empty) comment in a python source; moreover, the presence or absence of a ``if __name__ == '__main__'`` clause should not change the interpretation of a soure on a syntactical level. can anyone reproduce the above problem, and/or comment on the phenomenon? cheers From mehgcap at gmail.com Fri Jun 4 13:31:41 2010 From: mehgcap at gmail.com (Alex Hall) Date: Fri, 4 Jun 2010 13:31:41 -0400 Subject: General questions - where & how In-Reply-To: References: Message-ID: I am not sure about a search feature for the archives, but I can tell you about a "tutor" list for those new and somewhat new to Python (like me). Of course, both that list and this one are excellent resources, but the tutor list seems to be for questions generally encountered by relatively new Python programmers. Just FYI. On 6/4/10, Uriah Eisenstein wrote: > Hi all, > I'm relatively new to Python and have a few questions. Frankly, it took me a > while to find on python.org what seems like a suitable place to post my > questions. However, I'd like to check the archives and see if they haven't > been discussed already... But I don't find a Search function. Is there such > a thing? > > TIA, > Uriah > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From philip at semanchuk.com Fri Jun 4 13:35:39 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 4 Jun 2010 13:35:39 -0400 Subject: General questions - where & how In-Reply-To: References: Message-ID: <67A48378-C1B3-4C1B-9D46-CE1842774186@semanchuk.com> On Jun 4, 2010, at 1:22 PM, Uriah Eisenstein wrote: > Hi all, > I'm relatively new to Python and have a few questions. Frankly, it > took me a > while to find on python.org what seems like a suitable place to post > my > questions. However, I'd like to check the archives and see if they > haven't > been discussed already... Good thinking! > But I don't find a Search function. Is there such > a thing? I use Google's "site" keyword search. e.g. to search the archives for "banana": http://www.google.com/search?q=site%3Amail.python.org%2Fpipermail%2Fpython-list%2F++banana Enjoy P From kirby.urner at gmail.com Fri Jun 4 13:43:08 2010 From: kirby.urner at gmail.com (kirby.urner at gmail.com) Date: Fri, 4 Jun 2010 10:43:08 -0700 (PDT) Subject: weird pickle behavior in Python 3.1.2 + Eclipse 3.5.2 References: <7184874c-ea70-49e7-bd2c-e519cd0ff2bf@e34g2000pra.googlegroups.com> Message-ID: <37dc25c6-97ac-4e74-a26e-b68a0e1c0c32@42g2000prb.googlegroups.com> On Jun 4, 9:47?am, Peter Otten <__pete... at web.de> wrote: > I can provoke the error in "naked" Python 3 by changing the > Example.__module__ attribute: > > Python 3.1.1+ (r311:74480, Nov ?2 2009, 15:45:00) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import pickle > >>> class Example: > > ... ? ? pass > ... > >>> pickle.dumps(Example()) > > b'\x80\x03c__main__\nExample\nq\x00)\x81q\x01}q\x02b.' > >>> Example.__module__ = "builtins" > >>> pickle.dumps(Example()) > > Traceback (most recent call last): > ? File "", line 1, in > ? File "/usr/lib/python3.1/pickle.py", line 1358, in dumps > ? ? Pickler(f, protocol, fix_imports=fix_imports).dump(obj) > _pickle.PicklingError: Can't pickle : attribute lookup > builtins.Example failed > > What's the value of __module__ when you run your code in Eclipse? > > Peter Thank you for replying. Here's from Eclipse console: >>> Example.__module__ 'builtins' >>> __name__ 'builtins' Duplicating your result in naked Python: Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> class Example: pass >>> import pickle >>> Example.__module__ '__main__' >>> f = open('testpickle.pkl','wb') >>> obj = Example() >>> obj <__main__.Example object at 0x02A26690> >>> pickle.dump(obj, f) >>> Example.__module__ = 'builtins' >>> obj2 = Example() >>> pickle.dump(obj2, f) Traceback (most recent call last): File "", line 1, in pickle.dump(obj2, f) File "C:\Python31\lib\pickle.py", line 1354, in dump Pickler(file, protocol, fix_imports=fix_imports).dump(obj) _pickle.PicklingError: Can't pickle : attribute lookup builtins.Example failed So what if I'm in an Eclipse pydev console and change the Example.__module__ to '__main__'.... >>> import sys; print('%s %s' % (sys.executable or sys.platform, sys.version)) C:\Python31\python.exe 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] >>> import pickle >>> class Example: ... pass ... >>> Example.__module__ 'builtins' >>> Example.__module__ = '__main__' >>> obj = Example() >>> obj <__main__.Example object at 0x029E8FD0> >>> f = open('testpickle.pkl','wb') >>> pickle.dump(obj, f) Traceback (most recent call last): File "", line 1, in File "C:\Python31\lib\pickle.py", line 1354, in dump Pickler(file, protocol, fix_imports=fix_imports).dump(obj) _pickle.PicklingError: Can't pickle : attribute lookup __main__.Example failed >>> Dang. Any insights? Kirby From tjreedy at udel.edu Fri Jun 4 13:49:51 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 04 Jun 2010 13:49:51 -0400 Subject: [python] pass the name of args In-Reply-To: <8f424838-f888-416b-9a97-e907d201c627@w31g2000yqb.googlegroups.com> References: <8f424838-f888-416b-9a97-e907d201c627@w31g2000yqb.googlegroups.com> Message-ID: On 6/4/2010 7:32 AM, macm wrote: A few types of objects have definition names (.__name__ attribute). All have 0 to many namespace names. If you want to pass an attribute name, pass it -- as a string. > def myDef(x) > doSomething x > result = x.???? > return coolThings def f(x. x_attr_name): ... res = getattr(x, x__attr_name) ... Terry Jan Reedy From tjreedy at udel.edu Fri Jun 4 13:54:17 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 04 Jun 2010 13:54:17 -0400 Subject: General questions - where & how In-Reply-To: <67A48378-C1B3-4C1B-9D46-CE1842774186@semanchuk.com> References: <67A48378-C1B3-4C1B-9D46-CE1842774186@semanchuk.com> Message-ID: On 6/4/2010 1:35 PM, Philip Semanchuk wrote: > > On Jun 4, 2010, at 1:22 PM, Uriah Eisenstein wrote: > >> Hi all, >> I'm relatively new to Python and have a few questions. Frankly, it >> took me a >> while to find on python.org what seems like a suitable place to post my >> questions. However, I'd like to check the archives and see if they >> haven't >> been discussed already... > > Good thinking! > > >> But I don't find a Search function. Is there such >> a thing? > > I use Google's "site" keyword search. e.g. to search the archives for > "banana": > http://www.google.com/search?q=site%3Amail.python.org%2Fpipermail%2Fpython-list%2F++banana One can also search mailing lists mirrored and archived by gmane http://search.gmane.org/ This is gmane.comp.python.general. There are about 200 other g.c.python lists/groups that are more specialized. I have no idea about comparitive performance. Terry Jan Reedy From tjreedy at udel.edu Fri Jun 4 14:03:48 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 04 Jun 2010 14:03:48 -0400 Subject: Missing DLL in win98 In-Reply-To: <1guh06tt177al7rqar55ab0aiif1ibim57@4ax.com> References: <0bsh06pilrfls0i3f473unhbee1j71pmbs@4ax.com> <1guh06tt177al7rqar55ab0aiif1ibim57@4ax.com> Message-ID: On 6/4/2010 9:08 AM, Spyder42 wrote: > On Fri, 04 Jun 2010 14:50:28 +0200, Christian Heimes >> Python 2.6 is not supported on Windows 98 and earlier. You need at least >> Windows 2000 with a recent service pack. >> >> Christian > > So your response is either, you don't know if there is a fix, or 'No > way in h377.' You couldn't figure out by my post that I already knew > that? Get off your high horse. Dumping on volunteer helpers is a good way to drive them away. It was not obvious, without closely reading your original post, and even then it is not clear, that you *knew* than 2.6 was not supported on Win98. You could have asked 'I know 2.6+ is not officially supported in win98. Does anyone know a workaround other than upgrading windows or sticking with 2.5?". *That* would have been clear. Terry Jan Reedy From no.email at please.post Fri Jun 4 14:14:38 2010 From: no.email at please.post (kj) Date: Fri, 4 Jun 2010 18:14:38 +0000 (UTC) Subject: tallying occurrences in list Message-ID: Task: given a list, produce a tally of all the distinct items in the list (for some suitable notion of "distinct"). Example: if the list is ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a'], then the desired tally would look something like this: [('a', 4), ('b', 3), ('c', 3)] I find myself needing this simple operation so often that I wonder: 1. is there a standard name for it? 2. is there already a function to do it somewhere in the Python standard library? Granted, as long as the list consists only of items that can be used as dictionary keys (and Python's equality test for hashkeys agrees with the desired notion of "distinctness" for the tallying), then the following does the job passably well: def tally(c): t = dict() for x in c: t[x] = t.get(x, 0) + 1 return sorted(t.items(), key=lambda x: (-x[1], x[0])) But, of course, if a standard library solution exists it would be preferable. Otherwise I either cut-and-paste the above every time I need it, or I create a module just for it. (I don't like either of these, though I suppose that the latter is much better than the former.) So anyway, I thought I'd ask. :) ~K From john at castleamber.com Fri Jun 4 14:19:11 2010 From: john at castleamber.com (John Bokma) Date: Fri, 04 Jun 2010 13:19:11 -0500 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <1275560120.8775.6.camel@linux-yu4c.site> <4c0886f5$0$28659$c3e8da3@news.astraweb.com> <4c089852$0$28659$c3e8da3@news.astraweb.com> Message-ID: <87mxva7ja8.fsf@castleamber.com> Steven D'Aprano writes: > But the really sad thing is that you think that "bigger" automatically > equals "better". I don't think that was the point. Anyway, not everbody can pick a provider, there are plenty of places that have only one or maybe two. And if that's the choice and neither carries Usenet you have to pay for Usenet like I do. Note that I consider it well worth the 10 euros I pay for it. To me, it looks like the use of Usenet for text is on the decline. I've been away from Usenet for like a year or so and could see quite a difference. More and more ISPs in my experience are dropping Usenet from their services. Mind, I think that the number of users on Usenet (text only) still exceeds the number when I first used Usenet (back in the early 90's). But usage is on the decline as far as I can tell. On top of that I see people I know from Usenet now quite active on Stack Overflow and sister sites. Finally, I have to disagree with your disagreement (which is just a personal experience) based on my personal experience: it's harder to find an ISP that carries Usenet. And I have experience with, oh, just 3 countries where I have been living in for the past 10 years. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From usenot at geekmail.INVALID Fri Jun 4 14:21:41 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Fri, 4 Jun 2010 20:21:41 +0200 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87zkzccx3q.fsf@benfinney.id.au> <88192331-3301-47f8-8742-0a26eb9a65f0@j9g2000vbp.googlegroups.com> <20100603143440.30e34ce6@geekmail.INVALID> <87iq60cgfo.fsf@benfinney.id.au> Message-ID: <20100604202141.66202cf3@geekmail.INVALID> On Fri, 04 Jun 2010 00:57:15 +1000 Ben Finney wrote: > Andreas Waldenburger writes: > > > But consolidation is the *only* way to go, really. The parallelism > > between c.l.p. and python-list is great already. Now throw some sort > > of Forum in the mix > > This already *is* a forum. Whatever it is you think is needed, it's > already a forum. Can you be more specific about what you would add? > I meant a web forum. /W -- INVALID? DE! From tjreedy at udel.edu Fri Jun 4 14:27:04 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 04 Jun 2010 14:27:04 -0400 Subject: Python Forum In-Reply-To: References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <4c0891fc$0$28659$c3e8da3@news.astraweb.com> Message-ID: On 6/4/2010 12:28 PM, Emile van Sebille wrote: > Is there now a non-email method of posting to this list? Google <==> comp.lang.python <==> python-list <==> gmane.comp.python.general where <==> is a bi-directional gateway. Gmane mirrors about 250 other Python mailing lists under gman.comp.python.xxx. I currently subscibe to 3 others. gmane does this because many people like to 1) look at a group first without subscribing (in the mail list sense, as opposed to the newgroup sense of click a box) 2) keep messages for each group separated (without having to add folders and filters to their email reader) 3) only download messages they want to read Terry Jan Reedy From no.email at nospam.invalid Fri Jun 4 14:28:15 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 04 Jun 2010 11:28:15 -0700 Subject: tallying occurrences in list References: Message-ID: <7xfx127iv4.fsf@ruckus.brouhaha.com> kj writes: > 1. is there a standard name for it? I don't know of one, or a stdlib for it, but it's pretty trivial. > def tally(c): > t = dict() > for x in c: > t[x] = t.get(x, 0) + 1 > return sorted(t.items(), key=lambda x: (-x[1], x[0])) I like to use defaultdict and tuple unpacking for code like that: from collections import defaultdict def tally(c): t = defaultdict(int) for x in c: t[x] += 1 return sorted(t.iteritems(), key=lambda (k,v): (-v, k)) From nagle at animats.com Fri Jun 4 14:28:44 2010 From: nagle at animats.com (John Nagle) Date: Fri, 04 Jun 2010 11:28:44 -0700 Subject: Street address parsing in Python, again. Message-ID: <4c093feb$0$1657$742ec2ed@news.sonic.net> I'm still struggling with street address parsing in Python. (Previous discussion: http://www.velocityreviews.com/forums/t720759-usable-street-address-parser-in-python.html) I need something good enough to reliably extract street name and number. That gives me something I can match against databases. There are several parsers available in Perl, and various online services that have a street name database. The online parsers are good, but I need to encode some big databases, and the online ones are either rate-limited or expensive. The parser at PyParsing: http://pyparsing.wikispaces.com/file/view/streetAddressParser.py seems to work on about 80% of addresses. Addresses with "pre-directionals" and street types before the name seem to give the most trouble: 487 E. Middlefield Rd. -> streetnumber = 487, streetname = E. MIDDLEFIELD 487 East Middlefield Road -> streetnumber = 487, streetname = EAST MIDDLEFIELD 226 West Wayne Street -> streetnumber = 226, streetname = WEST WAYNE (Those are all Verisign offices) New Orchard Road -> streetnumber = , streetname = NEW 1 New Orchard Road -> streetnumber = 1 , streetname = NEW (IBM corporate HQ) 390 Park Avenue -> streetnumber =, streetname = 390 (Alcoa corporate HQ) None of those addresses are exotic or corner cases, but they're all mis-parsed. There's a USPS standard on this which might be helpful. http://pe.usps.com/text/pub28/28c2_003.html That says "When parsing the Delivery Address Line into the individual components, start from the right-most element of the address and work toward the left. Place each element in the appropriate field until all address components are isolated." PyParsing works left to right, and trying to do look-ahead to achieve the effect of right-to-left isn't working. It may be necessary to split the input, reverse the tokens, and write a parser that works in reverse. John Nagle From __peter__ at web.de Fri Jun 4 14:33:34 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 04 Jun 2010 20:33:34 +0200 Subject: tallying occurrences in list References: Message-ID: kj wrote: > > > > > > Task: given a list, produce a tally of all the distinct items in > the list (for some suitable notion of "distinct"). > > Example: if the list is ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', > 'c', 'a'], then the desired tally would look something like this: > > [('a', 4), ('b', 3), ('c', 3)] > > I find myself needing this simple operation so often that I wonder: > > 1. is there a standard name for it? > 2. is there already a function to do it somewhere in the Python > standard library? > > Granted, as long as the list consists only of items that can be > used as dictionary keys (and Python's equality test for hashkeys > agrees with the desired notion of "distinctness" for the tallying), > then the following does the job passably well: > > def tally(c): > t = dict() > for x in c: > t[x] = t.get(x, 0) + 1 > return sorted(t.items(), key=lambda x: (-x[1], x[0])) > > But, of course, if a standard library solution exists it would be > preferable. Otherwise I either cut-and-paste the above every time > I need it, or I create a module just for it. (I don't like either > of these, though I suppose that the latter is much better than the > former.) > > So anyway, I thought I'd ask. :) Python 3.1 has, and 2.7 will have collections.Counter: >>> from collections import Counter >>> c = Counter("abcabcabca") >>> c.most_common() [('a', 4), ('c', 3), ('b', 3)] Peter From alfps at start.no Fri Jun 4 14:36:02 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 04 Jun 2010 20:36:02 +0200 Subject: Python Forum In-Reply-To: <20100604202141.66202cf3@geekmail.INVALID> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87zkzccx3q.fsf@benfinney.id.au> <88192331-3301-47f8-8742-0a26eb9a65f0@j9g2000vbp.googlegroups.com> <20100603143440.30e34ce6@geekmail.INVALID> <87iq60cgfo.fsf@benfinney.id.au> <20100604202141.66202cf3@geekmail.INVALID> Message-ID: * Andreas Waldenburger, on 04.06.2010 20:21: > On Fri, 04 Jun 2010 00:57:15 +1000 Ben Finney > wrote: > >> Andreas Waldenburger writes: >> >>> But consolidation is the *only* way to go, really. The parallelism >>> between c.l.p. and python-list is great already. Now throw some sort >>> of Forum in the mix >> >> This already *is* a forum. Whatever it is you think is needed, it's >> already a forum. Can you be more specific about what you would add? >> > > I meant a web forum. You can access [comp.lang.python] via Google Groups and other web based interfaces. So it already is a web forum. Cheers & hth., - Alf -- blog at From magdoll at gmail.com Fri Jun 4 14:36:35 2010 From: magdoll at gmail.com (Magdoll) Date: Fri, 4 Jun 2010 11:36:35 -0700 (PDT) Subject: tallying occurrences in list References: <7xfx127iv4.fsf@ruckus.brouhaha.com> Message-ID: On Jun 4, 11:28?am, Paul Rubin wrote: > kj writes: > > 1. is there a standard name for it? > > I don't know of one, or a stdlib for it, but it's pretty trivial. > > > def tally(c): > > ? ? t = dict() > > ? ? for x in c: > > ? ? ? ? t[x] = t.get(x, 0) + 1 > > ? ? return sorted(t.items(), key=lambda x: (-x[1], x[0])) > > I like to use defaultdict and tuple unpacking for code like that: > > ?from collections import defaultdict > ?def tally(c): > ? ? ?t = defaultdict(int) > ? ? ?for x in c: > ? ? ? ? ?t[x] += 1 > ? ? ?return sorted(t.iteritems(), key=lambda (k,v): (-v, k)) I would also very much like to see this become part of the standard library. Sure the code is easy to write but I use this incredibly often and I've always wished I would have a one-line function call that has the same output as the mysql query: "SELECT id, count(*) FROM table GROUP BY somefield" or maybe there is already a short solution to this that I'm not aware of... From usenot at geekmail.INVALID Fri Jun 4 14:37:29 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Fri, 4 Jun 2010 20:37:29 +0200 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <4c0891fc$0$28659$c3e8da3@news.astraweb.com> Message-ID: <20100604203729.1559bc88@geekmail.INVALID> On Fri, 04 Jun 2010 09:28:23 -0700 Emile van Sebille wrote: > On 6/3/2010 10:41 PM Steven D'Aprano said... > > On Thu, 03 Jun 2010 06:15:20 -0400, Adam Tauno Williams wrote: > >> Most people use this list via e-mail, > > > > How do you know? Do you have evidence for this, or are you just > > making it up? > > > > Is there now a non-email method of posting to this list? > Te-he. Yes. In case you're not being ironic: /W -- INVALID? DE! From john at castleamber.com Fri Jun 4 14:37:59 2010 From: john at castleamber.com (John Bokma) Date: Fri, 04 Jun 2010 13:37:59 -0500 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87zkzccx3q.fsf@benfinney.id.au> <88192331-3301-47f8-8742-0a26eb9a65f0@j9g2000vbp.googlegroups.com> <4c088af3$0$28659$c3e8da3@news.astraweb.com> Message-ID: <878w6u7iew.fsf@castleamber.com> Pierre Quentel writes: > They certainly *can* distinguish. But it's so easy to make it more > explicit with syntax highlighting, background color, border etc. that > most sites about programing languages use it, including the Python > home site itself, or the Python cookbook on Active State [..] > That's 2 different things. When you use a programming language you > know you have to adopt the syntax defined by the program. When you > write something in a forum, you expect that the editor will be smart > enough to know that http://pythonforum.org is a URL You're using a bad Usenet client. Switch to Gnus, part of Emacs, for example and you can have both. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From magdoll at gmail.com Fri Jun 4 14:38:23 2010 From: magdoll at gmail.com (Magdoll) Date: Fri, 4 Jun 2010 11:38:23 -0700 (PDT) Subject: tallying occurrences in list References: Message-ID: <3746febb-3230-43ce-a61b-7831501268f5@k17g2000pro.googlegroups.com> On Jun 4, 11:33?am, Peter Otten <__pete... at web.de> wrote: > kj wrote: > > > Task: given a list, produce a tally of all the distinct items in > > the list (for some suitable notion of "distinct"). > > > Example: if the list is ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', > > 'c', 'a'], then the desired tally would look something like this: > > > [('a', 4), ('b', 3), ('c', 3)] > > > I find myself needing this simple operation so often that I wonder: > > > 1. is there a standard name for it? > > 2. is there already a function to do it somewhere in the Python > > ? ?standard library? > > > Granted, as long as the list consists only of items that can be > > used as dictionary keys (and Python's equality test for hashkeys > > agrees with the desired notion of "distinctness" for the tallying), > > then the following does the job passably well: > > > def tally(c): > > ? ? t = dict() > > ? ? for x in c: > > ? ? ? ? t[x] = t.get(x, 0) + 1 > > ? ? return sorted(t.items(), key=lambda x: (-x[1], x[0])) > > > But, of course, if a standard library solution exists it would be > > preferable. ?Otherwise I either cut-and-paste the above every time > > I need it, or I create a module just for it. ?(I don't like either > > of these, though I suppose that the latter is much better than the > > former.) > > > So anyway, I thought I'd ask. :) > > Python 3.1 has, and 2.7 will have collections.Counter: > > >>> from collections import Counter > >>> c = Counter("abcabcabca") > >>> c.most_common() > > [('a', 4), ('c', 3), ('b', 3)] > > Peter Thanks Peter, I think you just answered my post :) From john at castleamber.com Fri Jun 4 14:41:46 2010 From: john at castleamber.com (John Bokma) Date: Fri, 04 Jun 2010 13:41:46 -0500 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <4c0891fc$0$28659$c3e8da3@news.astraweb.com> Message-ID: <874ohi7i8l.fsf@castleamber.com> Steven D'Aprano writes: > Sure, a lot of those 1,800 posts are spam, but the spammers wouldn't > waste their time if they didn't think there were people still on > Usenet. Heh, since spamming goes automatically who cares how many people it reaches. I also see spam in which people forget to include a URL, etc. My site is daily hit by badly written spam software. So, no: spam is not by far any way to measure the number of readers. On top of that, there is /no way/ to even determine how many people read a given Usenet group. > How do you know? Do you have evidence for this, or are you just making it > up? I guess the same way as your remark regarding spam: guessing (I guess) ;-) > I happen to know at least one of the Gnus users is using News, so that's > 1 definite News, 2 Web, 4 either News or email, and no definite email. Fwiw: I use Usenet :-). -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From malaclypse2 at gmail.com Fri Jun 4 14:42:00 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Fri, 4 Jun 2010 14:42:00 -0400 Subject: strange syntax error In-Reply-To: References: Message-ID: On Fri, Jun 4, 2010 at 1:31 PM, _wolf wrote: > ? ?File "", line 6 > ? ? ?# > ? ? ?^ > ?SyntaxError: invalid syntax I believe you're encountering this bug: http://bugs.python.org/issue1184112 It's been fixed for 2.7 and 3.2. Until then, you'll need to work around it. You can either append a newline to the end of any source snippets that you are exec-ing, or if you're writing the code snippets that are being exec-ed yourself, don't write them in such a way that they trigger the bug. -- Jerry From john at castleamber.com Fri Jun 4 14:42:33 2010 From: john at castleamber.com (John Bokma) Date: Fri, 04 Jun 2010 13:42:33 -0500 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <4c0891fc$0$28659$c3e8da3@news.astraweb.com> Message-ID: <87zkza63mu.fsf@castleamber.com> Emile van Sebille writes: > On 6/3/2010 10:41 PM Steven D'Aprano said... >> On Thu, 03 Jun 2010 06:15:20 -0400, Adam Tauno Williams wrote: >>> Most people use this list via e-mail, >> >> How do you know? Do you have evidence for this, or are you just making it >> up? >> > > Is there now a non-email method of posting to this list? No idea what "this list" is, but I am reading your message in Gnus via Usenet. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From usenot at geekmail.INVALID Fri Jun 4 14:44:38 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Fri, 4 Jun 2010 20:44:38 +0200 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <87zkzccx3q.fsf@benfinney.id.au> <88192331-3301-47f8-8742-0a26eb9a65f0@j9g2000vbp.googlegroups.com> <20100603143440.30e34ce6@geekmail.INVALID> <87iq60cgfo.fsf@benfinney.id.au> <20100604202141.66202cf3@geekmail.INVALID> Message-ID: <20100604204438.412e0bf2@geekmail.INVALID> On Fri, 04 Jun 2010 20:36:02 +0200 "Alf P. Steinbach" wrote: > * Andreas Waldenburger, on 04.06.2010 20:21: > > On Fri, 04 Jun 2010 00:57:15 +1000 Ben Finney > > wrote: > > > >> Andreas Waldenburger writes: > >> > >>> But consolidation is the *only* way to go, really. The parallelism > >>> between c.l.p. and python-list is great already. Now throw some > >>> sort of Forum in the mix > >> > >> This already *is* a forum. Whatever it is you think is needed, it's > >> already a forum. Can you be more specific about what you would add? > >> > > > > I meant a web forum. > > You can access [comp.lang.python] via Google Groups and other web > based interfaces. > > So it already is a web forum. > Huh. I've never looked at it that way. OK, then. Forget what I said about Wave. Oh, you have? Good. ;) /W -- INVALID? DE! From python at mrabarnett.plus.com Fri Jun 4 14:50:16 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 04 Jun 2010 19:50:16 +0100 Subject: tallying occurrences in list In-Reply-To: References: Message-ID: <4C094AE8.2050001@mrabarnett.plus.com> kj wrote: > > > > > Task: given a list, produce a tally of all the distinct items in > the list (for some suitable notion of "distinct"). > > Example: if the list is ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', > 'c', 'a'], then the desired tally would look something like this: > > [('a', 4), ('b', 3), ('c', 3)] > > I find myself needing this simple operation so often that I wonder: > > 1. is there a standard name for it? > 2. is there already a function to do it somewhere in the Python > standard library? > > Granted, as long as the list consists only of items that can be > used as dictionary keys (and Python's equality test for hashkeys > agrees with the desired notion of "distinctness" for the tallying), > then the following does the job passably well: > > def tally(c): > t = dict() > for x in c: > t[x] = t.get(x, 0) + 1 > return sorted(t.items(), key=lambda x: (-x[1], x[0])) > > But, of course, if a standard library solution exists it would be > preferable. Otherwise I either cut-and-paste the above every time > I need it, or I create a module just for it. (I don't like either > of these, though I suppose that the latter is much better than the > former.) > > So anyway, I thought I'd ask. :) > In Python 3 there's the 'Counter' class in the 'collections' module. It'll also be in Python 2.7. For earlier versions there's this: http://code.activestate.com/recipes/576611/ From emile at fenx.com Fri Jun 4 15:04:56 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 04 Jun 2010 12:04:56 -0700 Subject: Python Forum In-Reply-To: References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <4c0891fc$0$28659$c3e8da3@news.astraweb.com> Message-ID: On 6/4/2010 11:27 AM Terry Reedy said... > On 6/4/2010 12:28 PM, Emile van Sebille wrote: > >> Is there now a non-email method of posting to this list? > > Google <==> comp.lang.python <==> python-list <==> > gmane.comp.python.general > > where <==> is a bi-directional gateway. Yes -- I use gmane as well. But, IIRC, I needed to be on the mail list in order for my responses to show up because MailMan is the primary back end and I thought it's set to only accept posts from members. Hence, my question. Aren't we all members posting (ultimately) exclusively through email regardless of preferred reading interfaces? Emile From alfps at start.no Fri Jun 4 15:08:19 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 04 Jun 2010 21:08:19 +0200 Subject: Python Forum In-Reply-To: <87mxva7ja8.fsf@castleamber.com> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <1275560120.8775.6.camel@linux-yu4c.site> <4c0886f5$0$28659$c3e8da3@news.astraweb.com> <4c089852$0$28659$c3e8da3@news.astraweb.com> <87mxva7ja8.fsf@castleamber.com> Message-ID: * John Bokma, on 04.06.2010 20:19: > Steven D'Aprano writes: > >> But the really sad thing is that you think that "bigger" automatically >> equals "better". > > I don't think that was the point. > > Anyway, not everbody can pick a provider, there are plenty of places > that have only one or maybe two. And if that's the choice and neither > carries Usenet you have to pay for Usenet like I do. Note that I > consider it well worth the 10 euros I pay for it. > > To me, it looks like the use of Usenet for text is on the > decline. I've been away from Usenet for like a year or so and could see > quite a difference. More and more ISPs in my experience are dropping > Usenet from their services. Mind, I think that the number of users on > Usenet (text only) still exceeds the number when I first used Usenet > (back in the early 90's). But usage is on the decline as far as I can > tell. On top of that I see people I know from Usenet now quite active on > Stack Overflow and sister sites. > > Finally, I have to disagree with your disagreement (which is just a > personal experience) based on my personal experience: it's harder to > find an ISP that carries Usenet. And I have experience with, oh, just 3 > countries where I have been living in for the past 10 years. True. While Usenet traffic is still exponentially increasing, most of that's in binary groups, and it's spam. I think much of the decline of Usenet is correlated with an increase of laws designed to limit free speech and support all kinds surveillance. It started, as I see it, back in the early 90's with Playboy attempting to sue anyone who used the Lena picture in photo processing tests etc. (it's the standard image for that). They failed in that particular endeavour, but did succeed in shutting down thousands of sites worldwide displaying Playboy pictures. The Church of Scientology picked up on the idea that a private company can /control/ net content worldwide by way of laws designed for other things. The record and movie industry caught on to this. Governments of some special countries such China, Saudi-Arabia and Iran, plus, very suprising to me, Australia, caught on to it, that is, the idea of controlling net content, or at least access to that content. Then finally George W. Bush caught on to it, and with American ISPs legally responsible for the content of the traffic, well, the following from Wikipedia isn't quite chronological but is quite clear: In 2008, Verizon Communications, Time Warner Cable and Sprint Nextel signed an agreement with Attorney General of New York Andrew Cuomo to shut down access to sources of child pornography.[31] Time Warner Cable stopped offering access to Usenet. Verizon reduced its access to the "Big 8" hierarchies. Sprint stopped access to the alt.* hierarchies. AT&T stopped access to the alt.binaries.* hierarchies. Cuomo never specifically named Usenet in his anti-child pornography campaign. David DeJean of PC World said that some worry that the ISPs used Cuomo's campaign as an excuse to end portions of Usenet access, as it is costly for the internet service providers. In 2008 AOL, which no longer offered Usenet access, and the four providers that responded to the Cuomo campaign were the five largest internet service providers in the United States; they had more than 50% of the U.S. ISP marketshare.[32] On June 8, 2009, AT&T announced that it would no longer provide access to the Usenet service as of July 15, 2009.[33] AOL announced that it would discontinue its integrated Usenet service in early 2005, citing the growing popularity of weblogs, chat forums and on-line conferencing.[34] The AOL community had a tremendous role in popularizing Usenet some 11 years earlier,[citation needed] with all of its positive and negative aspects. This change marked the end of the legendary Eternal September. Others, however, feel that Google Groups, especially with its new user interface, has picked up the torch that AOL has dropped?and that the so-called Eternal September has yet to end.[citation needed] In August, 2009, Verizon announced that it would discontinue access to Usenet on September 30, 2009.[35][36] In April 2010, Cox Communications announced (via email) that it would discontinue Usenet service, effective June 30, 2010. JANET(UK) announced it will discontinue Usenet service, effective July 31, 2010, citing Google Groups as an alternative.[37] Microsoft announced that it would discontinue support for it's public newsgroups (msnews.microsoft.com) from June 1, 2010, offering web forums as an alternative. In short, in the future you will no longer be able to access old articles via archives such as Google Groups (Google picked up that archive from Deja News). Until some replacement for Usenet appears, online discussion will in general be effectively /local/, unknown to all but the parties currently using a given web forum, and it will in general not be archived. As I see it, those who have made and continue to make the decisions to make it that way, want it that way. Cheers, - Alf -- blog at From bapat.namrata at gmail.com Fri Jun 4 15:15:36 2010 From: bapat.namrata at gmail.com (namrata) Date: Fri, 4 Jun 2010 12:15:36 -0700 (PDT) Subject: how to access data attributes of a class object Message-ID: <7c41101a-f774-4734-991f-4c197b8f1534@32g2000prq.googlegroups.com> Hi, i am new to python and sqlalchemy. so my doubt mite be very silly. I am creating an instance of a class. for example let the class be Temp and the attributes of the class be first_name and last_name. in order to access the attributes i will usually use the following command: a = Temp() a.last_name = "*******" now, i am using sqlalchemy and mapping a table in postgresql to python. i am trying to implement a method where i can pass the column name and a value to the method. the method will fire a query for that column name and value. the query is as follows: query = session.query(Temp).query.filter(Temp.last_name == some_value) the column name passed to the method is stored in a local variable say 'col_name' how do i pass this local variable to the query. when i try the below query it throws an error saying col_name is not an attirbute query = session.query(Temp).query.filter(Temp.col_name == some_value) please help. thanks in advance. From lie.1296 at gmail.com Fri Jun 4 15:22:21 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 05 Jun 2010 05:22:21 +1000 Subject: Python Forum In-Reply-To: <87y6ev36ix.fsf@castleamber.com> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c0619e7$0$24606$426a74cc@news.free.fr> <80f1faae-146d-40b6-9075-613faf38a5f7@g39g2000pri.googlegroups.com> <87y6ev36ix.fsf@castleamber.com> Message-ID: <4c0952e6$1@dnews.tpgi.com.au> On 06/04/10 11:56, John Bokma wrote: > Phlip writes: > >> On Jun 3, 3:20 pm, geremy condra wrote: >> >>>> You mean like how I never get answers, to my super-easy GED-level >>>> questions, here??! >>> >>> I agree. This proves conclusively that a web forum is the right >>> place for you. >> >> Ah, so you feel up to my "xsl for xmlrunner.py" question? > > Just jumping in the middle, but if you're looking for a web based forum > where you can ask questions, check out Stack Overflow (and sister sites, > depending on your question). I've noticed over the last couple of months > that often things I google for, are answered on Stack Overflow. One > thing that would've been nice to have on Usenet that I like is the > ability to vote answers up or down. I think Usenet would've been a bit > better with that option. Probably. A vote up/down feature tend to highlight popular problems, but it also buries less popular problems that might have perfectly good answers. I think Google Groups have 5-star-rating system? You might want to check on that. From __peter__ at web.de Fri Jun 4 15:26:55 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 04 Jun 2010 21:26:55 +0200 Subject: how to access data attributes of a class object References: <7c41101a-f774-4734-991f-4c197b8f1534@32g2000prq.googlegroups.com> Message-ID: namrata wrote: > I am creating an instance of a class. for example let the class be > Temp and the attributes of the class be first_name and last_name. > in order to access the attributes i will usually use the following > command: > a = Temp() > a.last_name = "*******" > > now, i am using sqlalchemy and mapping a table in postgresql to > python. i am trying to implement a method where i can pass the column > name and a value to the method. the method will fire a query for that > column name and value. the query is as follows: > query = session.query(Temp).query.filter(Temp.last_name == some_value) > > the column name passed to the method is stored in a local variable say > 'col_name' > how do i pass this local variable to the query. when i try the below > query it throws an error saying col_name is not an attirbute > query = session.query(Temp).query.filter(Temp.col_name == some_value) I'd guess you can use getattr(): query = session.query(Temp).query.filter(getattr(Temp, col_name) == some_value) Peter From jyoung79 at kc.rr.com Fri Jun 4 15:31:50 2010 From: jyoung79 at kc.rr.com (jyoung79 at kc.rr.com) Date: Fri, 4 Jun 2010 19:31:50 +0000 Subject: [python] pass the name of args Message-ID: <20100604193150.FFOO1.144608.root@hrndva-web16-z01> Would vars() help? Check out this link: http://www.daniweb.com/forums/thread134555.html Jay -- > def myDef(x) > doSomething x > result = x.???? > return coolThings > --------------------------------- > > WhatYourName = ('python','is','cool') > > myDef(WhatYourName) > > so what I am looking for in myDef > > result = WhatYourName From lie.1296 at gmail.com Fri Jun 4 15:41:36 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 05 Jun 2010 05:41:36 +1000 Subject: Python Forum In-Reply-To: <87mxva7ja8.fsf@castleamber.com> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <1275560120.8775.6.camel@linux-yu4c.site> <4c0886f5$0$28659$c3e8da3@news.astraweb.com> <4c089852$0$28659$c3e8da3@news.astraweb.com> <87mxva7ja8.fsf@castleamber.com> Message-ID: <4c09576a$1@dnews.tpgi.com.au> On 06/05/10 04:19, John Bokma wrote: > Steven D'Aprano writes: > >> But the really sad thing is that you think that "bigger" automatically >> equals "better". > > I don't think that was the point. > > Anyway, not everbody can pick a provider, there are plenty of places > that have only one or maybe two. And if that's the choice and neither > carries Usenet you have to pay for Usenet like I do. Note that I > consider it well worth the 10 euros I pay for it. Isn't gmane available where you live? I've used gmane for newsgroups that my local server doesn't carry. The only problem is that there's a slight delay in opening new posts (0.5 seconds or so). From lie.1296 at gmail.com Fri Jun 4 15:43:45 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 05 Jun 2010 05:43:45 +1000 Subject: Python Forum In-Reply-To: References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <4c0891fc$0$28659$c3e8da3@news.astraweb.com> Message-ID: <4c0957ea$1@dnews.tpgi.com.au> On 06/05/10 05:04, Emile van Sebille wrote: > On 6/4/2010 11:27 AM Terry Reedy said... >> On 6/4/2010 12:28 PM, Emile van Sebille wrote: >> >>> Is there now a non-email method of posting to this list? >> >> Google <==> comp.lang.python <==> python-list <==> >> gmane.comp.python.general >> >> where <==> is a bi-directional gateway. > > Yes -- I use gmane as well. But, IIRC, I needed to be on the mail list > in order for my responses to show up because MailMan is the primary back > end and I thought it's set to only accept posts from members. > > Hence, my question. Aren't we all members posting (ultimately) > exclusively through email regardless of preferred reading interfaces? No, I don't. From pmaupin at gmail.com Fri Jun 4 15:48:47 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Fri, 4 Jun 2010 12:48:47 -0700 (PDT) Subject: signed vs unsigned int References: Message-ID: <138e01be-019c-4443-bc92-19037fa0d493@o39g2000vbd.googlegroups.com> On Jun 2, 6:25?am, John Machin wrote: > On Jun 2, 4:43?pm, johnty wrote: > > > i'm reading bytes from a serial port, and storing it into an array. > > > each byte represents a signed 8-bit int. > > > currently, the code i'm looking at converts them to an unsigned int by > > doing ord(array[i]). however, what i'd like is to get the _signed_ > > integer value. whats the easiest way to do this? > > signed = unsigned if unsigned <= 127 else unsigned - 256 That works, but I prefer not using if/else for things that can be described in an expression without it. Other ways of expressing this include: signed = (unsigned & 127) - (unsigned & 128) signed = (unsigned & 127) * 2 - unsigned signed - unsigned - 2 * (unsigned & 128) Regards, Pat From magdoll at gmail.com Fri Jun 4 15:53:26 2010 From: magdoll at gmail.com (Magdoll) Date: Fri, 4 Jun 2010 12:53:26 -0700 (PDT) Subject: bz2 module doesn't work properly with all bz2 files Message-ID: I'm not sure what's causing this, but depending on the compression program used, the bz2 module sometimes exits earlier. I used pbzip2 to compress my bz2 files and read through the file using the bz2 module. The file descriptor always exits much earlier than where the actual EOF is. If I use bzip2 instead of pbzip2 to compress the files, then everything is fine. My files are generally big (several GBs) so decompressing them is not a wise choice, and it is a little unfortunate that I can't use pbzip2 because it's usually much faster than bz2. From pmaupin at gmail.com Fri Jun 4 15:55:01 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Fri, 4 Jun 2010 12:55:01 -0700 (PDT) Subject: Diff of Text References: Message-ID: On Jun 3, 9:54?pm, GZ wrote: > Hi All, > > I am looking for an algorithm that can compare to source code files > line by line and find the minimum diff. I have looked at the difflib > included in python. The problem is that it is designed to make the > diff results easier for humans to read, instead of minimize the size > of the output differencial. I would like an algorithm implementation > that gives the absolute minimum difference between the two files. > > Can you help me? > > Thanks, > gz There's an "rsync.py" module in pypi -- one would think that would have to solve that same problem... Regards, Pat From lie.1296 at gmail.com Fri Jun 4 15:56:01 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 05 Jun 2010 05:56:01 +1000 Subject: tallying occurrences in list In-Reply-To: <3746febb-3230-43ce-a61b-7831501268f5@k17g2000pro.googlegroups.com> References: <3746febb-3230-43ce-a61b-7831501268f5@k17g2000pro.googlegroups.com> Message-ID: <4c095aca$1@dnews.tpgi.com.au> On 06/05/10 04:38, Magdoll wrote: > On Jun 4, 11:33 am, Peter Otten <__pete... at web.de> wrote: >> kj wrote: >> >>> Task: given a list, produce a tally of all the distinct items in >>> the list (for some suitable notion of "distinct"). >> >>> Example: if the list is ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', >>> 'c', 'a'], then the desired tally would look something like this: >> >>> [('a', 4), ('b', 3), ('c', 3)] >> >>> I find myself needing this simple operation so often that I wonder: >> >>> 1. is there a standard name for it? >>> 2. is there already a function to do it somewhere in the Python >>> standard library? >> >>> Granted, as long as the list consists only of items that can be >>> used as dictionary keys (and Python's equality test for hashkeys >>> agrees with the desired notion of "distinctness" for the tallying), >>> then the following does the job passably well: >> >>> def tally(c): >>> t = dict() >>> for x in c: >>> t[x] = t.get(x, 0) + 1 >>> return sorted(t.items(), key=lambda x: (-x[1], x[0])) >> >>> But, of course, if a standard library solution exists it would be >>> preferable. Otherwise I either cut-and-paste the above every time >>> I need it, or I create a module just for it. (I don't like either >>> of these, though I suppose that the latter is much better than the >>> former.) >> >>> So anyway, I thought I'd ask. :) >> >> Python 3.1 has, and 2.7 will have collections.Counter: >> >>>>> from collections import Counter >>>>> c = Counter("abcabcabca") >>>>> c.most_common() >> >> [('a', 4), ('c', 3), ('b', 3)] >> >> Peter > > > Thanks Peter, I think you just answered my post :) If you're using previous versions (2.4 and onwards) then: [(o, len(list(g))) for o, g in itertools.groupby(sorted(myList))] From nagle at animats.com Fri Jun 4 15:59:21 2010 From: nagle at animats.com (John Nagle) Date: Fri, 04 Jun 2010 12:59:21 -0700 Subject: Street address parsing in Python, again. In-Reply-To: <4c093feb$0$1657$742ec2ed@news.sonic.net> References: <4c093feb$0$1657$742ec2ed@news.sonic.net> Message-ID: <4c095528$0$1652$742ec2ed@news.sonic.net> John Nagle wrote: > The parser at PyParsing: > > http://pyparsing.wikispaces.com/file/view/streetAddressParser.py > > ..Bad cases... > 487 E. Middlefield Rd. -> streetnumber = 487, streetname = E. MIDDLEFIELD > 487 East Middlefield Road -> streetnumber = 487, streetname = EAST MIDDLEFIELD > 226 West Wayne Street -> streetnumber = 226, streetname = WEST WAYNE > New Orchard Road -> streetnumber = , streetname = NEW > 1 New Orchard Road -> streetnumber = 1 , streetname = NEW > 390 Park Avenue -> streetnumber =, streetname = 390 Here's a system that gets all the above cases right: the USC Deterministic Address Parser. https://webgis.usc.edu/Services/AddressNormalization/Interactive/DeterministicNormalization.aspx This will parse a street address line alone, without a city, state, or ZIP code, so it's not using a big database. There's a technical paper http://gislab.usc.edu/i/publications/gislabtr11.pdf but it doesn't have that much detail. However, now we know a solution exists. I've asked USC if they'll make the code available. John Nagle From H.Schaathun at surrey.ac.uk Fri Jun 4 16:01:00 2010 From: H.Schaathun at surrey.ac.uk (Hans Georg Schaathun) Date: Fri, 4 Jun 2010 21:01:00 +0100 Subject: Plotting in batch with no display Message-ID: Admittedly not the strongest reason, but yet an important one, for switching from Matlab to python/numpy/scipy/matplotlib, is that Matlab is very cumbersome to run in batch. Now I discover that some of the matplotlib.pyplot functions (incl. plot and contour) insist on opening an X11 window (just like Matlab does). I would have preferred just to create the plot straight on file. The extra window is a nuisance on my laptop, it is deep-felt pain if I try to run it remotely. It fails completely if I run it without any display at all. Oddly, the bar() function does not open a window by default. I was very happy with that. It works exactly the way I want. (Why isn't pyplot more consistent?) Is there something I have missed? Is it possible to create standard 2D plots and contour plots without a display, writing the graphics straight into a PDF file? I'll be grateful for any pointers and ideas, :-- George From nagle at animats.com Fri Jun 4 16:26:00 2010 From: nagle at animats.com (John Nagle) Date: Fri, 04 Jun 2010 13:26:00 -0700 Subject: signed vs unsigned int In-Reply-To: References: Message-ID: <4c095b67$0$1625$742ec2ed@news.sonic.net> johnty wrote: > i'm reading bytes from a serial port, and storing it into an array. Try reading into a type "bytearray". That's the proper data type for raw bytes. John Nagle From bapat.namrata at gmail.com Fri Jun 4 16:29:07 2010 From: bapat.namrata at gmail.com (namrata) Date: Fri, 4 Jun 2010 13:29:07 -0700 (PDT) Subject: how to access data attributes of a class object References: <7c41101a-f774-4734-991f-4c197b8f1534@32g2000prq.googlegroups.com> Message-ID: Thanks a lot Peter. It works. On Jun 4, 12:26?pm, Peter Otten <__pete... at web.de> wrote: > namrata wrote: > > I am creating an instance of a class. for example let the class be > > Temp and the attributes of the class be first_name and last_name. > > in order to access the attributes i will usually use the following > > command: > > a = Temp() > > a.last_name = "*******" > > > now, i am using sqlalchemy and mapping a table in postgresql to > > python. i am trying to implement a method where i can pass the column > > name and a value to the method. the method will fire a query for that > > column name and value. the query is as follows: > > query = session.query(Temp).query.filter(Temp.last_name == some_value) > > > the column name passed to the method is stored in a local variable say > > 'col_name' > > how do i pass this local variable to the query. when i try the below > > query it throws an error saying col_name is not an attirbute > > query = session.query(Temp).query.filter(Temp.col_name == some_value) > > I'd guess you can use getattr(): > > query = session.query(Temp).query.filter(getattr(Temp, col_name) == > some_value) > > Peter From bryanjugglercryptographer at yahoo.com Fri Jun 4 16:40:21 2010 From: bryanjugglercryptographer at yahoo.com (Bryan) Date: Fri, 4 Jun 2010 13:40:21 -0700 (PDT) Subject: getting MemoryError with dicts; suspect memory fragmentation References: <1d1b48dd-3316-4a72-a8a0-e56d307e5ec7@n37g2000prc.googlegroups.com> <0878bb10-c3ff-4d48-85f7-cbcdbe696daf@z13g2000prh.googlegroups.com> Message-ID: <918fdf7a-f235-486a-b1b4-04ff46192f04@42g2000prb.googlegroups.com> Philip Semanchuk wrote: > At PyCon 2010, Brandon Craig Rhodes presented about how dictionaries ? > work under the hood:http://python.mirocommunity.org/video/1591/pycon-2010-the-mighty-dict... > > I found that very informative. That's a fine presentation of hash tables in general and Python's choices in particular. Also highly informative, while easily readable, is the Objects/dictnotes.txt file in the Python source. Fine as those resources may be, the issue here stands. Most of my own Python issues turn out to be stupid mistakes, and the problem here might be on that level, but Emin seems to have worked his problem and gotten a bunch of stuff right. There is no good reason why constructing a 50 kilobyte dict should fail with a MemoryError while constructing 50 megabyte lists succeeds. -- --Bryan Olson From no.email at please.post Fri Jun 4 16:52:11 2010 From: no.email at please.post (kj) Date: Fri, 4 Jun 2010 20:52:11 +0000 (UTC) Subject: tallying occurrences in list References: <3746febb-3230-43ce-a61b-7831501268f5@k17g2000pro.googlegroups.com> <4c095aca$1@dnews.tpgi.com.au> Message-ID: Thank you all! ~K From john at castleamber.com Fri Jun 4 16:55:08 2010 From: john at castleamber.com (John Bokma) Date: Fri, 04 Jun 2010 15:55:08 -0500 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <1275560120.8775.6.camel@linux-yu4c.site> <4c0886f5$0$28659$c3e8da3@news.astraweb.com> <4c089852$0$28659$c3e8da3@news.astraweb.com> <87mxva7ja8.fsf@castleamber.com> Message-ID: <87vd9y5xhv.fsf@castleamber.com> "Alf P. Steinbach" writes: > * John Bokma, on 04.06.2010 20:19: >> Steven D'Aprano writes: >> >>> But the really sad thing is that you think that "bigger" automatically >>> equals "better". >> >> I don't think that was the point. >> >> Anyway, not everbody can pick a provider, there are plenty of places >> that have only one or maybe two. And if that's the choice and neither >> carries Usenet you have to pay for Usenet like I do. Note that I >> consider it well worth the 10 euros I pay for it. >> >> To me, it looks like the use of Usenet for text is on the >> decline. I've been away from Usenet for like a year or so and could see >> quite a difference. More and more ISPs in my experience are dropping >> Usenet from their services. Mind, I think that the number of users on >> Usenet (text only) still exceeds the number when I first used Usenet >> (back in the early 90's). But usage is on the decline as far as I can >> tell. On top of that I see people I know from Usenet now quite active on >> Stack Overflow and sister sites. >> >> Finally, I have to disagree with your disagreement (which is just a >> personal experience) based on my personal experience: it's harder to >> find an ISP that carries Usenet. And I have experience with, oh, just 3 >> countries where I have been living in for the past 10 years. > > True. > > While Usenet traffic is still exponentially increasing, most of that's > in binary groups, and it's spam. > > I think much of the decline of Usenet is correlated with an increase > of laws designed to limit free speech and support all kinds > surveillance. In my experience, as in people I know who've left Usenet, reasons for leaving Usenet are: 1) spam, number 1 culprit being Google. 2) newbies who don't care about posting guidelines 3) regulars in their ivory towers Other reasons: 4) MFA (Made for AdSense) sites that pretend to be a forum but just harvest all data from Usnet 5) trolls and kooks. > It started, as I see it, back in the early 90's with > Playboy attempting to sue anyone who used the Lena picture in photo > processing tests etc. (it's the standard image for that). They failed > in that particular endeavour, but did succeed in shutting down > thousands of sites worldwide displaying Playboy pictures. I know of the use of Lena. And to be honest, I agree with Playboy that they have the copyright. Some of the articles published on image processing end up behind a paywall or in a book. And I don't think the authors will be very happy if I convert their work in PDFs and offer it as free download on my site. Everybody wants a free ride until they have to create and maintain the rides in their own precious time with their own money. [...] > Until some replacement for Usenet appears, online discussion will in > general be effectively /local/, unknown to all but the parties > currently using a given web forum, and it will in general not be > archived. I like Stackoverflow and its sister sites a lot. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From john at castleamber.com Fri Jun 4 16:57:47 2010 From: john at castleamber.com (John Bokma) Date: Fri, 04 Jun 2010 15:57:47 -0500 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c0619e7$0$24606$426a74cc@news.free.fr> <80f1faae-146d-40b6-9075-613faf38a5f7@g39g2000pri.googlegroups.com> <87y6ev36ix.fsf@castleamber.com> <4c0952e6$1@dnews.tpgi.com.au> Message-ID: <87r5km5xdg.fsf@castleamber.com> Lie Ryan writes: > On 06/04/10 11:56, John Bokma wrote: >> Phlip writes: >> >>> On Jun 3, 3:20 pm, geremy condra wrote: >>> >>>>> You mean like how I never get answers, to my super-easy GED-level >>>>> questions, here??! >>>> >>>> I agree. This proves conclusively that a web forum is the right >>>> place for you. >>> >>> Ah, so you feel up to my "xsl for xmlrunner.py" question? >> >> Just jumping in the middle, but if you're looking for a web based forum >> where you can ask questions, check out Stack Overflow (and sister sites, >> depending on your question). I've noticed over the last couple of months >> that often things I google for, are answered on Stack Overflow. One >> thing that would've been nice to have on Usenet that I like is the >> ability to vote answers up or down. I think Usenet would've been a bit >> better with that option. > > Probably. A vote up/down feature tend to highlight popular problems, but > it also buries less popular problems that might have perfectly good > answers. Unless I misunderstand, the voting is for the replies, not for the questions. Or maybe the questions can be promoted to a queue, no idea. But that's not that different from questions posted to Usenet. The popular ones are asked often, the less popular ones once in a while, and might also not result in solutions. > I think Google Groups have 5-star-rating system? You might want > to check on that. Brrrr... no, I really prefer my Usenet via Gnus ;-). -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From john at castleamber.com Fri Jun 4 17:00:55 2010 From: john at castleamber.com (John Bokma) Date: Fri, 04 Jun 2010 16:00:55 -0500 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <1275560120.8775.6.camel@linux-yu4c.site> <4c0886f5$0$28659$c3e8da3@news.astraweb.com> <4c089852$0$28659$c3e8da3@news.astraweb.com> <87mxva7ja8.fsf@castleamber.com> <4c09576a$1@dnews.tpgi.com.au> Message-ID: <87mxva5x88.fsf@castleamber.com> Lie Ryan writes: > On 06/05/10 04:19, John Bokma wrote: >> Steven D'Aprano writes: >> >>> But the really sad thing is that you think that "bigger" automatically >>> equals "better". >> >> I don't think that was the point. >> >> Anyway, not everbody can pick a provider, there are plenty of places >> that have only one or maybe two. And if that's the choice and neither >> carries Usenet you have to pay for Usenet like I do. Note that I >> consider it well worth the 10 euros I pay for it. > > Isn't gmane available where you live? I've used gmane for newsgroups > that my local server doesn't carry. The only problem is that there's a > slight delay in opening new posts (0.5 seconds or so). I am aware of Gmane [1] but in their own words: "Gmane is a mailing list archive.", so it's not Usenet. It's a Usenet server which provides access to mailing lists. (A very cool idea). But I am with Individual.net and IMO very great service for just 10 euro. [1] http://johnbokma.com/mexit/2005/01/14/gmane-mail-to-news.html -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From emile at fenx.com Fri Jun 4 17:13:38 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 04 Jun 2010 14:13:38 -0700 Subject: Plotting in batch with no display In-Reply-To: References: Message-ID: On 6/4/2010 1:01 PM Hans Georg Schaathun said... > Admittedly not the strongest reason, but yet an important one, > for switching from Matlab to python/numpy/scipy/matplotlib, > is that Matlab is very cumbersome to run in batch. > > Now I discover that some of the matplotlib.pyplot functions > (incl. plot and contour) insist on opening an X11 window > (just like Matlab does). I found the same to be true when running OpenOffice in batch mode. Ultimately, the following was key to getting things going: at the shell: /usr/bin/vncserver :1 then from within python: XDISPLAY=':1' cmd='''cd /usr/ftp/CSV && DISPLAY=%s \ /usr/bin/soffice -norecover -nologo -nodefault \ "macro:///Standard.Module1.csvToXLS(%s)"''' \ % (XDISPLAY,csvfile) dummy = commands.getoutput(cmd) Then, if it doesn't run to conclusion, you can vnc to :1 and see where it's stalled out. HTH, Emile From aahz at pythoncraft.com Fri Jun 4 17:25:48 2010 From: aahz at pythoncraft.com (Aahz) Date: 4 Jun 2010 14:25:48 -0700 Subject: if, continuation and indentation References: Message-ID: In article , Tim Chase wrote: > >While it's not PEP material, I tend to use the coding standards I >learned working for Computer Sciences Corporation (10 yrs ago, so >things may have changed) that mandated 2 levels of indentation >for continued lines, turning the above into > > if (width == 0 and > height == 0 and > color == 'red' and > emphasis == 'strong' or > highlight> 100): > # or the closing "):" on this line, > # aligned with the previous line > raise ValueError("sorry, you lose") +1 -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From debatem1 at gmail.com Fri Jun 4 17:37:46 2010 From: debatem1 at gmail.com (geremy condra) Date: Fri, 4 Jun 2010 14:37:46 -0700 Subject: Python Forum In-Reply-To: <87vd9y5xhv.fsf@castleamber.com> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <1275560120.8775.6.camel@linux-yu4c.site> <4c0886f5$0$28659$c3e8da3@news.astraweb.com> <4c089852$0$28659$c3e8da3@news.astraweb.com> <87mxva7ja8.fsf@castleamber.com> <87vd9y5xhv.fsf@castleamber.com> Message-ID: On Fri, Jun 4, 2010 at 1:55 PM, John Bokma wrote: > I know of the use of Lena. And to be honest, I agree with Playboy that > they have the copyright. Some of the articles published on image > processing end up behind a paywall or in a book. And I don't think the > authors will be very happy if I convert their work in PDFs and offer it > as free download on my site. Everybody wants a free ride until they have > to create and maintain the rides in their own precious time with their > own money. Playboy permits use of the image for research, so unless you planned on getting permission from the authors first this is a totally invalid comparison. Geremy Condra From zyzhu2000 at gmail.com Fri Jun 4 17:51:39 2010 From: zyzhu2000 at gmail.com (GZ) Date: Fri, 4 Jun 2010 14:51:39 -0700 (PDT) Subject: Diff of Text References: Message-ID: <02f098c8-c2fc-4485-b748-1034373ad62c@q13g2000vbm.googlegroups.com> Hi Pat, On Jun 4, 2:55?pm, Patrick Maupin wrote: > On Jun 3, 9:54?pm, GZ wrote: > > > Hi All, > > > I am looking for an algorithm that can compare to source code files > > line by line and find the minimum diff. I have looked at the difflib > > included in python. The problem is that it is designed to make the > > diff results easier for humans to read, instead of minimize the size > > of the output differencial. I would like an algorithm implementation > > that gives the absolute minimum difference between the two files. > > > Can you help me? > > > Thanks, > > gz > > There's an "rsync.py" module in pypi -- one would think that would > have to solve that same problem... > > Regards, > Pat No, rsync does not solve my problem. I want a library that does unix 'diff' like function, i.e. compare two strings line by line and output the difference. Python's difflib does not work perfectly for me, because the resulting differences are pretty big. I would like an algorithm that generates the smallest differences. From cs at zip.com.au Fri Jun 4 18:05:20 2010 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 5 Jun 2010 08:05:20 +1000 Subject: bz2 module doesn't work properly with all bz2 files In-Reply-To: References: Message-ID: <20100604220520.GA8014@cskk.homeip.net> On 04Jun2010 12:53, Magdoll wrote: | I'm not sure what's causing this, but depending on the compression | program used, the bz2 module sometimes exits earlier. | | I used pbzip2 to compress my bz2 files and read through the file using | the bz2 module. The file descriptor always exits much earlier than | where the actual EOF is. If I use bzip2 instead of pbzip2 to compress | the files, then everything is fine. | | My files are generally big (several GBs) so decompressing them is not | a wise choice, and it is a little unfortunate that I can't use pbzip2 | because it's usually much faster than bz2. Have you tested the decompression or the problematic files with the bunzip2 command? Just to ensure the bug is with the python bz2 module and not with the pbzip2 utility? -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ A lot of people don't know the difference between a violin and a viola, so I'll tell you. A viola burns longer. - Victor Borge From john at castleamber.com Fri Jun 4 18:24:05 2010 From: john at castleamber.com (John Bokma) Date: Fri, 04 Jun 2010 17:24:05 -0500 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <1275560120.8775.6.camel@linux-yu4c.site> <4c0886f5$0$28659$c3e8da3@news.astraweb.com> <4c089852$0$28659$c3e8da3@news.astraweb.com> <87mxva7ja8.fsf@castleamber.com> <87vd9y5xhv.fsf@castleamber.com> Message-ID: <877hmefncq.fsf@castleamber.com> geremy condra writes: > On Fri, Jun 4, 2010 at 1:55 PM, John Bokma wrote: >> I know of the use of Lena. And to be honest, I agree with Playboy that >> they have the copyright. Some of the articles published on image >> processing end up behind a paywall or in a book. And I don't think the >> authors will be very happy if I convert their work in PDFs and offer it >> as free download on my site. Everybody wants a free ride until they have >> to create and maintain the rides in their own precious time with their >> own money. > > Playboy permits use of the image for research, OK, then I don't get the issue, and if you can enlighten me on it I will be thankful. > so unless you planned > on getting permission from the authors first this is a totally invalid > comparison. Clear. But my free ride remark stands IMO -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From invalid at invalid.invalid Fri Jun 4 18:24:38 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 4 Jun 2010 22:24:38 +0000 (UTC) Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <1275560120.8775.6.camel@linux-yu4c.site> <4c0886f5$0$28659$c3e8da3@news.astraweb.com> <4c089852$0$28659$c3e8da3@news.astraweb.com> <87mxva7ja8.fsf@castleamber.com> <4c09576a$1@dnews.tpgi.com.au> <87mxva5x88.fsf@castleamber.com> Message-ID: On 2010-06-04, John Bokma wrote: > Lie Ryan writes: > >> On 06/05/10 04:19, John Bokma wrote: >>> Steven D'Aprano writes: >>> >>>> But the really sad thing is that you think that "bigger" automatically >>>> equals "better". >>> >>> I don't think that was the point. >>> >>> Anyway, not everbody can pick a provider, there are plenty of places >>> that have only one or maybe two. And if that's the choice and neither >>> carries Usenet you have to pay for Usenet like I do. Note that I >>> consider it well worth the 10 euros I pay for it. >> >> Isn't gmane available where you live? I've used gmane for newsgroups >> that my local server doesn't carry. The only problem is that there's a >> slight delay in opening new posts (0.5 seconds or so). > > I am aware of Gmane [1] but in their own words: "Gmane is a mailing list > archive.", so it's not Usenet. It's a Usenet server which provides > access to mailing lists. (A very cool idea). No, it's not a Usenet server. It's a mailing-list gateway that provides access via NNTP. Usenet is a peer-to-peer system that trasfers articles around between servers. NNTP is a protocol often used to provide access to Usenet servers (Usenet was around long before NNTP). NNTP can be used to provide access to other things (as Gmane does). -- Grant From exarkun at twistedmatrix.com Fri Jun 4 18:27:33 2010 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Fri, 04 Jun 2010 22:27:33 -0000 Subject: Plotting in batch with no display In-Reply-To: References: Message-ID: <20100604222733.2139.1606259764.divmod.xquotient.41@localhost.localdomain> On 08:01 pm, h.schaathun at surrey.ac.uk wrote: >Admittedly not the strongest reason, but yet an important one, >for switching from Matlab to python/numpy/scipy/matplotlib, >is that Matlab is very cumbersome to run in batch. > >Now I discover that some of the matplotlib.pyplot functions >(incl. plot and contour) insist on opening an X11 window >(just like Matlab does). I would have preferred just to create >the plot straight on file. The extra window is a nuisance on my >laptop, it is deep-felt pain if I try to run it remotely. It fails >completely if I run it without any display at all. > >Oddly, the bar() function does not open a window by default. >I was very happy with that. It works exactly the way I want. >(Why isn't pyplot more consistent?) > >Is there something I have missed? Is it possible to create >standard 2D plots and contour plots without a display, writing >the graphics straight into a PDF file? It's possible to plot with matplotlib without a display. I'm not surprised you didn't figure out how, though, it's not all that obvious. Check out the matplotlib.use function. For example: import matplotlib matplotlib.use('agg') import pylab pylab.plot([1, 3, 5]) fig = file('foo.png', 'wb') pylab.savefig(fig, format='png') fig.close() This should work fine without a display. Jean-Paul From magdoll at gmail.com Fri Jun 4 18:32:47 2010 From: magdoll at gmail.com (Magdoll) Date: Fri, 4 Jun 2010 15:32:47 -0700 (PDT) Subject: bz2 module doesn't work properly with all bz2 files References: Message-ID: <79291259-8727-4342-be19-bed51ee5d328@k17g2000pro.googlegroups.com> On Jun 4, 3:05?pm, Cameron Simpson wrote: > On 04Jun2010 12:53, Magdoll wrote: > | I'm not sure what's causing this, but depending on the compression > | program used, the bz2 module sometimes exits earlier. > | > | I used pbzip2 to compress my bz2 files and read through the file using > | the bz2 module. The file descriptor always exits much earlier than > | where the actual EOF is. If I use bzip2 instead of pbzip2 to compress > | the files, then everything is fine. > | > | My files are generally big (several GBs) so decompressing them is not > | a wise choice, and it is a little unfortunate that I can't use pbzip2 > | because it's usually much faster than bz2. > > Have you tested the decompression or the problematic files with the > bunzip2 command? Just to ensure the bug is with the python bz2 module > and not with the pbzip2 utility? > -- > Cameron Simpson DoD#743http://www.cskk.ezoshosting.com/cs/ > > A lot of people don't know the difference between a violin and a viola, so > I'll tell you. ?A viola burns longer. ? - Victor Borge Yes. Decompressing them with either pbzip2 or bunzip2 are both fine. So the problem is not with pbzip2. From spyder1960 at yahoo.com Fri Jun 4 18:47:39 2010 From: spyder1960 at yahoo.com (Spyder42) Date: Fri, 04 Jun 2010 14:47:39 -0800 Subject: Missing DLL in win98 References: <0bsh06pilrfls0i3f473unhbee1j71pmbs@4ax.com> <1guh06tt177al7rqar55ab0aiif1ibim57@4ax.com> Message-ID: On Fri, 04 Jun 2010 14:03:48 -0400, Terry Reedy wrote: >On 6/4/2010 9:08 AM, Spyder42 wrote: >> On Fri, 04 Jun 2010 14:50:28 +0200, Christian Heimes > >>> Python 2.6 is not supported on Windows 98 and earlier. You need at least >>> Windows 2000 with a recent service pack. >>> >>> Christian >> >> So your response is either, you don't know if there is a fix, or 'No >> way in h377.' You couldn't figure out by my post that I already knew >> that? > >Get off your high horse. Dumping on volunteer helpers is a good way to >drive them away. > >It was not obvious, without closely reading your original post, and even >then it is not clear, that you *knew* than 2.6 was not supported on >Win98. You could have asked 'I know 2.6+ is not officially supported in >win98. Does anyone know a workaround other than upgrading windows or >sticking with 2.5?". *That* would have been clear. > >Terry Jan Reedy > I'm sorry, but if I asked where the nearest gas station was, I wouldn't expect someone to answer, "You can't get there because your out of gas." I had a specific question and I got a non-specific non-answer. If they didn't know, they should not have answered. >It was not obvious, without closely reading your original post... So it WAS obvious to anyone who was PAYING ATTENTION? Life is not a dress rehersal. If you don't get it right, things like the BP's oil spill, Chernobyl, and 3 mile island happen. Perhaps I'm being extreme, but computer programs underly our entire civilization today. Computers dump stock, and Billions are lost, needlessly affecting everyones life. Trains crash, boats sink, and psychos like me go off the deep end, because no-one is paying attention. L8r Spyder From drsalists at gmail.com Fri Jun 4 19:41:51 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 4 Jun 2010 16:41:51 -0700 Subject: getting MemoryError with dicts; suspect memory fragmentation In-Reply-To: References: Message-ID: On Thu, Jun 3, 2010 at 3:43 PM, Emin.shopper Martinian.shopper < emin.shopper at gmail.com> wrote: > Dear Experts, > > I am getting a MemoryError when creating a dict in a long running > process and suspect this is due to memory fragmentation. Any > suggestions would be welcome. Full details of the problem are below. > > I have a long running processing which eventually dies to a > MemoryError exception Here's something good about Python memory leaks: http://www.lshift.net/blog/2008/11/14/tracing-python-memory-leaks Just curious: What if you use a gdbm key-value store or treap instead of a builtin {} dictionary? gdbm is usually built in, and my treap module is here, as pure python or partial CPython+partial cython: http://stromberg.dnsalias.org/~dstromberg/treap/ The gdbm module would require your keys and values to be strings (unless you wrap it), but it should pretty much take dictionary-related Virtual Memory (VM) out of the picture by mostly storing your data to disk. One way of wrapping one would be to use my (UCI's) cachedb module, which does implicit to- and from-string conversions using functions you provide to its constructor, and allows you to control how many values to cache in VM: http://stromberg.dnsalias.org/~strombrg/cachedb.html The treap module should be able to store arbitrary objects in VM out of the box, and is much like a dictionary but implemented quite differently - its chief difference is a little memory _overhead_ (normally, maybe not this time due to the significantly different implementation details) in order to get the "dictionary's" objects always sorted in key order, and to store things as a (mostly!) self-balanced tree (it sacrifices fastidious balancing to get better average performance) with a heap invariant. Because it stores things as a balanced tree of discrete objects, it should be pretty clear that it's not looking for contiguous memory unless the backend CPython memory management does for some reason beyond dictionary specifics. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchichkov at gmail.com Fri Jun 4 20:01:14 2010 From: dchichkov at gmail.com (dmtr) Date: Fri, 4 Jun 2010 17:01:14 -0700 (PDT) Subject: An empty object with dynamic attributes (expando) References: <4c088911$0$28659$c3e8da3@news.astraweb.com> Message-ID: > Why does it have to be a one-liner? Is the Enter key on your keyboard > broken? Nah. I was simply looking for something natural and intuitive, like: m = object(); m.a = 1; Usually python is pretty good providing these natural and intuitive solutions. > You have a perfectly good solution: define a class, then instantiate it. > But if you need a one-liner (perhaps to win a game of code golf), then > this will work: > > >>> m = type('', (), {})() > >>> m.attribute = 2 Heh. Creating it dynamically. Ace. ;) -- Cheers, Dmitry From knny.myer at gmail.com Fri Jun 4 20:48:19 2010 From: knny.myer at gmail.com (Kenny Meyer) Date: Fri, 4 Jun 2010 17:48:19 -0700 (PDT) Subject: plac, the easiest command line arguments parser in the world References: <1d09462d-3de1-4e40-8cc7-c45e18cf0ffd@m4g2000vbl.googlegroups.com> Message-ID: On Jun 2, 12:37?am, Michele Simionato wrote: > I would like to announce to the world the first public release of > plac: > > ?http://pypi.python.org/pypi/plac > > Plac is a wrapper over argparse and works in all versions of > Python starting from Python 2.3 up to Python 3.1. > > With blatant immodesty, plac claims to be the easiest to use command > line arguments parser module in the Python world. Its goal is to > reduce the > learning curve of argparse from hours to minutes. It does so by > removing the need to build a command line arguments parser by hand: > actually it is smart enough to infer the parser from function > annotations. > > Here is a simple example (in Python 3) to wet your appetite: > > $ cat example.py > def main(arg: "required argument"): > ? ? "do something with arg" > ? ? print('Got %s' % arg) > > if __name__ == '__main__': > ? ? import plac; plac.call(main) # passes sys.argv[1:] to main > > $ python example.py -h > usage: example.py [-h] arg > > do something with arg > > positional arguments: > ? arg ? ? ? ? required argument > > optional arguments: > ? -h, --help ?show this help message and exit > > $ python example.py > usage: example.py [-h] arg > example.py: error: too few arguments > > $ ?python example.py arg > Got arg > > $ ?python example.py arg1 arg2 > usage: example.py [-h] arg > example.py: error: unrecognized arguments: arg2 > > You can find in the documentation a lot of other simple and not so > simple > examples: > > ?http://micheles.googlecode.com/hg/plac/doc/plac.html > > Enjoy! > > ? ? ? ? ? ? ?Michele Simionato > > P.S. answering an unspoken question: yes, we really needed yet > another > command line arguments parser! ;) I like this approach to command-line argument parsing! Thanks for sharing your work. From tjreedy at udel.edu Fri Jun 4 21:01:23 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 04 Jun 2010 21:01:23 -0400 Subject: An empty object with dynamic attributes (expando) In-Reply-To: References: <4c088911$0$28659$c3e8da3@news.astraweb.com> Message-ID: On 6/4/2010 8:01 PM, dmtr wrote: >> Why does it have to be a one-liner? Is the Enter key on your keyboard >> broken? > > Nah. I was simply looking for something natural and intuitive, like: m > = object(); m.a = 1; > Usually python is pretty good providing these natural and intuitive > solutions. As far as I can think of now, one cannot add attributes to *any* builtin-class instance, but can add attributes to any user class which does not have them disabled. >>> [].a = 3 Traceback (most recent call last): File "", line 1, in [].a = 3 AttributeError: 'list' object has no attribute 'a' >>> class L(list): pass >>> i = L(); i; i.a = 3; i.a [] 3 Terry Jan Reedy From tjreedy at udel.edu Fri Jun 4 21:06:49 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 04 Jun 2010 21:06:49 -0400 Subject: Python Forum In-Reply-To: References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <4c0891fc$0$28659$c3e8da3@news.astraweb.com> Message-ID: On 6/4/2010 3:04 PM, Emile van Sebille wrote: > On 6/4/2010 11:27 AM Terry Reedy said... >> On 6/4/2010 12:28 PM, Emile van Sebille wrote: >> >>> Is there now a non-email method of posting to this list? >> >> Google <==> comp.lang.python <==> python-list <==> >> gmane.comp.python.general >> >> where <==> is a bi-directional gateway. > > Yes -- I use gmane as well. But, IIRC, I needed to be on the mail list > in order for my responses to show up because MailMan is the primary back > end and I thought it's set to only accept posts from members. I think this somewhat depends on the list (admin settings) > Hence, my question. Aren't we all members posting (ultimately) > exclusively through email regardless of preferred reading interfaces? From lie.1296 at gmail.com Fri Jun 4 21:11:01 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 05 Jun 2010 11:11:01 +1000 Subject: Python Forum In-Reply-To: <87r5km5xdg.fsf@castleamber.com> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c0619e7$0$24606$426a74cc@news.free.fr> <80f1faae-146d-40b6-9075-613faf38a5f7@g39g2000pri.googlegroups.com> <87y6ev36ix.fsf@castleamber.com> <4c0952e6$1@dnews.tpgi.com.au> <87r5km5xdg.fsf@castleamber.com> Message-ID: <4c09a49e$1@dnews.tpgi.com.au> On 06/05/10 06:57, John Bokma wrote: > Lie Ryan writes: > >> On 06/04/10 11:56, John Bokma wrote: >>> Phlip writes: >>> >>>> On Jun 3, 3:20 pm, geremy condra wrote: >>>> >>>>>> You mean like how I never get answers, to my super-easy GED-level >>>>>> questions, here??! >>>>> >>>>> I agree. This proves conclusively that a web forum is the right >>>>> place for you. >>>> >>>> Ah, so you feel up to my "xsl for xmlrunner.py" question? >>> >>> Just jumping in the middle, but if you're looking for a web based forum >>> where you can ask questions, check out Stack Overflow (and sister sites, >>> depending on your question). I've noticed over the last couple of months >>> that often things I google for, are answered on Stack Overflow. One >>> thing that would've been nice to have on Usenet that I like is the >>> ability to vote answers up or down. I think Usenet would've been a bit >>> better with that option. >> >> Probably. A vote up/down feature tend to highlight popular problems, but >> it also buries less popular problems that might have perfectly good >> answers. > > Unless I misunderstand, the voting is for the replies, not for the > questions. Or maybe the questions can be promoted to a queue, no > idea. But that's not that different from questions posted to Usenet. The > popular ones are asked often, the less popular ones once in a while, and > might also not result in solutions. If you look at Stack Overflow, the highest voted questions are: - Hidden Features of C#? - What is the single most influential book every programmer should read? - What's your favorite "programmer" cartoon? - What is your best programmer joke? ... and so on many of them are nearly out-of-topic. >> I think Google Groups have 5-star-rating system? You might want >> to check on that. > > Brrrr... no, I really prefer my Usenet via Gnus ;-). From lie.1296 at gmail.com Fri Jun 4 21:37:26 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 05 Jun 2010 11:37:26 +1000 Subject: Diff of Text In-Reply-To: <02f098c8-c2fc-4485-b748-1034373ad62c@q13g2000vbm.googlegroups.com> References: <02f098c8-c2fc-4485-b748-1034373ad62c@q13g2000vbm.googlegroups.com> Message-ID: <4c09aacf$1@dnews.tpgi.com.au> On 06/05/10 07:51, GZ wrote: > Hi Pat, > > On Jun 4, 2:55 pm, Patrick Maupin wrote: >> On Jun 3, 9:54 pm, GZ wrote: >> >>> Hi All, >> >>> I am looking for an algorithm that can compare to source code files >>> line by line and find the minimum diff. I have looked at the difflib >>> included in python. The problem is that it is designed to make the >>> diff results easier for humans to read, instead of minimize the size >>> of the output differencial. I would like an algorithm implementation >>> that gives the absolute minimum difference between the two files. >> >>> Can you help me? >> >>> Thanks, >>> gz >> >> There's an "rsync.py" module in pypi -- one would think that would >> have to solve that same problem... >> >> Regards, >> Pat > > No, rsync does not solve my problem. > > I want a library that does unix 'diff' like function, i.e. compare two > strings line by line and output the difference. Python's difflib does > not work perfectly for me, because the resulting differences are > pretty big. I would like an algorithm that generates the smallest > differences. is n=0 not short enough? pprint.pprint(list(difflib.context_diff(s, t, n=0))) From steve at REMOVE-THIS-cybersource.com.au Fri Jun 4 22:06:18 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Jun 2010 02:06:18 GMT Subject: bz2 module doesn't work properly with all bz2 files References: Message-ID: <4c09b11a$0$28659$c3e8da3@news.astraweb.com> On Fri, 04 Jun 2010 12:53:26 -0700, Magdoll wrote: > I'm not sure what's causing this, but depending on the compression > program used, the bz2 module sometimes exits earlier. [...] The current bz2 module only supports files written as a single stream, and not multiple stream files. This is why the BZ2File class has no "append" mode. See this bug report: http://bugs.python.org/issue1625 Here's an example: >>> bz2.BZ2File('a.bz2', 'w').write('this is the first chunk of text') >>> bz2.BZ2File('b.bz2', 'w').write('this is the second chunk of text') >>> bz2.BZ2File('c.bz2', 'w').write('this is the third chunk of text') >>> # concatenate the files ... d = file('concate.bz2', 'w') >>> for name in "abc": ... ? ? f = file('%c.bz2' % name, 'rb') ... ? ? d.write(f.read()) ... >>> d.close() >>> >>> bz2.BZ2File('concate.bz2', 'r').read() 'this is the first chunk of text' Sure enough, BZ2File only sees the first chunk of text, but if I open it in (e.g.) KDE's Ark application, I see all the text. So this is a known bug, sorry. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jun 4 22:09:59 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Jun 2010 02:09:59 GMT Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <1275560120.8775.6.camel@linux-yu4c.site> <4c0886f5$0$28659$c3e8da3@news.astraweb.com> <4c089852$0$28659$c3e8da3@news.astraweb.com> Message-ID: <4c09b1f7$0$28659$c3e8da3@news.astraweb.com> On Fri, 04 Jun 2010 08:56:34 -0500, Jim Byrnes wrote: > I thought his point was they are big enough to have the resources to > offer newsgroups but don't. If I want fast internet I must use Comcast > and Comcast doesn't offer newsgroups either. Sadly is seems getting > access to newsgroups is getting harder and harder. I'm sorry for all you people who don't live in a place with a genuinely free market, and instead have to suffer with the lack of competition and poor service of a monopoly or duopoly masquerading as a free market. But *my* point was that your woes are not universal, and Usenet is alive and well. It might be declining, but it's a long, slow decline and, like Cobol, it will probably still be around a decade after the cool kids declared it dead. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Jun 4 22:14:07 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Jun 2010 02:14:07 GMT Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c0619e7$0$24606$426a74cc@news.free.fr> <80f1faae-146d-40b6-9075-613faf38a5f7@g39g2000pri.googlegroups.com> <87y6ev36ix.fsf@castleamber.com> <4c0952e6$1@dnews.tpgi.com.au> Message-ID: <4c09b2ef$0$28659$c3e8da3@news.astraweb.com> On Sat, 05 Jun 2010 05:22:21 +1000, Lie Ryan wrote: > Probably. A vote up/down feature tend to highlight popular problems, but > it also buries less popular problems that might have perfectly good > answers. I think Google Groups have 5-star-rating system? You might want > to check on that. I don't remember the URL, but I read an article about Yahoo Answers which explained that the Yahoo team started off with 5-star ratings for answers, but quickly discovered that most ratings were either 0 or 5, and so changed to a Vote Up/Down system. According to Yahoo's experience, the extra complexity just adds an illusionary sense of precision with no additional benefit. -- Steven From alfps at start.no Fri Jun 4 22:25:14 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 05 Jun 2010 04:25:14 +0200 Subject: An empty object with dynamic attributes (expando) In-Reply-To: References: <4c088911$0$28659$c3e8da3@news.astraweb.com> Message-ID: * Terry Reedy, on 05.06.2010 03:01: > On 6/4/2010 8:01 PM, dmtr wrote: >>> Why does it have to be a one-liner? Is the Enter key on your keyboard >>> broken? >> >> Nah. I was simply looking for something natural and intuitive, like: m >> = object(); m.a = 1; >> Usually python is pretty good providing these natural and intuitive >> solutions. > > As far as I can think of now, one cannot add attributes to *any* > builtin-class instance, but can add attributes to any user class which > does not have them disabled. > > >>> [].a = 3 > Traceback (most recent call last): > File "", line 1, in > [].a = 3 > AttributeError: 'list' object has no attribute 'a' > >>> class L(list): pass > > >>> i = L(); i; i.a = 3; i.a > [] > 3 > > Terry Jan Reedy You can add attributes to functions. I'm not sure, but I think it was you who once provided me with a reference to the relevant PEP (thanks!), so I guess it just slipped your mind on a late Friday night. :-) See my earlier reply in this thread regarding that. Regarding user defined classes, I gather that by "have them [attributes] disabled" you're including the case of a class with slots? There was an article recently in DDJ where the author seemed to be unaware of this, but I'm not going to pay for the privilege of commenting on articles. Cheers & hth., - Alf PS: How come that when I post a blog entry proving mathematically that the reader is really really smart, the number of views dropped like a stone? Huh. But OK, it was just a late-night posting, I couldn't sleep so I posted a bit of what I, late at night, thought was some funny or at least amusing philosophy... -- blog at From steve at REMOVE-THIS-cybersource.com.au Fri Jun 4 22:29:08 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Jun 2010 02:29:08 GMT Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <4c0891fc$0$28659$c3e8da3@news.astraweb.com> Message-ID: <4c09b674$0$28659$c3e8da3@news.astraweb.com> On Fri, 04 Jun 2010 02:29:58 -0400, D'Arcy J.M. Cain wrote: > On 04 Jun 2010 05:41:17 GMT > Steven D'Aprano wrote: >> Sure, a lot of those 1,800 posts are spam, but the spammers wouldn't >> waste their time if they didn't think there were people still on >> Usenet. > > Kidding, right? Cost to spam is virtually zero so the ROI is pretty > close to infinite no matter how many people they reach. What, you think the Russian mob hands out their botnets for free? Spam is a business. An evil, unethical, immoral, scum-sucking business, but still a business, and like all businesses, spammers care about cost and profit. The marginal cost of sending spam might be approaching zero, but the total cost isn't, and spammers try to maximise the number of eyeballs they reach while minimising the cost. If they weren't, they would still be using the same spam techniques from the 90s, instead of engaged in an arms race with anti-spam apps. This is why things like picture spam comes in waves. Every few months, some newbie spammer hits on the brilliant idea of putting his spam in a jpg image, carefully obfuscating it so that OCR software can't recognise the URL but humans can, pays his $200 (or whatever it is) to rent a botnet, and for two weeks everybody gets an uptick in spam because the anti-spam apps can't filter picture spam very well. And then they discover that the morons who buy from spammers aren't just stupid, they're lazy too. Nobody is going to type the URL into their browser, that's too much like actual work. So the spammer learns that his investment didn't make him any profit, and he tries something else, or gives up, and the picture spam disappears for a few more months until some other newbie fails to think things through. If there weren't people reading the spam on Usenet and buying whatever junk is being sold, the spammers would move on. -- Steven From john at castleamber.com Fri Jun 4 22:29:31 2010 From: john at castleamber.com (John Bokma) Date: Fri, 04 Jun 2010 21:29:31 -0500 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <1275560120.8775.6.camel@linux-yu4c.site> <4c0886f5$0$28659$c3e8da3@news.astraweb.com> <4c089852$0$28659$c3e8da3@news.astraweb.com> <87mxva7ja8.fsf@castleamber.com> <4c09576a$1@dnews.tpgi.com.au> <87mxva5x88.fsf@castleamber.com> Message-ID: <87d3w6yzxw.fsf@castleamber.com> Grant Edwards writes: > On 2010-06-04, John Bokma wrote: >> Lie Ryan writes: >> >>> On 06/05/10 04:19, John Bokma wrote: >>>> Steven D'Aprano writes: >>>> >>>>> But the really sad thing is that you think that "bigger" automatically >>>>> equals "better". >>>> >>>> I don't think that was the point. >>>> >>>> Anyway, not everbody can pick a provider, there are plenty of places >>>> that have only one or maybe two. And if that's the choice and neither >>>> carries Usenet you have to pay for Usenet like I do. Note that I >>>> consider it well worth the 10 euros I pay for it. >>> >>> Isn't gmane available where you live? I've used gmane for newsgroups >>> that my local server doesn't carry. The only problem is that there's a >>> slight delay in opening new posts (0.5 seconds or so). >> >> I am aware of Gmane [1] but in their own words: "Gmane is a mailing list >> archive.", so it's not Usenet. It's a Usenet server which provides >> access to mailing lists. (A very cool idea). > > No, it's not a Usenet server. OK, it's an NNTP server, but on the other hand I think one can argue that an NNTP server also implies Usenet since Usenet doesn't imply that all groups available on Usenet should be available, nor does it imply -- like you already mentioned below (snipped) -- how exactly that data arrives or that is has to be complete. Since this posting ends up on Gmane, I think it's correct to call Gmane part of Usenet, and hence, they're running a Usenet server. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From steve at REMOVE-THIS-cybersource.com.au Fri Jun 4 22:31:21 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Jun 2010 02:31:21 GMT Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <1275560120.8775.6.camel@linux-yu4c.site> <4c0886f5$0$28659$c3e8da3@news.astraweb.com> <4c089852$0$28659$c3e8da3@news.astraweb.com> <87mxva7ja8.fsf@castleamber.com> <87vd9y5xhv.fsf@castleamber.com> Message-ID: <4c09b6f8$0$28659$c3e8da3@news.astraweb.com> On Fri, 04 Jun 2010 15:55:08 -0500, John Bokma wrote: > "Alf P. Steinbach" writes: [...] >> It started, as I see it, back in the early 90's with Playboy attempting >> to sue anyone who used the Lena picture in photo processing tests etc. >> (it's the standard image for that). They failed in that particular >> endeavour, but did succeed in shutting down thousands of sites >> worldwide displaying Playboy pictures. > > I know of the use of Lena. And to be honest, I agree with Playboy that > they have the copyright. I don't think that anyone argues that Playboy don't own the copyright. What they don't own is the principle of fair use. > Some of the articles published on image > processing end up behind a paywall or in a book. Perhaps. So what? Publishing dozens of photos from Playboy isn't fair use. Publishing a single copy of Lena is. Fair use doesn't cease to be fair use if you put it in a book. > And I don't think the > authors will be very happy if I convert their work in PDFs and offer it > as free download on my site. Everybody wants a free ride until they have > to create and maintain the rides in their own precious time with their > own money. I'm sorry, Playboy took that photo of Lena, what, thirty years ago? In what possible sense do they have to maintain it? Do they have to photoshop out the wrinkles each year to maintain the photo's youthful appearance? -- Steven From john at castleamber.com Fri Jun 4 22:34:05 2010 From: john at castleamber.com (John Bokma) Date: Fri, 04 Jun 2010 21:34:05 -0500 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c0619e7$0$24606$426a74cc@news.free.fr> <80f1faae-146d-40b6-9075-613faf38a5f7@g39g2000pri.googlegroups.com> <87y6ev36ix.fsf@castleamber.com> <4c0952e6$1@dnews.tpgi.com.au> <87r5km5xdg.fsf@castleamber.com> <4c09a49e$1@dnews.tpgi.com.au> Message-ID: <878w6uyzqa.fsf@castleamber.com> Lie Ryan writes: > If you look at Stack Overflow, the highest voted questions are: > > - Hidden Features of C#? > - What is the single most influential book every programmer should read? > - What's your favorite "programmer" cartoon? > - What is your best programmer joke? > ... and so on > > many of them are nearly out-of-topic. What do you mean with out-of-topic? (off topic?) http://stackoverflow.com/questions/tagged/python But to be honest I mostly end up on Stack Overflow when I google for a specific problem, and most of the time I find a nice concise answer without much noise. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From john at castleamber.com Fri Jun 4 22:49:09 2010 From: john at castleamber.com (John Bokma) Date: Fri, 04 Jun 2010 21:49:09 -0500 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <1275560120.8775.6.camel@linux-yu4c.site> <4c0886f5$0$28659$c3e8da3@news.astraweb.com> <4c089852$0$28659$c3e8da3@news.astraweb.com> <4c09b1f7$0$28659$c3e8da3@news.astraweb.com> Message-ID: <874ohiyz16.fsf@castleamber.com> Steven D'Aprano writes: > On Fri, 04 Jun 2010 08:56:34 -0500, Jim Byrnes wrote: > >> I thought his point was they are big enough to have the resources to >> offer newsgroups but don't. If I want fast internet I must use Comcast >> and Comcast doesn't offer newsgroups either. Sadly is seems getting >> access to newsgroups is getting harder and harder. > > I'm sorry for all you people who don't live in a place with a genuinely > free market, If such a thing exists it still doesn't mean that each and every place where one can live has plenty of choice. Even in the Netherlands, where I am originally from, which is quite crowded there are plenty of places where the number of provider options are limited. But I don't think you should feel sorry for those people, because the majority is not interested in Usenet (well, the "text" part) and the few who do will find a way. On top of that, not every provider has the expertise to handle Usenet resulting in a very crappy service nobody cares about. > and instead have to suffer with the lack of competition and > poor service of a monopoly or duopoly masquerading as a free market. But > *my* point was that your woes are not universal, and Usenet is alive and > well. It might be declining, but it's a long, slow decline and, like > Cobol, it will probably still be around a decade after the cool kids > declared it dead. Well, I've noticed quite some groups I used to follow have become "dead" in less than a year, so while I have no doubt you're correct with the decade, I don't think there is much fun in being subscribed to 20 groups only to find one message a month :-D. I use email to stay in contact with some regulars of groups that indeed do have just one message / month. I doubt it has anything to do with being a cool kid or not. Some groups also dry up because the topic has been discussed to dead and/or it's easier to nowadays find the information on line somewhere else. And yet others, in my opinion, dry up because the people who are holding the fort are IMO sitting in ivory towers and have extremely little patience with newbies but are also somewhat tired with each other because they don't want to end up in the same discussion again. So, yeah, Usenet will be around for decades, I don't doubt it. I am convinced that in a decade from now the total number of users will still be higher than 20 years ago so it's far from dead then. But I guess that will make it only more so that one has to pay for access. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From tjreedy at udel.edu Fri Jun 4 23:13:32 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 04 Jun 2010 23:13:32 -0400 Subject: An empty object with dynamic attributes (expando) In-Reply-To: References: <4c088911$0$28659$c3e8da3@news.astraweb.com> Message-ID: On 6/4/2010 10:25 PM, Alf P. Steinbach wrote: >> As far as I can think of now, one cannot add attributes to *any* >> builtin-class instance, but can add attributes to any user class which >> does not have them disabled. >> >> >>> [].a = 3 >> Traceback (most recent call last): >> File "", line 1, in >> [].a = 3 >> AttributeError: 'list' object has no attribute 'a' >> >>> class L(list): pass >> >> >>> i = L(); i; i.a = 3; i.a >> [] >> 3 >> >> Terry Jan Reedy > > You can add attributes to functions. > > I'm not sure, but I think it was you who once provided me with a > reference to the relevant PEP (thanks!), so I guess it just slipped your > mind on a late Friday night. :-) Right on both counts. Function attributes are exceptions, and they were added after I learned Python. > Regarding user defined classes, I gather that by "have them [attributes] > disabled" you're including the case of a class with slots? Yes. or custom __setattr__ or something. tjr From zyzhu2000 at gmail.com Sat Jun 5 01:43:48 2010 From: zyzhu2000 at gmail.com (GZ) Date: Fri, 4 Jun 2010 22:43:48 -0700 (PDT) Subject: Diff of Text References: <02f098c8-c2fc-4485-b748-1034373ad62c@q13g2000vbm.googlegroups.com> <4c09aacf$1@dnews.tpgi.com.au> Message-ID: On Jun 4, 8:37?pm, Lie Ryan wrote: > On06/05/10 07:51, GZ wrote: > > > > > > > Hi Pat, > > > On Jun 4, 2:55 pm, Patrick Maupin wrote: > >> On Jun 3, 9:54 pm, GZ wrote: > > >>> Hi All, > > >>> I am looking for an algorithm that can compare to source code files > >>> line by line and find the minimum diff. I have looked at the difflib > >>> included in python. The problem is that it is designed to make the > >>> diff results easier for humans to read, instead of minimize the size > >>> of the output differencial. I would like an algorithm implementation > >>> that gives the absolute minimum difference between the two files. > > >>> Can you help me? > > >>> Thanks, > >>> gz > > >> There's an "rsync.py" module in pypi -- one would think that would > >> have to solve that same problem... > > >> Regards, > >> Pat > > > No, rsync does not solve my problem. > > > I want a library that does unix 'diff' like function, i.e. compare two > > strings line by line and output the difference. Python's difflib does > > not work perfectly for me, because the resulting differences are > > pretty big. I would like an algorithm that generates the smallest > > differences. > > is n=0 not short enough? > > pprint.pprint(list(difflib.context_diff(s, t, n=0))) This still does not do what I want it to do. It only displays the diff results in a different format. I want a different algorithm to generate a smaller diff -- in other words less differences From asdef at castor.oyl.com Sat Jun 5 03:11:15 2010 From: asdef at castor.oyl.com (asdef at castor.oyl.com) Date: Sat, 05 Jun 2010 09:11:15 +0200 Subject: Plotting in batch with no display References: Message-ID: <861vcmymwc.fsf@aiuole.stru.polimi.it> exarkun at twistedmatrix.com writes: > It's possible to plot with matplotlib without a display. I'm not > surprised you didn't figure out how, though, it's not all that > obvious. http://matplotlib.sourceforge.net/faq/howto_faq.html#plotting-howto ,---- | Generate images without having a window popup `---- From H.Schaathun at surrey.ac.uk Sat Jun 5 03:14:13 2010 From: H.Schaathun at surrey.ac.uk (Hans Georg Schaathun) Date: Sat, 5 Jun 2010 08:14:13 +0100 Subject: Plotting in batch with no display References: Message-ID: <53apd7-jee.ln1@nyquist.hawker03.mcs.surrey.ac.uk> On Fri, 04 Jun 2010 22:27:33 -0000, exarkun at twistedmatrix.com wrote: : It's possible to plot with matplotlib without a display. I'm not : surprised you didn't figure out how, though, it's not all that obvious. Thank you very much. That's a good start. Do you know of any good documentation on how to choose and use backends? What I find is very thin... : Check out the matplotlib.use function. For example: : : import matplotlib : matplotlib.use('agg') : import pylab : pylab.plot([1, 3, 5]) : fig = file('foo.png', 'wb') : pylab.savefig(fig, format='png') : fig.close() Raster graphics is not good enough, I will need a backend which does vector graphics and pdf output. AFAICS from the FAQ at sourceforge, agg only supports raster and png. Cairo supports vector graphics and PDF, but I cannot find any information about how/if it deals with X11... :-- George From vvw25w at googlemail.com Sat Jun 5 03:53:23 2010 From: vvw25w at googlemail.com (Steve) Date: Sat, 5 Jun 2010 00:53:23 -0700 (PDT) Subject: Replace in large text file ? Message-ID: <4e5b0acc-8073-480a-9a32-72f9c43f0adb@t10g2000yqg.googlegroups.com> I am new to Python and am wanting to replace characters in a very large text file.....6 GB In plain language what I wish to do is: Remove all comma's Replace all @ with comma's Save as a new file. Any of you clever people know the best way to do this......idiot guide please. Thanks Steve From lie.1296 at gmail.com Sat Jun 5 03:53:32 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 05 Jun 2010 17:53:32 +1000 Subject: Diff of Text In-Reply-To: References: <02f098c8-c2fc-4485-b748-1034373ad62c@q13g2000vbm.googlegroups.com> <4c09aacf$1@dnews.tpgi.com.au> Message-ID: <4c0a02f5$1@dnews.tpgi.com.au> On 06/05/10 15:43, GZ wrote: > On Jun 4, 8:37 pm, Lie Ryan wrote: >> On06/05/10 07:51, GZ wrote: >>> No, rsync does not solve my problem. >> >>> I want a library that does unix 'diff' like function, i.e. compare two >>> strings line by line and output the difference. Python's difflib does >>> not work perfectly for me, because the resulting differences are >>> pretty big. I would like an algorithm that generates the smallest >>> differences. >> >> is n=0 not short enough? >> >> pprint.pprint(list(difflib.context_diff(s, t, n=0))) > > This still does not do what I want it to do. It only displays the diff > results in a different format. I want a different algorithm to > generate a smaller diff -- in other words less differences No, I meant I was confirming that you already have turned off context lines (i.e. the n=0 part), right? Also, what's the nature of the changes? You might be able to minimize difflib's output by using word-based or character-based diff-ing instead of traditional line-based diff-ing. diff output is fairly compressable, so you might want to look at zipping the output. From lie.1296 at gmail.com Sat Jun 5 04:01:33 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 05 Jun 2010 18:01:33 +1000 Subject: Python Forum In-Reply-To: <878w6uyzqa.fsf@castleamber.com> References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c0619e7$0$24606$426a74cc@news.free.fr> <80f1faae-146d-40b6-9075-613faf38a5f7@g39g2000pri.googlegroups.com> <87y6ev36ix.fsf@castleamber.com> <4c0952e6$1@dnews.tpgi.com.au> <87r5km5xdg.fsf@castleamber.com> <4c09a49e$1@dnews.tpgi.com.au> <878w6uyzqa.fsf@castleamber.com> Message-ID: <4c0a04d7@dnews.tpgi.com.au> On 06/05/10 12:34, John Bokma wrote: > Lie Ryan writes: > >> If you look at Stack Overflow, the highest voted questions are: >> >> - Hidden Features of C#? >> - What is the single most influential book every programmer should read? >> - What's your favorite "programmer" cartoon? >> - What is your best programmer joke? >> ... and so on >> >> many of them are nearly out-of-topic. > > What do you mean with out-of-topic? (off topic?) yeah, "off-topic", that's the word. > http://stackoverflow.com/questions/tagged/python > > But to be honest I mostly end up on Stack Overflow when I google for a > specific problem, and most of the time I find a nice concise answer > without much noise. Same here. But the point is, since Google bypasses the voting system, that's why I don't see much added value in having a voting system. From gagsl-py2 at yahoo.com.ar Sat Jun 5 04:03:25 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 5 Jun 2010 01:03:25 -0700 (PDT) Subject: changing format of time duration. References: <11191764-f704-4f1e-9a0e-1fb9d174afa1@l6g2000vbo.googlegroups.com> <16748e83-2b7e-44f2-a581-d9a540365a84@k39g2000yqd.googlegroups.com> Message-ID: On 4 jun, 06:14, "G?nther Dietrich" wrote: > GabrielGenellina wrote: > >Try the strptime method with a suitable format, like this (untested): > >delta = now2-now1 > >delta.strftime('%H:%M:%S.%f') > > Throws an exception: > > |Traceback (most recent call last): > | ?File "", line 1, in > |AttributeError: 'datetime.timedelta' object has no attribute 'strftime' > > What seems logical, since the documentation doesn't mention an strftime > method for timedelta. You're right. Second try (still untested): def nice_timedelta_str(d): result = str(d) if result[1] == ':': result = '0' + result return result delta = now2-now1 print nice_timedelta_str(delta) -- Gabriel Genellina From steve at REMOVE-THIS-cybersource.com.au Sat Jun 5 04:04:12 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Jun 2010 08:04:12 GMT Subject: Diff of Text References: <02f098c8-c2fc-4485-b748-1034373ad62c@q13g2000vbm.googlegroups.com> <4c09aacf$1@dnews.tpgi.com.au> Message-ID: <4c0a04fc$0$28659$c3e8da3@news.astraweb.com> On Fri, 04 Jun 2010 22:43:48 -0700, GZ wrote: > This still does not do what I want it to do. It only displays the diff > results in a different format. I want a different algorithm to generate > a smaller diff -- in other words less differences Can you give a *short* example, showing the output from Python's diff and what you would prefer instead? -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Jun 5 04:06:41 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Jun 2010 08:06:41 GMT Subject: Replace in large text file ? References: <4e5b0acc-8073-480a-9a32-72f9c43f0adb@t10g2000yqg.googlegroups.com> Message-ID: <4c0a0591$0$28659$c3e8da3@news.astraweb.com> On Sat, 05 Jun 2010 00:53:23 -0700, Steve wrote: > I am new to Python and am wanting to replace characters in a very large > text file.....6 GB > In plain language what I wish to do is: > > Remove all comma's > Replace all @ with comma's > Save as a new file. input_file = open("some_huge_file.txt", "r") output_file = open("newfilename.txt", "w") for line in input_file: line = line.replace(",", "") line = line.replace("@", ",") output_file.write(line) output_file.close() input_file.close() -- Steve From gagsl-py2 at yahoo.com.ar Sat Jun 5 04:13:26 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 5 Jun 2010 01:13:26 -0700 (PDT) Subject: General questions - where & how References: <67A48378-C1B3-4C1B-9D46-CE1842774186@semanchuk.com> Message-ID: On 4 jun, 14:54, Terry Reedy wrote: > On 6/4/2010 1:35 PM, Philip Semanchuk wrote: > > On Jun 4, 2010, at 1:22 PM, Uriah Eisenstein wrote: > > >> I'm relatively new to Python and have a few questions. Frankly, it > >> took me a > >> while to find on python.org what seems like a suitable place to post my > >> questions. However, I'd like to check the archives and see if they > >> haven't > >> been discussed already... > > > I use Google's "site" keyword search. e.g. to search the archives for > > "banana": > >http://www.google.com/search?q=site%3Amail.python.org%2Fpipermail%2Fp... > > One can also search mailing lists mirrored and archived by gmanehttp://search.gmane.org/ > This is gmane.comp.python.general. There are about 200 other g.c.python > lists/groups that are more specialized. I have no idea about comparitive > performance. In addition, Google Groups mirrors this list too as http://groups.google.com/group/comp.lang.python/ -- Gabriel Genellina From jdk2588 at gmail.com Sat Jun 5 04:14:34 2010 From: jdk2588 at gmail.com (Jaideep Khandelwal) Date: Sat, 5 Jun 2010 13:44:34 +0530 Subject: Moving Pickle data to Store in a Postgresql Database Message-ID: Hi, I just need to know is there any existing module or library that could be used for storing pickle data fields into a Postgresql server database , I have found some answers to this about using with the SQlite3 for Python 2.5, but is it possible for Postgresql Server. ? Thanks Regards Jaideep -------------- next part -------------- An HTML attachment was scrubbed... URL: From magnus.lycka at gmail.com Sat Jun 5 04:30:40 2010 From: magnus.lycka at gmail.com (magnus.lycka at gmail.com) Date: Sat, 5 Jun 2010 01:30:40 -0700 (PDT) Subject: Python treats non-breaking space wrong? Message-ID: <5d11dc72-cf3e-4c18-8441-57e6f57a8854@d8g2000yqf.googlegroups.com> It seems that Python treats non-breaking space (\xa0) as a normal whitespace character, e.g. when splitting a string. See below: >>> s='hello\xa0there' >>> s.split() ['hello', 'there'] Surely this is not intended behaviour? From gagsl-py2 at yahoo.com.ar Sat Jun 5 04:47:46 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 5 Jun 2010 01:47:46 -0700 (PDT) Subject: Missing DLL in win98 References: <0bsh06pilrfls0i3f473unhbee1j71pmbs@4ax.com> <1guh06tt177al7rqar55ab0aiif1ibim57@4ax.com> Message-ID: <3ff1b81c-202f-48bc-b6e0-6534b7083728@i28g2000yqa.googlegroups.com> On 4 jun, 19:47, Spyder42 wrote: > On Fri, 04 Jun 2010 14:03:48 -0400, Terry Reedy > wrote: > >On 6/4/2010 9:08 AM, Spyder42 wrote: > >> On Fri, 04 Jun 2010 14:50:28 +0200, Christian Heimes > > >>> Python 2.6 is not supported on Windows 98 and earlier. You need at least > >>> Windows 2000 with a recent service pack. > >> So your response is either, you don't know if there is a fix, or 'No > >> way in h377.' You couldn't figure out by my post that I already knew > >> that? > > >It was not obvious, without closely reading your original post, and even > >then it is not clear, that you *knew* than 2.6 was not supported on > >Win98. You could have asked 'I know 2.6+ is not officially supported in > >win98. Does anyone know a workaround other than upgrading windows or > >sticking with 2.5?". *That* would have been clear. > > I had a specific question and I got a non-specific non-answer. > If they didn't know, they should not have answered. You didn't state your question as clearly as you appear to think. > >It was not obvious, without closely reading your original post... > > So it WAS obvious to anyone who was PAYING ATTENTION? It is not obvious to me at least, even after closely reading your post. All I can deduce from it is that you assumed you would have a better chance upgrading your OS, not that you *knew* your current OS was officially unsupported. Christian Heimes gave you the right answer, even if it was not the answer you expected. -- Gabriel Genellina From mskumar547 at gmail.com Sat Jun 5 04:50:57 2010 From: mskumar547 at gmail.com (***SNDX****) Date: Sat, 5 Jun 2010 01:50:57 -0700 (PDT) Subject: Computer Tricks,Untold Shortcuts and Important facts Message-ID: <0ad18d25-619e-4567-a269-75b82fc6c7a7@t34g2000prd.googlegroups.com> Know About Computer Tricks, Working Tricks, Untold Shortcuts and all Computer Facts .. . Visit my Website http://computertipsnfacts.blogspot.com http://amazingworld4all.blogspot.com Thank You, Santhosh... http://forexindianew.blogspot.com From steve at REMOVE-THIS-cybersource.com.au Sat Jun 5 04:59:16 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Jun 2010 08:59:16 GMT Subject: Python treats non-breaking space wrong? References: <5d11dc72-cf3e-4c18-8441-57e6f57a8854@d8g2000yqf.googlegroups.com> Message-ID: <4c0a11e4$0$14135$c3e8da3@news.astraweb.com> On Sat, 05 Jun 2010 01:30:40 -0700, magnus.lycka at gmail.com wrote: > It seems that Python treats non-breaking space (\xa0) as a normal > whitespace character, e.g. when splitting a string. See below: > >>>> s='hello\xa0there' >>>> s.split() > ['hello', 'there'] > > Surely this is not intended behaviour? Yes it is. str.split() breaks on whitespace, and \xa0 is whitespace according to the Unicode standard. To put it another way, str.split() is not a word- wrapping split. This has been reported before, and rejected as a won't- fix. http://mail.python.org/pipermail/python-bugs-list/2006-January/031531.html -- Steven From gagsl-py2 at yahoo.com.ar Sat Jun 5 05:38:12 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 5 Jun 2010 02:38:12 -0700 (PDT) Subject: reading help() - newbie question References: Message-ID: On 31 mayo, 07:19, Payal wrote: > When I type help(something) e.g. help(list), I see many methods like, > __methodname__(). Are these something special? How do I use them and why > put "__" around them? You may want to install and use "see", a human-friendly replacement of dir() So instead of this mess: py> dir(pencil_case) ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', ' __delslice__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__get item__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', ' __init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__ ', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__str__', 'a ppend', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse' , 'sort'] you get this instead: py> see(pencil_case) [] in + += * *= < <= == != > >= hash() help() iter() len() repr() reversed() str() .append() .count() .extend() .index() .insert() .pop() .remove() .reverse() .sort() For us mere mortals, it's a lot more readable. "see" is available at http://github.com/inky/see -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Jun 5 06:11:44 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 5 Jun 2010 03:11:44 -0700 (PDT) Subject: Py_single_input and the side-effects... References: <71e9afe5-f64e-4c2a-9c25-d814d13c7d46@t14g2000prm.googlegroups.com> <0d5415fc-d59b-42a2-99da-d1fd49c7a401@11g2000prv.googlegroups.com> Message-ID: On 31 mayo, 08:11, moerchendiser2k3 wrote: > you are right, Python still holds the last > reference. I just set a dummy and thats it :) > > Can you tell me where did you get the information from? Do you mean the _ variable? It's in the tutorial: http://docs.python.org/tutorial/introduction.html#using-python-as-a-calculator -- Gabriel Genellina From lie.1296 at gmail.com Sat Jun 5 07:24:34 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 05 Jun 2010 21:24:34 +1000 Subject: reading help() - newbie question In-Reply-To: References: Message-ID: <4c0a346b@dnews.tpgi.com.au> On 05/31/10 20:19, Payal wrote: > Hi, > I am trying to learn Python (again) and have some basic doubts which I > hope someone in the list can address. (English is not my first language and I > have no CS background except I can write decent shell scripts) > > When I type help(something) e.g. help(list), I see many methods like, > __methodname__(). Are these something special? How do I use them and why > put "__" around them? Yes, the double-underscore are hooks to the various python protocols. They defines, among all, operator overloading, class construction and initialization, iterator protocol, descriptor protocol, type-casting, etc. A typical usage of these double-underscore is to create a class that overrides these functions, e.g.: class Comparable(object): def __init__(self, value): self.value = value def __lt__(self, other): return self.value > other.value def __gt__(self, other): return self.value < other.value def __str__(self): return "Value: " + self.value You should never create your own double-underscore method, just override/use the ones that Python provide. > One more simple query. Many times I see something like this, > | D.iteritems() -> an iterator over the (key, value) items of D > What is this iterator they are talking about and how do I use these > methods because simly saying D.iteritems() does not work? > read about iterator protocol. Basically, the iterator protocol allows for-looping over a user-defined class (e.g. for emulating a collection). D.iteritems() returns an iterator object, which for-loop knows how to iterate over to generate the stream of (key, value) pairs. From michelparker at live.com Sat Jun 5 08:26:03 2010 From: michelparker at live.com (michel parker) Date: Sat, 5 Jun 2010 13:26:03 +0100 Subject: error in importing numpy Message-ID: Hi, I am using ubuntu 9.10 . I just installed python 2.6.1 in /opt/python2.6 for using it with wingide for debugging symbols. I also installed numpy in python 2.6.1 using -- prefix method. but when i import numpy i get following error : ImportError: undefined symbol: _PyUnicodeUCS4_IsWhitespace please help me. Thanks in advance. Michell _________________________________________________________________ Hotmail: Powerful Free email with security by Microsoft. https://signup.live.com/signup.aspx?id=60969 -------------- next part -------------- An HTML attachment was scrubbed... URL: From exarkun at twistedmatrix.com Sat Jun 5 09:28:54 2010 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Sat, 05 Jun 2010 13:28:54 -0000 Subject: error in importing numpy In-Reply-To: References: Message-ID: <20100605132854.1708.1709828625.divmod.xquotient.17@localhost.localdomain> On 12:26 pm, michelparker at live.com wrote: > >Hi, >I am using ubuntu 9.10 . I just installed python 2.6.1 in >/opt/python2.6 for using it with wingide for debugging symbols. I also >installed numpy in python 2.6.1 using -- prefix method. but when i >import numpy i get following error : > >ImportError: undefined symbol: _PyUnicodeUCS4_IsWhitespace >please help me. Your numpy is compiled for a UCS4 build of Python. But you have a UCS2 build of Python. Rebuild one of them to match up with the other. Jean-Paul From luke.leighton at gmail.com Sat Jun 5 09:42:44 2010 From: luke.leighton at gmail.com (lkcl) Date: Sat, 5 Jun 2010 06:42:44 -0700 (PDT) Subject: is there a way to warn about missing modules *without* running python? Message-ID: <992066fb-bdea-41be-9fa0-41f5e7904849@g19g2000yqc.googlegroups.com> folks, hi, although i know the answer to this question, i'm having difficulty explaining it, to a user on the pyjamas list. i was therefore wondering if somebody could also provide an answer, on this list, to which i can refer the user. to make it clear: the user is confused as to why the pyjamas compiler (which strictly speaking isn't actually a compiler it's a "language translator", translating from one dynamic language into another dynamic language, feature-for-feature, concept-for-concept) is _not_ making any effort to help or advise the user at *COMPILE TIME* when they make the mistake of trying to import a module that does not exist. they are confused as to why they have to go to all the trouble of executing the [translated] javascript code in a web browser engine, where web browser engines are known to be a complete pain as far as debugging is concerned, just to find out that they made a mistake in mis-naming an import module. in other words, they are confusing the concept of "python as a dynamic language" with the concept of "compiler in the traditional static- language-such-as-c-or-c++ sense". i've tried explaining that the answer is because this has absolutely ****-all to do with pyjamas, and has everything to do with the http://python.org programming language, but i'm not getting through to them. if someone could perhaps explain this (in a different way from me), in the context of "python the programming language" and "python the http://python.org interpreter", i.e. having absolutely nothing to do with pyjamas, i would be most grateful, and it would benefit that user's understanding of python. many thanks, l. ref: http://groups.google.com/group/pyjamas-dev/browse_thread/thread/64cf948082bfec52?hl=en_US From dodo_do_not_wake_up at yahoo.Fr Sat Jun 5 09:46:05 2010 From: dodo_do_not_wake_up at yahoo.Fr (Dodo) Date: Sat, 05 Jun 2010 15:46:05 +0200 Subject: Tkinter help - Why this behavior ? (py3) Message-ID: <4c0a5519$0$27584$ba4acef3@reader.news.orange.fr> Hi, let's consider this exemple : from tkinter import * from tkinter.ttk import * class First: def __init__(self): self.root = Tk() B = Button(self.root, command=self.op) B.pack() self.root.mainloop() def op(self): Second(self) print("print") class Second: def __init__(self, parent): root = Toplevel(parent.root) root.grab_set() root.mainloop() First() when I close the second window, the print is NOT executed. It's done when I close the first window. Why do it "freeze" my function? Dorian From steve at REMOVE-THIS-cybersource.com.au Sat Jun 5 10:16:05 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Jun 2010 14:16:05 GMT Subject: is there a way to warn about missing modules *without* running python? References: <992066fb-bdea-41be-9fa0-41f5e7904849@g19g2000yqc.googlegroups.com> Message-ID: <4c0a5c24$0$14135$c3e8da3@news.astraweb.com> On Sat, 05 Jun 2010 06:42:44 -0700, lkcl wrote: > to make it clear: the user is confused as to why the pyjamas compiler > (which strictly speaking isn't actually a compiler it's a "language > translator", translating from one dynamic language into another dynamic > language, feature-for-feature, concept-for-concept) is _not_ making any > effort to help or advise the user at *COMPILE TIME* when they make the > mistake of trying to import a module that does not exist. Just because a module doesn't exist at compile time doesn't mean it won't exist later on when the code is run. And visa versa: just because the module exists when pyjamas "compiles" the code doesn't mean it will still be there when you actually try to run the code. [...] > in other words, they are confusing the concept of "python as a dynamic > language" with the concept of "compiler in the traditional static- > language-such-as-c-or-c++ sense". Neither Python, nor Javascript (as far as I know -- I welcome corrections) do static linking. If your Python code relies on a library, that library must be there *at runtime*, or you will get an error. This is no different from C or C++ code using dynamic linking. This is very common in e.g. Windows applications that use DLLs. Python modules are, conceptually speaking, like DLLs. They are loaded at runtime, not at compile time. This has many advantages over static linking, but some disadvantages as well. -- Steven From no.email at nospam.invalid Sat Jun 5 10:46:51 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 05 Jun 2010 07:46:51 -0700 Subject: Replace in large text file ? References: <4e5b0acc-8073-480a-9a32-72f9c43f0adb@t10g2000yqg.googlegroups.com> Message-ID: <7xljattu3o.fsf@ruckus.brouhaha.com> Steve writes: > Remove all comma's > Replace all @ with comma's > Save as a new file. The simplest way is just copy the file one character at a time, making replacements to commas and @'s as stated. That will be a bit slow (especially in Python) but if you only have to do it once, just wait it out. From gabriele.lanaro at gmail.com Sat Jun 5 11:24:55 2010 From: gabriele.lanaro at gmail.com (Gabriele Lanaro) Date: Sat, 5 Jun 2010 17:24:55 +0200 Subject: Replace in large text file ? In-Reply-To: <7xljattu3o.fsf@ruckus.brouhaha.com> References: <4e5b0acc-8073-480a-9a32-72f9c43f0adb@t10g2000yqg.googlegroups.com> <7xljattu3o.fsf@ruckus.brouhaha.com> Message-ID: A module designed to do this is fileinput: http://docs.python.org/library/fileinput.html The approach is the same as the other except that it's in the standard library. 2010/6/5 Paul Rubin > Steve writes: > > Remove all comma's > > Replace all @ with comma's > > Save as a new file. > > The simplest way is just copy the file one character at a time, making > replacements to commas and @'s as stated. That will be a bit slow > (especially in Python) but if you only have to do it once, just wait it > out. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Sat Jun 5 11:35:42 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 05 Jun 2010 16:35:42 +0100 Subject: Replace in large text file ? In-Reply-To: <4c0a0591$0$28659$c3e8da3@news.astraweb.com> References: <4e5b0acc-8073-480a-9a32-72f9c43f0adb@t10g2000yqg.googlegroups.com> <4c0a0591$0$28659$c3e8da3@news.astraweb.com> Message-ID: <4C0A6ECE.4040408@mrabarnett.plus.com> Steven D'Aprano wrote: > On Sat, 05 Jun 2010 00:53:23 -0700, Steve wrote: > >> I am new to Python and am wanting to replace characters in a very large >> text file.....6 GB >> In plain language what I wish to do is: >> >> Remove all comma's >> Replace all @ with comma's >> Save as a new file. > > > input_file = open("some_huge_file.txt", "r") > output_file = open("newfilename.txt", "w") > for line in input_file: > line = line.replace(",", "") > line = line.replace("@", ",") > output_file.write(line) > output_file.close() > input_file.close() > I'd probably process it in larger chunks: CHUNK_SIZE = 1024 ** 2 # 1MB at a time input_file = open("some_huge_file.txt", "r") output_file = open("newfilename.txt", "w") while True: chunk = input_file.read(CHUNK_SIZE) if not chunk: break chunk = chunk.replace(",", "") chunk = chunk.replace("@", ",") output_file.write(chunk) output_file.close() input_file.close() From usernet at ilthio.net Sat Jun 5 12:10:01 2010 From: usernet at ilthio.net (Tim Harig) Date: Sat, 5 Jun 2010 16:10:01 +0000 (UTC) Subject: Plotting in batch with no display References: <53apd7-jee.ln1@nyquist.hawker03.mcs.surrey.ac.uk> Message-ID: On 2010-06-05, Hans Georg Schaathun wrote: > Raster graphics is not good enough, I will need a backend which > does vector graphics and pdf output. AFAICS from the FAQ at > sourceforge, agg only supports raster and png. Cairo supports > vector graphics and PDF, but I cannot find any information about > how/if it deals with X11... 1. I am not familiar with matlab; but, I have written python programs that generate plots using GNUplot (which can create PDFs). There are python modules available for working with GNUplot or you can open it yourself under a subprocess and send it commands through a pipe. GNUplot allows you to save files directly and does not therefore require X. 2. If you can generate a raster file with Matlab, you can use ImageMagick (which has python bindings or could be execed directly) or other conversion software to convert the file to whatever format you choose. 3. Depending on your requirements, you could generate a plot using postscript. Postscript is easy to convert directly to PDF as the two are closely related. As postscript is a powerful language itself you can actually write the graphing routines in postscript and use python to simply embed the data into the postscript. From alfps at start.no Sat Jun 5 13:07:43 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 05 Jun 2010 19:07:43 +0200 Subject: Tkinter help - Why this behavior ? (py3) In-Reply-To: <4c0a5519$0$27584$ba4acef3@reader.news.orange.fr> References: <4c0a5519$0$27584$ba4acef3@reader.news.orange.fr> Message-ID: * Dodo, on 05.06.2010 15:46: > Hi, > > let's consider this exemple : > > from tkinter import * > from tkinter.ttk import * > > class First: > def __init__(self): > self.root = Tk() > B = Button(self.root, command=self.op) > B.pack() > > self.root.mainloop() > > def op(self): > Second(self) > print("print") > > > class Second: > def __init__(self, parent): > root = Toplevel(parent.root) > root.grab_set() > > root.mainloop() > > > First() > > > > when I close the second window, the print is NOT executed. It's done > when I close the first window. > Why do it "freeze" my function? First, sorry about Thunderbird 3.x messing up the quoting of the code. Don't know what they did to introduce all those bugs, but anyway, Thunderbird 3.x is an example that even seasoned programmers introduce an unbelievable number of bugs, I think mostly just by repeating code patterns blindly. In your code above you're doing as the TB programmers presumably did, repeating a code pattern that you've seen has worked, without fully grokking it. The call to 'mainloop' enters a loop. A button press causes your callback to be invoked from within that loop, but your code then enters a new 'mainloop'. Don't. Except for modal dialogs the single top level 'mainloop' suffices (all it does is to dispatch "messages" to "handlers", such as your button press callback). So, just place a single call to 'mainloop' at the end of your program. Remove the calls in 'First' and 'Second'. Cheers & hth., - Alf -- blog at From strombrg at gmail.com Sat Jun 5 13:14:13 2010 From: strombrg at gmail.com (Dan Stromberg) Date: Sat, 5 Jun 2010 17:14:13 +0000 (UTC) Subject: FIle transfer over network - with Pyro? References: <20100603200515.1988.953489959.divmod.xquotient.17@localhost.localdomain> Message-ID: On Thu, 03 Jun 2010 20:05:15 +0000, exarkun wrote: > On 06:58 pm, strombrg at gmail.com wrote: >>On Jun 3, 10:47?am, Nathan Huesken wrote: >>>Hi, >>> >>>I am writing a network application which needs from time to time do >>>file transfer (I am writing the server as well as the client). For >>>simple network messages, I use pyro because it is very comfortable. >>>But I suspect, that doing a file transfer is very inefficient over >>>pyro, am I right (the files are pretty big)? >>> >>>I somehow need to ensure, that the client requesting a file transfer is >>>the same client getting the file. So some sort of authentication is >>>needed. >>> >>>What library would you use to do the file transfer? Regards, >>>Nathan >> >>I've never used Pyro, but for a fast network file transfer in Python, >>I'd probably use the socket module directly, with a cache oblivious >>algorithm: >> http://en.wikipedia.org/wiki/Cache-oblivious_algorithm >> >>It doesn't use sockets, it uses files, but I recently did a Python >>progress meter application that uses a cache oblivious algorithm that >>can get over 5 gigabits/second throughput (that's without the network in >>the picture, though if it were used on 10 Gig-E with a suitable >>transport it could probably do nearly that), on a nearly-modern PC >>running Ubuntu with 2 cores It's at: >> http://stromberg.dnsalias.org/~strombrg/gprog/ . > > This seems needlessly complicated. Do you have a hard drive that can > deliver 5 gigabits/second to your application? More than likely not. Most such programs aren't optimized well for one machine, let alone adapting well to the cache-related specifics of about any transfer - so the thing you're using to measure performance, instead becomes the bottleneck itself. I don't think I'd use an oral thermometer that gave a patient a temporarily higher fever, and it'd be nice if I didn't have to retune the thermometer for each patient, too. Besides, it's a _conceptually_ simple algorithm - keep the n best- performing block sizes, and pick the best one historically for subsequent writes, trying a different, random blocksize once in a while even if things are going well with the current blocksize. It's actually something I learned about as an undergrad from a favorite professor, who was a little insistent that hard coding a "good" block size for the specifics of a single machine was short sighted when you care about performance, as code almost always moves to a different machine (or a different disk, or a different network peer) eventually. Come to think of it, she taught two of my 3 algorithms classes. Naturally, she also said that you shouldn't tune for performance unnecessarily. > A more realistic answer is probably to use something based on HTTP. This > solves a number of real-world problems, like the exact protocol to use > over the network, and detecting network issues which cause the transfer > to fail. It also has the benefit that there's plenty of libraries > already written to help you out. Didn't the OP request something fast? HTTP code is prone to be "optimized" for small transfers (if that), as most of the web is small files. OP: I should mention: If you're on gigabit or better, you probably should speak with your sysadmin about enabling Jumbo Frames and Path MTU Discovery - otherwise, even a cache oblivious algorithm likely won't be able to help much - the CPU would likely get pegged too early. If, on the other hand, you only care about 10BaseT speeds, or perhaps even 100BaseT speeds, HTTP would probably be fine (a typical CPU today can keep up with that fine), especially if you're doing a single transfer at a time. From john at castleamber.com Sat Jun 5 13:38:22 2010 From: john at castleamber.com (John Bokma) Date: Sat, 05 Jun 2010 12:38:22 -0500 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c0619e7$0$24606$426a74cc@news.free.fr> <80f1faae-146d-40b6-9075-613faf38a5f7@g39g2000pri.googlegroups.com> <87y6ev36ix.fsf@castleamber.com> <4c0952e6$1@dnews.tpgi.com.au> <87r5km5xdg.fsf@castleamber.com> <4c09a49e$1@dnews.tpgi.com.au> <878w6uyzqa.fsf@castleamber.com> <4c0a04d7@dnews.tpgi.com.au> Message-ID: <87mxv94bxt.fsf@castleamber.com> Lie Ryan writes: > On 06/05/10 12:34, John Bokma wrote: [..] >> http://stackoverflow.com/questions/tagged/python >> >> But to be honest I mostly end up on Stack Overflow when I google for a >> specific problem, and most of the time I find a nice concise answer >> without much noise. > > Same here. But the point is, since Google bypasses the voting system, > that's why I don't see much added value in having a voting system. There is also voting on the answers ;-). -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From victorsubervi at gmail.com Sat Jun 5 13:52:43 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Sat, 5 Jun 2010 13:52:43 -0400 Subject: Another MySQL Question In-Reply-To: <4c080600$0$1654$742ec2ed@news.sonic.net> References: <4c080600$0$1654$742ec2ed@news.sonic.net> Message-ID: On Thu, Jun 3, 2010 at 4:09 PM, John Nagle wrote: > The real problem with this is not the Python. It's the approach > to SQL. What's going on here is that you have some collection of > named options that come in from some external source, and you're > trying to handle that by dynamically constructing the table schema. > > It would be easier to store the "option" values in a separate > table, with something like > > CREATE TABLE temp01 ( > entryid BIGINT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY, > Store VARCHAR(40) NOT NULL, > PatientID VARCHAR(40) NOT NULL, > ProdID VARCHAR(40) NOT NULL, > Pkg VARCHAR(10) NOT NULL) > ENGINE=INNODB; > > CREATE TABLE ouroptions ( > FOREIGN KEY (parententry) REFERENCES temp01(entryid) > ON DELETE CASCADE, > optionname VARCHAR(40) NOT NULL, > optionvalue VARCHAR(40) NOT NULL) > ENGINE=INNODB; > > This creates two tables which are locked together. For any entry > in "temp01", you can create any "option" entries you need in "ouroptions". > If you delete the entry in "temp01", the related "options" entries will go > away. > (That's what ON DELETE CASCADE does.) When inserting, insert the record in > temp01 first, then the recrods in "ouroptions", in a single transaction. > > Incidentally, if you don't specify some indices, lookups will > take a very long time. > Your solution is very elegant; however, the application here is inappropriate. I'd been contemplating creating a temp table like you suggest, but in this application, there is only need for one table. However, you've given me an idea that will no doubt come in helpful in the future ;) Thanks, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From thatiparthysreenivas at gmail.com Sat Jun 5 13:55:21 2010 From: thatiparthysreenivas at gmail.com (Sreenivas Reddy Thatiparthy) Date: Sat, 5 Jun 2010 10:55:21 -0700 (PDT) Subject: tallying occurrences in list References: Message-ID: <8be2c826-208e-4c1c-bf36-e0afdd7bf937@y6g2000pra.googlegroups.com> On Jun 4, 11:14?am, kj wrote: > Task: given a list, produce a tally of all the distinct items in > the list (for some suitable notion of "distinct"). > > Example: if the list is ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', > 'c', 'a'], then the desired tally would look something like this: > > [('a', 4), ('b', 3), ('c', 3)] > > I find myself needing this simple operation so often that I wonder: > > 1. is there a standard name for it? > 2. is there already a function to do it somewhere in the Python > ? ?standard library? > > Granted, as long as the list consists only of items that can be > used as dictionary keys (and Python's equality test for hashkeys > agrees with the desired notion of "distinctness" for the tallying), > then the following does the job passably well: > > def tally(c): > ? ? t = dict() > ? ? for x in c: > ? ? ? ? t[x] = t.get(x, 0) + 1 > ? ? return sorted(t.items(), key=lambda x: (-x[1], x[0])) > > But, of course, if a standard library solution exists it would be > preferable. ?Otherwise I either cut-and-paste the above every time > I need it, or I create a module just for it. ?(I don't like either > of these, though I suppose that the latter is much better than the > former.) > > So anyway, I thought I'd ask. :) > > ~K How about this one liner, if you prefer them; set([(k,yourList.count(k)) for k in yourList]) From no.email at nospam.invalid Sat Jun 5 14:00:25 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 05 Jun 2010 11:00:25 -0700 Subject: tallying occurrences in list References: <8be2c826-208e-4c1c-bf36-e0afdd7bf937@y6g2000pra.googlegroups.com> Message-ID: <7xvd9xuzpi.fsf@ruckus.brouhaha.com> Sreenivas Reddy Thatiparthy writes: > How about this one liner, if you prefer them; > set([(k,yourList.count(k)) for k in yourList]) That has a rather bad efficiency problem if the list is large. From tjreedy at udel.edu Sat Jun 5 15:24:55 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 05 Jun 2010 15:24:55 -0400 Subject: is there a way to warn about missing modules *without* running python? In-Reply-To: <992066fb-bdea-41be-9fa0-41f5e7904849@g19g2000yqc.googlegroups.com> References: <992066fb-bdea-41be-9fa0-41f5e7904849@g19g2000yqc.googlegroups.com> Message-ID: On 6/5/2010 9:42 AM, lkcl wrote: > if someone could perhaps explain this (in a different way from me), in > the context of "python the programming language" and "python the > http://python.org interpreter", i.e. having absolutely nothing to do > with pyjamas, i would be most grateful, and it would benefit that > user's understanding of python. I do not know the background of your user, but here is my try: Loading a Python module at runtime is like loading a song, picture, or web page. An import statement is like a web page link. If the name of the resource is misspelled, or if the resource is not available when requested, it cannot be loaded and the requesting progran can only report an error. ImportError is equivalent to http's "40x: not found" message. A web link that works one time may not work another time. Terry Jan Reedy From victorsubervi at gmail.com Sat Jun 5 16:17:55 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Sat, 5 Jun 2010 16:17:55 -0400 Subject: Where's the List? Message-ID: Hi; I have this: for order in order_details: store = order[0] prodid = order[1] pkg = order[2] quantity = order[3] if 'PatientID' in order_fields: patientID = order[4] try: option_values = order[5:] except TypeError: option_values = [] sql = 'insert into orders%s values (Null, %s)' % (store, ", ".join("%s" * (4 + len(option_values)))) cursor.execute(sql, tuple([pkg, prodid, tmpTable, quantity] + option_values)) else: patientID = '' try: option_values = order[4:] except TypeError: option_values = [] sql = 'insert into orders%s values (Null, %s)' % (store, ", ".join("%s" * (4 + len(option_values)))) # cursor.execute(sql, tuple([pkg, prodid, tmpTable, quantity, order[4], order[5]])) cursor.execute(sql, tuple([pkg, prodid, tmpTable, quantity] + option_values)) It throws this error: *TypeError*: can only concatenate list (not "tuple") to list args = ('can only concatenate list (not "tuple") to list',) Where's the list? They're both tuples in that last line of code. TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Sat Jun 5 16:30:18 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 05 Jun 2010 22:30:18 +0200 Subject: Where's the List? References: Message-ID: Victor Subervi wrote: > Where's the list? They're both tuples in that last line of code. > for order in order_details: > store = order[0] > prodid = order[1] > pkg = order[2] > quantity = order[3] > if 'PatientID' in order_fields: > patientID = order[4] > try: > option_values = order[5:] > except TypeError: > option_values = [] Here... > sql = 'insert into orders%s values (Null, %s)' % (store, ", > ".join("%s" * (4 + len(option_values)))) > cursor.execute(sql, tuple([pkg, prodid, tmpTable, quantity] + > option_values)) > else: > patientID = '' > try: > option_values = order[4:] > except TypeError: > option_values = [] there... > sql = 'insert into orders%s values (Null, %s)' % (store, ", > ".join("%s" * (4 + len(option_values)))) > # cursor.execute(sql, tuple([pkg, prodid, tmpTable, quantity, > order[4], order[5]])) > cursor.execute(sql, tuple([pkg, prodid, tmpTable, quantity] + > option_values)) > > It throws this error: > > *TypeError*: can only concatenate list (not "tuple") to list > args = ('can only concatenate list (not "tuple") to list',) everywhere? From emile at fenx.com Sat Jun 5 16:31:08 2010 From: emile at fenx.com (Emile van Sebille) Date: Sat, 05 Jun 2010 13:31:08 -0700 Subject: Where's the List? In-Reply-To: References: Message-ID: On 6/5/2010 1:17 PM Victor Subervi said... > cursor.execute(sql, tuple([pkg, prodid, tmpTable, quantity] + > option_values)) > > It throws this error: > > *TypeError*: can only concatenate list (not "tuple") to list > args = ('can only concatenate list (not "tuple") to list',) > > Where's the list? They're both tuples in that last line of code. No they're not. That's what the error is saying. From debatem1 at gmail.com Sat Jun 5 16:34:45 2010 From: debatem1 at gmail.com (geremy condra) Date: Sat, 5 Jun 2010 13:34:45 -0700 Subject: FIle transfer over network - with Pyro? In-Reply-To: References: <20100603200515.1988.953489959.divmod.xquotient.17@localhost.localdomain> Message-ID: On Sat, Jun 5, 2010 at 10:14 AM, Dan Stromberg wrote: >> A more realistic answer is probably to use something based on HTTP. This >> solves a number of real-world problems, like the exact protocol to use >> over the network, and detecting network issues which cause the transfer >> to fail. ?It also has the benefit that there's plenty of libraries >> already written to help you out. > > Didn't the OP request something fast? Nope. He pointed out that pyro is not efficient and asked what libraries we would use. OP: HTTP is a reasonable choice unless you need really extreme performance. Geremy Condra From apt.shansen at gmail.com Sat Jun 5 16:52:15 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sat, 5 Jun 2010 13:52:15 -0700 Subject: Where's the List? In-Reply-To: References: Message-ID: On Sat, Jun 5, 2010 at 1:17 PM, Victor Subervi wrote: > option_values = [] > Here you create a list. You also can get option_values by slicing your 'order' variable, and I assume that is actually producing a tuple. Otherwise, you wouldn't get the error you're getting. Either way, you go on to do some strangeness: cursor.execute(sql, tuple([pkg, prodid, tmpTable, quantity] + > option_values)) > I'm not at all sure why you're building a list, adding option_values to it, then trying to convert it all into a tuple. That's sorta a lot of wasted conversion going on. Splitting that single line up into multiple lines to clarify exactly what is going on: foo1 = [pkg, prodid, tmpTable, quantity] foo2 = foo1 + option_values foo3 = tuple(my_list) cur.execute(sql, foo3) Although its all on one line, those three separate actions are done in that order when said line is executed. The problem is on foo2. During the execution of foo2, my_list -- a list, not a tuple -- is there that you created, and you're adding option_values to it. The problem: option_values is a tuple, and you can't add a tuple to the end of a list. Why, you may ask? Because Python isn't sure what the result should be in such a case: a mutable list, or an immutable tuple? The operations "foo1.extend(option_values)" or foo1 += option_values would make it very clear that you're just adding stuff to the end of an existing list. But a + b returns a /new/ object, and Python won't guess if you want it to be a list or a tuple. Now, that said. The fix is easy. Broken down: foo1 = [pkg, prodid, tmpTable, quantity] foo2 = foo1 + list(option_values) cur.execute(sql, foo2) Alternately: foo1 = (pkg, prodid, tmpTable, quantity) foo2 = foo1 + option_values cur.execute(sql, foo2) And then condensed back into a single line: cur.execute(sql, [pkg, prodid, tmpTable, quantity] + list(option_values)) Or: cur.execute(sql, (pkg, prodid, tmpTable, quantity) + option_values) I removed the explicit conversion-to-tuple in the first, because... you don't need to. Execute takes a sequence. It doesn't have to be a tuple. A list is fine. In the second one, I just build my first arguments as a tuple instead of as a list, and then add option_values to it... You'll just have to go up top and do: option_values = () In both places where you currently use []. As you can't add a list to a tuple anymore then a tuple to a list, for the same reasons. HTH, --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From travis+ml-python at subspacefield.org Sat Jun 5 17:14:58 2010 From: travis+ml-python at subspacefield.org (travis+ml-python at subspacefield.org) Date: Sat, 5 Jun 2010 14:14:58 -0700 Subject: pythonic web markup languages & templating systems & site generators Message-ID: <20100605211458.GK5634@subspacefield.org> I started to review static blog-like HTML generators, and found myself overwhelmed with how many there were. I narrowed it down to pythonic ones, and then realized I had to pick a markup language and templating language, of which there are several pythonic implementations... The results of my inquiry (still ongoing) are here: http://www.subspacefield.org/~travis/static_blog_generators.html It's a little disorganized, but does represent a fair amount of work, and might be a nice intro for a python programmer who isn't up to his neck in web authoring tools. Suggestions on how to organize it are welcome. Of course, while writing it, I was struck by how much I actually needed one of these systems to write the reviews of the systems :-) writing raw HTML is teh suck. -- A Weapon of Mass Construction My emails do not have attachments; it's a digital signature that your mail program doesn't understand. | http://www.subspacefield.org/~travis/ If you are a spammer, please email john at subspacefield.org to get blacklisted. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From john at castleamber.com Sat Jun 5 17:21:40 2010 From: john at castleamber.com (John Bokma) Date: Sat, 05 Jun 2010 16:21:40 -0500 Subject: pythonic web markup languages & templating systems & site generators References: Message-ID: <874ohhkwez.fsf@castleamber.com> travis+ml-python at subspacefield.org writes: > systems to write the reviews of the systems :-) writing raw HTML > is teh suck. You might want to check out: http://code.google.com/p/zen-coding/ And thanks for your work, marked, and will read it later. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From lie.1296 at gmail.com Sat Jun 5 18:25:10 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 06 Jun 2010 08:25:10 +1000 Subject: reading help() - newbie question In-Reply-To: <4c0a346b@dnews.tpgi.com.au> References: <4c0a346b@dnews.tpgi.com.au> Message-ID: <4c0acf43$1@dnews.tpgi.com.au> On 06/05/10 21:24, Lie Ryan wrote: > On 05/31/10 20:19, Payal wrote: >> Hi, >> I am trying to learn Python (again) and have some basic doubts which I >> hope someone in the list can address. (English is not my first language and I >> have no CS background except I can write decent shell scripts) >> >> When I type help(something) e.g. help(list), I see many methods like, >> __methodname__(). Are these something special? How do I use them and why >> put "__" around them? > > Yes, the double-underscore are hooks to the various python protocols. > They defines, among all, operator overloading, class construction and > initialization, iterator protocol, descriptor protocol, type-casting, etc. > > A typical usage of these double-underscore is to create a class that > overrides these functions, e.g.: > > class Comparable(object): > def __init__(self, value): > self.value = value > def __lt__(self, other): > return self.value > other.value > def __gt__(self, other): > return self.value < other.value > def __str__(self): > return "Value: " + self.value > > You should never create your own double-underscore method, just > override/use the ones that Python provide. Ok, I just read what I wrote again and I noticed that the example isn't complete enough to illustrate what I'm talking about, so: class Comparable(object): def __init__(self, value): self.value = value def __lt__(self, other): return self.value > other.value def __gt__(self, other): return self.value < other.value def __str__(self): return "Value: " + self.value a = Comparable(10) # a.value = 10 b = Comparable(20) # b.value = 20 # the < operator calls __lt__ special method and this # prints False, because a.value > other.value is False print a < b # prints "Value: 10" since 'print' statement calls str() builtin # function which calls __str__ to turn objects into a string print a From alan.isaac at gmail.com Sat Jun 5 18:44:43 2010 From: alan.isaac at gmail.com (Alan G Isaac) Date: Sat, 05 Jun 2010 18:44:43 -0400 Subject: modify XMP data (Python/Windows) Message-ID: I want to modify XMP data for a bunch of JPEG files, using Python if possible, on Windows. I expected PIL would support this. But no? I found the Python XMP Toolkit http://www.spacetelescope.org/static/projects/python-xmp-toolkit/docs/installation.html#requirements but no reports of successful use on Windows. I found Chilkat's XMP library http://www.chilkatsoft.com/python-xmp.asp but it is not open source and I found no encouraging reviews. Is there a Python package providing functinonality comparable to Image::ExifTool (perl)? Thanks, Alan Isaac From psdasilva.nospam at netcabonospam.pt Sat Jun 5 19:03:24 2010 From: psdasilva.nospam at netcabonospam.pt (Paulo da Silva) Date: Sun, 06 Jun 2010 00:03:24 +0100 Subject: Handling text lines from files with some (few) starnge chars Message-ID: <4c0ad7bc$0$23684$a729d347@news.telepac.pt> I need to read text files and process each line using string comparisions and regexp. I have a python2 program that uses .readline to read each line as a string. Then, processing it was a trivial job. With python3 I got error messagew like: File "./pp1.py", line 93, in RL line=inf.readline() File "/usr/lib64/python3.1/codecs.py", line 300, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf8' codec can't decode bytes in position 4963-4965: invalid data How do I handle this? If I use .read from an open as binary file I got a object. Then how do I handle it? Reg exps, comparisions with strings, ?... Thanks for any help. From timr at probo.com Sat Jun 5 19:36:38 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 05 Jun 2010 16:36:38 -0700 Subject: problems with CSV module References: Message-ID: <1pnl06plqjlq5mjbn4ic52dagihnl0708t@4ax.com> Carlos Grohmann wrote: > >Hi all, I'm using csv to read text files, and its working fine, except >in two cases: > >- when there is only one line of text (data) in the file >- when there is a blank line after the last data line > dialect = csv.Sniffer().sniff(sample) # Check for file format with >sniffer. csv.Sniffer uses heuristics to try to guess what the file format is. In order for those heuristics to work, the file must contain a sufficient number of lines, and the lines must actually have information that allows it to tell the difference between formats. It has been my experience that csv.Sniffer is NEVER worth the trouble. You know what the format is. Just embed the dialect yourself. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From clp2 at rebertia.com Sat Jun 5 19:41:55 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 5 Jun 2010 16:41:55 -0700 Subject: Handling text lines from files with some (few) starnge chars In-Reply-To: <4c0ad7bc$0$23684$a729d347@news.telepac.pt> References: <4c0ad7bc$0$23684$a729d347@news.telepac.pt> Message-ID: On Sat, Jun 5, 2010 at 4:03 PM, Paulo da Silva wrote: > I need to read text files and process each line using string > comparisions and regexp. > > I have a python2 program that uses .readline to read each > line as a string. Then, processing it was a trivial job. > > With python3 I got error messagew like: > File "./pp1.py", line 93, in RL > ? ?line=inf.readline() > ?File "/usr/lib64/python3.1/codecs.py", line 300, in decode > ? ?(result, consumed) = self._buffer_decode(data, self.errors, final) > UnicodeDecodeError: 'utf8' codec can't decode bytes in position > 4963-4965: invalid data > > How do I handle this? Specify the encoding of the text when opening the file using the `encoding` parameter. For Windows-1252 for example: your_file = open("path/to/file.ext", 'r', encoding='cp1252') Cheers, Chris -- http://blog.rebertia.com From jenn.duerr at gmail.com Sat Jun 5 19:47:11 2010 From: jenn.duerr at gmail.com (noydb) Date: Sat, 5 Jun 2010 16:47:11 -0700 (PDT) Subject: save xls to csv/dbf without Excel/win32com.client Message-ID: Is there a way to save a .xls file (the first worksheet) as a .dbf or .csv without opening an instance of Excel with win32com.client (been awhile, is this the best module these days for v2.5)? In case a computer does not have Excel (2007) installed. From python at bdurham.com Sat Jun 5 19:49:29 2010 From: python at bdurham.com (python at bdurham.com) Date: Sat, 05 Jun 2010 19:49:29 -0400 Subject: Handling text lines from files with some (few) starnge chars In-Reply-To: References: <4c0ad7bc$0$23684$a729d347@news.telepac.pt> Message-ID: <1275781769.24456.1378658215@webmail.messagingengine.com> Chris, > Specify the encoding of the text when opening the file using the `encoding` parameter. For Windows-1252 for example: > > your_file = open("path/to/file.ext", 'r', encoding='cp1252') This looks similar to the codecs module's functionality. Do you know if the codecs module is still required in Python 3.x? Thank you, Malcolm From zyzhu2000 at gmail.com Sat Jun 5 21:20:04 2010 From: zyzhu2000 at gmail.com (GZ) Date: Sat, 5 Jun 2010 18:20:04 -0700 (PDT) Subject: vector addition Message-ID: Hi, I am looking for a fast internal vector representation so that (a1,b2,c1)+(a2,b2,c2)=(a1+a2,b1+b2,c1+c2). So I have a list l = ['a'a,'bb','ca','de'...] I want to count all items that start with an 'a', 'b', and 'c'. What I can do is: count_a = sum(int(x[1]=='a') for x in l) count_b = sum(int(x[1]=='b') for x in l) count_c = sum(int(x[1]=='c') for x in l) But this loops through the list three times, which can be slow. I'd like to have something like this: count_a, count_b, count_c = sum( (int(x[1]=='a',int(x[1]=='b',int(x[1]=='c') for x in l) I hesitate to use numpy array, because that will literally create and destroy a ton of the arrays, and is likely to be slow. From psdasilva.nospam at netcabonospam.pt Sat Jun 5 21:24:18 2010 From: psdasilva.nospam at netcabonospam.pt (Paulo da Silva) Date: Sun, 06 Jun 2010 02:24:18 +0100 Subject: Handling text lines from files with some (few) starnge chars In-Reply-To: References: <4c0ad7bc$0$23684$a729d347@news.telepac.pt> Message-ID: <4c0af8c2$0$23685$a729d347@news.telepac.pt> Em 06-06-2010 00:41, Chris Rebert escreveu: > On Sat, Jun 5, 2010 at 4:03 PM, Paulo da Silva > wrote: ... > > Specify the encoding of the text when opening the file using the > `encoding` parameter. For Windows-1252 for example: > > your_file = open("path/to/file.ext", 'r', encoding='cp1252') > OK! This fixes my current problem. I used encoding="iso-8859-15". This is how my text files are encoded. But what about a more general case where the encoding of the text file is unknown? Is there anything like "autodetect"? From python.list at tim.thechases.com Sat Jun 5 21:31:23 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 05 Jun 2010 20:31:23 -0500 Subject: save xls to csv/dbf without Excel/win32com.client In-Reply-To: References: Message-ID: <4C0AFA6B.2070901@tim.thechases.com> On 06/05/2010 06:47 PM, noydb wrote: > Is there a way to save a .xls file (the first worksheet) as a .dbf > or .csv without opening an instance of Excel with win32com.client > (been awhile, is this the best module these days for v2.5)? In case a > computer does not have Excel (2007) installed. Use the "xlrd" module[1] ############################ import csv import xlrd FILE_NAME = 'example.xls' wb = xlrd.open_workbook(FILE_NAME) for name in wb.sheet_names(): out = file('%s.csv' % name, 'wb') writer = csv.writer(out) sheet = wb.sheet_by_name(name) for row in xrange(sheet.nrows): writer.writerow([ sheet.cell_value(row, col) for col in xrange(sheet.ncols) ]) out.close() ############################# You say you only want the first sheet, so adjust accordingly. -tkc [1] http://pypi.python.org/pypi/xlrd/ From zyzhu2000 at gmail.com Sat Jun 5 21:32:21 2010 From: zyzhu2000 at gmail.com (GZ) Date: Sat, 5 Jun 2010 18:32:21 -0700 (PDT) Subject: Diff of Text References: <02f098c8-c2fc-4485-b748-1034373ad62c@q13g2000vbm.googlegroups.com> <4c09aacf$1@dnews.tpgi.com.au> <4c0a02f5$1@dnews.tpgi.com.au> Message-ID: Hi Lie, On Jun 5, 2:53?am, Lie Ryan wrote: > On 06/05/10 15:43, GZ wrote: > > > > > > > On Jun 4, 8:37 pm, Lie Ryan wrote: > >> On06/05/10 07:51, GZ wrote: > >>> No, rsync does not solve my problem. > > >>> I want a library that does unix 'diff' like function, i.e. compare two > >>> strings line by line and output the difference. Python's difflib does > >>> not work perfectly for me, because the resulting differences are > >>> pretty big. I would like an algorithm that generates the smallest > >>> differences. > > >> is n=0 not short enough? > > >> pprint.pprint(list(difflib.context_diff(s, t, n=0))) > > > This still does not do what I want it to do. It only displays the diff > > results in a different format. I want a different algorithm to > > generate a smaller diff -- in other words less differences > > No, I meant I was confirming that you already have turned off context > lines (i.e. the n=0 part), right? > > Also, what's the nature of the changes? You might be able to minimize > difflib's output by using word-based or character-based diff-ing instead > of traditional line-based diff-ing. > > diff output is fairly compressable, so you might want to look at zipping > the output.- Hide quoted text - > > - Show quoted text - Thanks for your response. The verboseness of the format is not really my problem and I only care about line by line comparison for now. Let me think of a better way to express what I mean by a "smaller diff." After I diff the two strings, I will have something like this: AAA - BBB + CCC + DDD - EEE It means the first line does not change, the second line is replaced by the third line, the forth line is new, and the fifth line is deleted. I define the "smallness" of the diff algorithm as "the sum of the total number of minuses and pluses". In my above example, it is 4 (two minuses and 2 pluses). Note that no matter what format we use to represent the diff, this number is the same. Python's difflib does not really minimize this number. It tries to make this number small, but also tries to yield matches that ?look right? to people at the cost of increasing this number. (http:// docs.python.org/library/difflib.html). What I am looking for is an algo that can really minimize this number. From ben+python at benfinney.id.au Sat Jun 5 21:42:00 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 06 Jun 2010 11:42:00 +1000 Subject: Diff of Text References: <02f098c8-c2fc-4485-b748-1034373ad62c@q13g2000vbm.googlegroups.com> <4c09aacf$1@dnews.tpgi.com.au> <4c0a02f5$1@dnews.tpgi.com.au> Message-ID: <871vcl9btj.fsf@benfinney.id.au> GZ writes: > Let me think of a better way to express what I mean by a "smaller > diff." After I diff the two strings, I will have something like this: > > AAA > - BBB > + CCC > + DDD > - EEE > > It means the first line does not change, the second line is replaced > by the third line, the forth line is new, and the fifth line is > deleted. Are you drawing a distinction between: * ?line FOO is replaced by line BAR? * ?line FOO is deleted, line BAR is added? Your wording seems to make that distinction, but I don't see how it's useful or meaningful in a discussion about diff. Are they not exactly the same? -- \ ?Injustice is relatively easy to bear; what stings is justice.? | `\ ?Henry L. Mencken | _o__) | Ben Finney From clp2 at rebertia.com Sat Jun 5 21:54:05 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 5 Jun 2010 18:54:05 -0700 Subject: vector addition In-Reply-To: References: Message-ID: On Sat, Jun 5, 2010 at 6:20 PM, GZ wrote: > Hi, > > I am looking for a fast internal vector representation so that > (a1,b2,c1)+(a2,b2,c2)=(a1+a2,b1+b2,c1+c2). > > So I have a list > > l = ['a'a,'bb','ca','de'...] > > I want to count all items that start with an 'a', 'b', and 'c'. > > What I can do is: > > count_a = sum(int(x[1]=='a') for x in l) > count_b = sum(int(x[1]=='b') for x in l) > count_c = sum(int(x[1]=='c') for x in l) > > But this loops through the list three times, which can be slow. I don't really get how that relates to vectors or why you'd use that representation, and it looks like you're forgotten that Python uses 0-based indexing, but anyway, here's my crack at something more efficient: from collections import defaultdict cared_about = set('abc') letter2count = defaultdict(int) for item in l: initial = item[0] if initial in cared_about: letter2count[initial] += 1 count_a = letter2count['a'] count_b = letter2count['b'] count_c = letter2count['c'] Cheers, Chris -- http://blog.rebertia.com From python at mrabarnett.plus.com Sat Jun 5 22:01:00 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 06 Jun 2010 03:01:00 +0100 Subject: vector addition In-Reply-To: References: Message-ID: <4C0B015C.6010204@mrabarnett.plus.com> GZ wrote: > Hi, > > I am looking for a fast internal vector representation so that > (a1,b2,c1)+(a2,b2,c2)=(a1+a2,b1+b2,c1+c2). > > So I have a list > > l = ['a'a,'bb','ca','de'...] > > I want to count all items that start with an 'a', 'b', and 'c'. > > What I can do is: > > count_a = sum(int(x[1]=='a') for x in l) > count_b = sum(int(x[1]=='b') for x in l) > count_c = sum(int(x[1]=='c') for x in l) > > But this loops through the list three times, which can be slow. > > I'd like to have something like this: > count_a, count_b, count_c = > sum( (int(x[1]=='a',int(x[1]=='b',int(x[1]=='c') for x in l) > > I hesitate to use numpy array, because that will literally create and > destroy a ton of the arrays, and is likely to be slow. > If you want to do vector addition then numpy is the way to go. However, first you could try: from collections import defaultdict counts = defaultdict(int) for x in l: counts[x[0]] += 1 (Note that in Python indexes are zero-based.) From dchichkov at gmail.com Sat Jun 5 22:07:32 2010 From: dchichkov at gmail.com (dmtr) Date: Sat, 5 Jun 2010 19:07:32 -0700 (PDT) Subject: An empty object with dynamic attributes (expando) References: <4c088911$0$28659$c3e8da3@news.astraweb.com> Message-ID: <86beb1fe-36ec-4a89-b926-3bb227c09a6f@g39g2000pri.googlegroups.com> Right. >>> m = lambda:expando >>> m.myattr = 1 >>> print m.myattr 1 -- Cheers, Dmitry From benjamin at python.org Sat Jun 5 22:08:32 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 5 Jun 2010 21:08:32 -0500 Subject: [RELEASE] Python 2.7 release candidate 1 released Message-ID: On behalf of the Python development team, I'm effusive to announce the first release candidate of Python 2.7. Python 2.7 is scheduled (by Guido and Python-dev) to be the last major version in the 2.x series. However, 2.7 will have an extended period of bugfix maintenance. 2.7 includes many features that were first released in Python 3.1. The faster io module, the new nested with statement syntax, improved float repr, set literals, dictionary views, and the memoryview object have been backported from 3.1. Other features include an ordered dictionary implementation, unittests improvements, a new sysconfig module, and support for ttk Tile in Tkinter. For a more extensive list of changes in 2.7, see http://doc.python.org/dev/whatsnew/2.7.html or Misc/NEWS in the Python distribution. To download Python 2.7 visit: http://www.python.org/download/releases/2.7/ While this is a preview release and is thus not suitable for production use, we strongly encourage Python application and library developers to test the release with their code and report any bugs they encounter to: http://bugs.python.org/ This helps ensure that those upgrading to Python 2.7 will encounter as few bumps as possible. 2.7 documentation can be found at: http://docs.python.org/2.7/ Enjoy! -- Benjamin Peterson Release Manager benjamin at python.org (on behalf of the entire python-dev team and 2.7's contributors) From davea at ieee.org Sat Jun 5 22:09:03 2010 From: davea at ieee.org (Dave Angel) Date: Sat, 05 Jun 2010 22:09:03 -0400 Subject: Diff of Text In-Reply-To: References: <02f098c8-c2fc-4485-b748-1034373ad62c@q13g2000vbm.googlegroups.com> <4c09aacf$1@dnews.tpgi.com.au> <4c0a02f5$1@dnews.tpgi.com.au> Message-ID: <4C0B033F.1040804@ieee.org> GZ wrote: > >>>>> I want a library that does unix 'diff' like function, i.e. compare two >>>>> strings line by line and output the difference. Python's difflib does >>>>> not work perfectly for me, because the resulting differences are >>>>> pretty big. I would like an algorithm that generates the smallest >>>>> differences. >>>>> >> > Thanks for your response. > > The verboseness of the format is not really my problem and I only care > about line by line comparison for now. > > Let me think of a better way to express what I mean by a "smaller > diff." After I diff the two strings, I will have something like this: > > AAA > - BBB > + CCC > + DDD > - EEE > > It means the first line does not change, the second line is replaced > by the third line, the forth line is new, and the fifth line is > deleted. > > I define the "smallness" of the diff algorithm as "the sum of the > total number of minuses and pluses". In my above example, it is 4 (two > minuses and 2 pluses). Note that no matter what format we use to > represent the diff, this number is the same. > > Python's difflib does not really minimize this number. It tries to > make this number small, but also tries to yield matches that ?look > right? to people at the cost of increasing this number. (http:// > docs.python.org/library/difflib.html). > > What I am looking for is an algo that can really minimize this number. > > The - lines aren't needed, any more than the context lines are needed, so that will typically cut your results in half. But perhaps the real algorithm you're describing is one that permits lines to be moved as well as inserted and deleted. If you then consider that information to be free (it's not part of the measure you're specifying), you may do best with the following algorithm: Scan the two files looking for lines that appear exactly once in each file. Consider those lines the first invariants, and everything else a potential change. Now, starting with each pair (which I call a bridge between islands), look at the line previous and the line following, and if either or both are also matched, expand the two islands to include them. As an island grows to butt up against another island, merge them. Now, each bridge is a "move" operation, and every line left over in either file is either a plus or a minus, an insert or a delete. For most editing transactions, there will be relatively few of these. For example, if three functions were reordered, from A, B, C, to A, C, B, there would be no plus or minus lines at all. DaveA From aaron.watters at gmail.com Sat Jun 5 22:14:00 2010 From: aaron.watters at gmail.com (Aaron Watters) Date: Sat, 5 Jun 2010 19:14:00 -0700 (PDT) Subject: Announcing: WHIFF 1.0 Message-ID: <9bef6481-1da7-489c-b6cc-1d6ad918dd20@l6g2000vbo.googlegroups.com> WHIFF 1.0 RELEASED WHIFF 1.0 is the first stable release of WHIFF intended to be production ready. PROJECT PAGE: http://whiff.sourceforge.net/ DOCUMENTATION: http://whiffdoc.appspot.com DOWNLOAD: https://sourceforge.net/projects/whiff/ REPOSITORY: http://code.google.com/p/whiff/source/checkout WHIFF [WSGI HTTP Integrated Filesystem Frames] is a collection of support services for Python/WSGI Web applications which allows applications to be composed by "dropping" dynamic pages into container directories. This mode of development will be familiar to developers who have created PHP applications, vanilla CGI scripts, Apache/modpy Publisher applications, JSP pages, or static web content. WHIFF 1.0 adds support for Guarded Resources to implement information access control in web applications. http://whiffdoc.appspot.com/docs/W1100_2400.AuthorizedResources In addition to a number of bugfixes and minor enhancements the release also includes from previous releases: Test drive http://whiffdoc.appspot.com/docs/W1100_0500.TestDrive Mako template support http://whiffdoc.appspot.com/docs/W1100_1075.MakoGrading Drop down menus middlewares http://whiffdoc.appspot.com/docs/W1100_1300.menus AJAX callback support http://whiffdoc.appspot.com/docs/W1100_1400.calc Jquery helpers http://whiffdoc.appspot.com/docs/W1100_1450.jQueryUI Integration support for repoze.who authentication http://whiffdoc.appspot.com/docs/W1100_1500.who Open Flash Charts http://whiffdoc.appspot.com/docs/W1100_1600.openFlashCharts Internationalization support http://whiffdoc.appspot.com/docs/W1100_1700.international Tree views with AJAX callbacks http://whiffdoc.appspot.com/docs/W1100_2200.TreeView Google App Engine compatibility http://whiffdoc.appspot.com/docs/W1100_2300.GAEDeploy And much more. Please try it out and let me know what you think -- Aaron Watters === This one goes to eleven. From python at mrabarnett.plus.com Sat Jun 5 22:14:49 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 06 Jun 2010 03:14:49 +0100 Subject: Handling text lines from files with some (few) starnge chars In-Reply-To: <4c0af8c2$0$23685$a729d347@news.telepac.pt> References: <4c0ad7bc$0$23684$a729d347@news.telepac.pt> <4c0af8c2$0$23685$a729d347@news.telepac.pt> Message-ID: <4C0B0499.7060502@mrabarnett.plus.com> Paulo da Silva wrote: > Em 06-06-2010 00:41, Chris Rebert escreveu: >> On Sat, Jun 5, 2010 at 4:03 PM, Paulo da Silva >> wrote: > ... > >> Specify the encoding of the text when opening the file using the >> `encoding` parameter. For Windows-1252 for example: >> >> your_file = open("path/to/file.ext", 'r', encoding='cp1252') >> > > OK! This fixes my current problem. I used encoding="iso-8859-15". This > is how my text files are encoded. > But what about a more general case where the encoding of the text file > is unknown? Is there anything like "autodetect"? > An encoding like 'cp1252' uses 1 byte/character, but so does 'cp1250'. How could you tell which was the correct encoding? Well, if the file contained words in a certain language and some of the characters were wrong, then you'd know that the encoding was wrong. This does imply, though, that you'd need to know what the language should look like! You could try different encodings, and for each one try to identify what could be words, then look them up in dictionaries for various languages to see whether they are real words... From shimbo at uklinux.net Sat Jun 5 22:22:39 2010 From: shimbo at uklinux.net (ant) Date: Sat, 5 Jun 2010 19:22:39 -0700 (PDT) Subject: GUIs - A Modest Proposal Message-ID: I get the strong feeling that nobody is really happy with the state of Python GUIs. Tkinter is not widely liked, but is widely distributed. WxPython and PyGtk are both powerful, but quirky in different ways. PyQt is tied to one platform. And there are dozens more. Whether or not we like graphics programming, it's not going to go away. I get the uneasy feeling whenever I start a new project that there should be a 'better' GUI than the ones I currently use (WxPython and PyGtk). Fragmentation is our enemy. Our resources are being dissipated. Is it not time to start again? We have shown that it is possible to do the right thing, by creating Python3. I ask the group; should we try to create a new GUI for Python, with the following properties?: - Pythonic - The default GUI (so it replaces Tkinter) - It has the support of the majority of the Python community - Simple and obvious to use for simple things - Comprehensive, for complicated things - Cross-platform - Looks good (to be defined) - As small as possible in its default form If so, what are the next steps? The Python SIG on GUIs closed years ago. Should that be revived? This is "A Modest Proposal" (J. Swift). In a sense, I am suggesting that we eat our own babies. But don't we owe it to the community? From vvw25w at googlemail.com Sat Jun 5 22:27:51 2010 From: vvw25w at googlemail.com (Steve) Date: Sat, 5 Jun 2010 19:27:51 -0700 (PDT) Subject: Replace in large text file ? References: <4e5b0acc-8073-480a-9a32-72f9c43f0adb@t10g2000yqg.googlegroups.com> Message-ID: On 5 June, 08:53, Steve wrote: > I am new to Python and am wanting ?to replace characters in a very > large text file.....6 GB > In plain language what I wish to do is: > > Remove all comma's > Replace all @ with comma's > Save as a new file. > > Any of you clever people know the best way to do this......idiot guide > please. > > Thanks > > Steve Many thanks for your suggestions. sed -i 's/Hello/hello/g' file Run twice on the CL..with the hello's changed for my needs did it in a few minutes , Again thanks Steve From debatem1 at gmail.com Sat Jun 5 22:33:58 2010 From: debatem1 at gmail.com (geremy condra) Date: Sat, 5 Jun 2010 19:33:58 -0700 Subject: GUIs - A Modest Proposal In-Reply-To: References: Message-ID: On Sat, Jun 5, 2010 at 7:22 PM, ant wrote: > I get the strong feeling that nobody is really happy with the state of > Python GUIs. > Tkinter is not widely liked, but is widely distributed. WxPython and > PyGtk are both > powerful, but quirky in different ways. PyQt is tied to one platform. > And there are > dozens more. > > Whether or not we like graphics programming, it's not going to go > away. I get the > uneasy feeling whenever I start a new project that there should be a > 'better' GUI > than the ones I currently use (WxPython and PyGtk). > > Fragmentation is our enemy. Our resources are being dissipated. Is it > not time to > start again? We have shown that it is possible to do the right thing, > by creating Python3. > > I ask the group; should we try to create a new GUI for Python, with > the following > properties?: > > - Pythonic > - The default GUI (so it replaces Tkinter) > - It has the support of the majority of the Python community > - Simple and obvious to use for simple things > - Comprehensive, for complicated things > - Cross-platform > - Looks good (to be defined) > - As small as possible in its default form > > If so, what are the next steps? > > The Python SIG on GUIs closed years ago. Should that be revived? > > This is "A Modest Proposal" (J. Swift). In a sense, I am suggesting > that > we eat our own babies. > > But don't we owe it to the community? No. http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ Geremy Condra From zyzhu2000 at gmail.com Sat Jun 5 22:35:53 2010 From: zyzhu2000 at gmail.com (GZ) Date: Sat, 5 Jun 2010 19:35:53 -0700 (PDT) Subject: Diff of Text References: <02f098c8-c2fc-4485-b748-1034373ad62c@q13g2000vbm.googlegroups.com> <4c09aacf$1@dnews.tpgi.com.au> <4c0a02f5$1@dnews.tpgi.com.au> <871vcl9btj.fsf@benfinney.id.au> Message-ID: <4ecb86e9-98bc-4417-8bbb-298abb70c4f0@y11g2000yqm.googlegroups.com> On Jun 5, 8:42?pm, Ben Finney wrote: > GZ writes: > > Let me think of a better way to express what I mean by a "smaller > >diff." After Idiffthe two strings, I will have something like this: > > > ? AAA > > - BBB > > + CCC > > + DDD > > - EEE > > > It means the first line does not change, the second line is replaced > > by the third line, the forth line is new, and the fifth line is > > deleted. > > Are you drawing a distinction between: > > ? * ?line FOO is replaced by line BAR? > ? * ?line FOO is deleted, line BAR is added? > > Your wording seems to make that distinction, but I don't see how it's > useful or meaningful in a discussion aboutdiff. Are they not exactly > the same? > > -- > ?\ ? ? ?Injustice is relatively easy to bear; what stings is justice.? | > ? `\ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Henry L. Mencken | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| > Ben Finney I should distinguish between modifications and additions. In my above example, one line is modified/replaced, one line is added and one line is deleted. There are a total of 3 edits. I am looking for an alternative python library other than difflib that minimizes this number (edit distance). From benjamin at python.org Sat Jun 5 23:03:27 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 6 Jun 2010 03:03:27 +0000 (UTC) Subject: GUIs - A Modest Proposal References: Message-ID: ant uklinux.net> writes: > PyQt is tied to one platform. What do you mean one platform? From sjmachin at lexicon.net Sat Jun 5 23:05:54 2010 From: sjmachin at lexicon.net (John Machin) Date: Sat, 5 Jun 2010 20:05:54 -0700 (PDT) Subject: Handling text lines from files with some (few) starnge chars References: <4c0ad7bc$0$23684$a729d347@news.telepac.pt> <4c0af8c2$0$23685$a729d347@news.telepac.pt> Message-ID: On Jun 6, 12:14?pm, MRAB wrote: > Paulo da Silva wrote: > > Em 06-06-2010 00:41, Chris Rebert escreveu: > >> On Sat, Jun 5, 2010 at 4:03 PM, Paulo da Silva > >> wrote: > > ... > > >> Specify the encoding of the text when opening the file using the > >> `encoding` parameter. For Windows-1252 for example: > > >> your_file = open("path/to/file.ext", 'r', encoding='cp1252') > > > OK! This fixes my current problem. I used encoding="iso-8859-15". This > > is how my text files are encoded. > > But what about a more general case where the encoding of the text file > > is unknown? Is there anything like "autodetect"? > > ?> > An encoding like 'cp1252' uses 1 byte/character, but so does 'cp1250'. > How could you tell which was the correct encoding? > > Well, if the file contained words in a certain language and some of the > characters were wrong, then you'd know that the encoding was wrong. This > does imply, though, that you'd need to know what the language should > look like! > > You could try different encodings, and for each one try to identify what > could be words, then look them up in dictionaries for various languages > to see whether they are real words... This has been automated (semi-successfully, with caveats) by the chardet package ... see http://chardet.feedparser.org/ From psdasilva.nospam at netcabonospam.pt Sat Jun 5 23:27:33 2010 From: psdasilva.nospam at netcabonospam.pt (Paulo da Silva) Date: Sun, 06 Jun 2010 04:27:33 +0100 Subject: Handling text lines from files with some (few) starnge chars In-Reply-To: References: <4c0ad7bc$0$23684$a729d347@news.telepac.pt> <4c0af8c2$0$23685$a729d347@news.telepac.pt> Message-ID: <4c0b15a5$0$23681$a729d347@news.telepac.pt> Em 06-06-2010 04:05, John Machin escreveu: > On Jun 6, 12:14 pm, MRAB wrote: >> Paulo da Silva wrote: ... >>> OK! This fixes my current problem. I used encoding="iso-8859-15". This >>> is how my text files are encoded. >>> But what about a more general case where the encoding of the text file >>> is unknown? Is there anything like "autodetect"? >> ... > > This has been automated (semi-successfully, with caveats) by the > chardet package ... see http://chardet.feedparser.org/ This seems nice! Thanks From awilliam at whitemice.org Sat Jun 5 23:43:13 2010 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Sat, 05 Jun 2010 23:43:13 -0400 Subject: GUIs - A Modest Proposal In-Reply-To: References: Message-ID: <1275795793.20908.4.camel@linux-yu4c.site> On Sat, 2010-06-05 at 19:22 -0700, ant wrote: > I get the strong feeling that nobody is really happy with the state of > Python GUIs. > WxPython and PyGtk are both powerful, but quirky in different ways. All widget libraries are quirky - because sophisticated user interfaces are complicated. If you make a new one that is sophisticated enough to be really useful - it will be "quirky". > PyQt is tied to one platform. No it isn't. > Whether or not we like graphics programming, it's not going to go > away. I get the > uneasy feeling whenever I start a new project that there should be a > 'better' GUI > than the ones I currently use (WxPython and PyGtk). > > Fragmentation is our enemy. So fragment some more? And at least PyGtk is a wrapper around Gtk, so in a sense that is anti-fragmentation. It is reusing Gtk which is also reused as Gtk# by Mono/.NET and other bindings. > Our resources are being dissipated. Is it not time to start again? No. > I ask the group; should we try to create a new GUI for Python, with > the following properties?: > - Pythonic > - The default GUI (so it replaces Tkinter) > - It has the support of the majority of the Python community > - Simple and obvious to use for simple things > - Comprehensive, for complicated things > - Cross-platform > - Looks good (to be defined) > - As small as possible in its default form Good luck. Seems pointless to me. > But don't we owe it to the community? Seems like there are already several very mature options. From torriem at gmail.com Sat Jun 5 23:58:15 2010 From: torriem at gmail.com (Michael Torrie) Date: Sat, 05 Jun 2010 21:58:15 -0600 Subject: GUIs - A Modest Proposal In-Reply-To: References: Message-ID: <4C0B1CD7.1020203@gmail.com> On 06/05/2010 08:22 PM, ant wrote: > WxPython and PyGtk are both powerful, but quirky in different ways. > PyQt is tied to one platform. And there are dozens more. In what way is PyQt (or the new PySide bindings) tied to one platform? PyQt is "native" on Win32, Mac, and Linux. Would your universal GUI be any less quirky? > I ask the group; should we try to create a new GUI for Python, with > the following properties?: > > - Comprehensive, for complicated things - Cross-platform Most GUI toolkits currently are, to some degree or another. Qt is the most comprehensive cross-platform toolkit that I know of. You can pretty much do any application operation using its API. > - Looks good (to be defined) Does that mean it looks native? Should it be native? Does not the Tkinter gui look "good?" I can think of at least the following reasons why a new universal GUI for Python will have acceptance issues: - stuck with the lowest common denominator of functionality on each platform if you thunk to native widgets (a la wxWidgets) - often look and feel is not quite native even when using native themes (GTK on windows, for example) - if you take the Java Swing approach, you'll look out of place everywhere, which is kind of where tkinter is now. From bryanjugglercryptographer at yahoo.com Sun Jun 6 00:16:32 2010 From: bryanjugglercryptographer at yahoo.com (Bryan) Date: Sat, 5 Jun 2010 21:16:32 -0700 (PDT) Subject: Diff of Text References: <02f098c8-c2fc-4485-b748-1034373ad62c@q13g2000vbm.googlegroups.com> <4c09aacf$1@dnews.tpgi.com.au> <4c0a02f5$1@dnews.tpgi.com.au> <871vcl9btj.fsf@benfinney.id.au> <4ecb86e9-98bc-4417-8bbb-298abb70c4f0@y11g2000yqm.googlegroups.com> Message-ID: <72f989b4-7f21-4d96-877f-381efa54a174@n37g2000prc.googlegroups.com> GZ wrote: > I should distinguish between modifications and additions. In my above > example, one line is modified/replaced, one line is added and one line > is deleted. There are a total of 3 edits. I am looking for an > alternative python library other than difflib that minimizes this > number (edit distance). Since you know the lingo, "edit distance", I expect you've already Googled up the general results. Depending on what kinds of edits we count, the problem of finding a minimal diff can be low-order poly- time, NP-hard, or incomputable. Gonzalo Navarro's 2001 survey, "A Guided Tour to Approximate String Matching", is now available on-line for free: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.96.7225&rep=rep1&type=pdf The paper notes, "issues have been put aside to keep a reasonable scope," but presents more than most of us ever wanted to know about the subject. I don't know of a module that does what GZ asks. There are scores of line-oriented diff implementations, and there are minimal-edit- distance diffs, but the combination is rare at best. Problem domains that call for a true minimal diff tend not to work in units of lines of text. -- --Bryan From nospam Sun Jun 6 00:40:56 2010 From: nospam (pdlemper) Date: Sat, 05 Jun 2010 23:40:56 -0500 Subject: Python Imaging Library available for Python 3.1 ? Fractals Message-ID: On the site http://code.activestate.com/recipes/langs/python/ there are several scripts for fractals. See page five. These begin from PIL import Image This fails in my python 3.1.2 Google reveals PIL is Python Imaging Library from pythonware.com According to their website PIL is not available beyond 2.6 : ( Do I need a full GUI like tkinter to image a fractal ( on my python 3.1.2 ) ? Is there any simpler option ? Thanks, Dave WB3DWE From miki.tebeka at gmail.com Sun Jun 6 00:51:16 2010 From: miki.tebeka at gmail.com (Miki) Date: Sat, 5 Jun 2010 21:51:16 -0700 (PDT) Subject: "python setup.py sdist" does pick one directory Message-ID: <422422a2-db5c-4bea-bb4e-3cd53bb72aad@v29g2000prb.googlegroups.com> Hello All, The Selenium setup.py can be found at http://code.google.com/p/selenium/source/browse/trunk/setup.py. When running "python setup.py sdist" the "firefox/test/py" directory is ignored for some reason though it's mentioned in the "package_dir" and in "packages". Any ideas why it's ignored? Thanks, -- Miki From aahz at pythoncraft.com Sun Jun 6 01:11:41 2010 From: aahz at pythoncraft.com (Aahz) Date: 5 Jun 2010 22:11:41 -0700 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c075f3b$0$24148$426a74cc@news.free.fr> <1275560120.8775.6.camel@linux-yu4c.site> Message-ID: In article , Monte Milanuk wrote: > >Decent NNTP access is harder to find. Not impossible, but no longer >a 'free' part of most standard ISP access any more. This seems like a good time to promote my ISP: panix.com -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From aahz at pythoncraft.com Sun Jun 6 01:14:52 2010 From: aahz at pythoncraft.com (Aahz) Date: 5 Jun 2010 22:14:52 -0700 Subject: Python Forum References: <272f6220-0d54-4c80-97fa-84a962b9ad52@m33g2000vbi.googlegroups.com> <4c089852$0$28659$c3e8da3@news.astraweb.com> <4c09b1f7$0$28659$c3e8da3@news.astraweb.com> Message-ID: In article <4c09b1f7$0$28659$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > >I'm sorry for all you people who don't live in a place with a genuinely >free market, and instead have to suffer with the lack of competition and >poor service of a monopoly or duopoly masquerading as a free market. But >*my* point was that your woes are not universal, and Usenet is alive and >well. It might be declining, but it's a long, slow decline and, like >Cobol, it will probably still be around a decade after the cool kids >declared it dead. Your position is the same as mine as of about two weeks ago, before someone sent this to me: http://news.duke.edu/2010/05/usenet.html Now I think that if even a top-tier educational institution isn't willing to serve as a living museum for a technology it created, maybe the death of Usenet is closer than I'd like to think. :-( Sucks because nothing replaces a good netnews client. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From gabriele.lanaro at gmail.com Sun Jun 6 04:13:27 2010 From: gabriele.lanaro at gmail.com (Gabriele Lanaro) Date: Sun, 6 Jun 2010 10:13:27 +0200 Subject: GUIs - A Modest Proposal In-Reply-To: <4C0B1CD7.1020203@gmail.com> References: <4C0B1CD7.1020203@gmail.com> Message-ID: I'd really like to s/tkinter/WxWidgets/g, the multiplatformness is (almost) the same but wx looks infinitely better. IMHO a good intention is to best the API of wx. Anyway, GUI programmers usually choose the toolkit (often 3rd party) more appropriate for the situation, wether it is or not in the standard library, to cite again Java, python interface looks generally better than Java ones because of this "freedom" of choicing the appropriate GUI. Personally If I'll have to develop a windows GUI I will use IronPython (choosing a different python implementation!). My 2 cents 2010/6/6 Michael Torrie > On 06/05/2010 08:22 PM, ant wrote: > > WxPython and PyGtk are both powerful, but quirky in different ways. > > PyQt is tied to one platform. And there are dozens more. > > In what way is PyQt (or the new PySide bindings) tied to one platform? > PyQt is "native" on Win32, Mac, and Linux. Would your universal GUI be > any less quirky? > > > I ask the group; should we try to create a new GUI for Python, with > > the following properties?: > > > > - Comprehensive, for complicated things - Cross-platform > Most GUI toolkits currently are, to some degree or another. Qt is the > most comprehensive cross-platform toolkit that I know of. You can > pretty much do any application operation using its API. > > > - Looks good (to be defined) > Does that mean it looks native? Should it be native? Does not the > Tkinter gui look "good?" > > I can think of at least the following reasons why a new universal GUI > for Python will have acceptance issues: > - stuck with the lowest common denominator of functionality on each > platform if you thunk to native widgets (a la wxWidgets) > - often look and feel is not quite native even when using native themes > (GTK on windows, for example) > - if you take the Java Swing approach, you'll look out of place > everywhere, which is kind of where tkinter is now. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Sun Jun 6 05:00:11 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 06 Jun 2010 19:00:11 +1000 Subject: GUIs - A Modest Proposal In-Reply-To: References: Message-ID: <4c0b6417$1@dnews.tpgi.com.au> On 06/06/10 12:22, ant wrote: > I get the strong feeling that nobody is really happy with the state of > Python GUIs. > Tkinter is not widely liked, but is widely distributed. WxPython and > PyGtk are both > powerful, but quirky in different ways. PyQt is tied to one platform. > And there are > dozens more. > > Whether or not we like graphics programming, it's not going to go > away. I get the > uneasy feeling whenever I start a new project that there should be a > 'better' GUI > than the ones I currently use (WxPython and PyGtk). > > Fragmentation is our enemy. Our resources are being dissipated. Is it > not time to > start again? We have shown that it is possible to do the right thing, > by creating Python3. > > I ask the group; should we try to create a new GUI for Python, with > the following > properties?: > > - Pythonic > - The default GUI (so it replaces Tkinter) > - It has the support of the majority of the Python community > - Simple and obvious to use for simple things > - Comprehensive, for complicated things > - Cross-platform > - Looks good (to be defined) > - As small as possible in its default form > > If so, what are the next steps? > > The Python SIG on GUIs closed years ago. Should that be revived? > > This is "A Modest Proposal" (J. Swift). In a sense, I am suggesting > that > we eat our own babies. > > But don't we owe it to the community? Pick any two: - Simple - Beautiful - Cross-platform From ken at picloud.com Sun Jun 6 05:39:58 2010 From: ken at picloud.com (Ken Elkabany) Date: Sun, 6 Jun 2010 02:39:58 -0700 Subject: ANN: PiCloud cloud library 1.9 release Message-ID: PiCloud, a cloud computing platform for the Python Programming Language, has released version 1.9 of its client library, cloud. PiCloud enables Python users to leverage the power of an on-demand, high performance, and auto scaling compute cluster with as few as three lines of code! No server management necessary. You can find out more here: http://www.picloud.com What's New: * Store your data files on the cloud using our cloud.files interface! * Greatly reduced the cloud library's memory and cpu usage when sending large data. * Map jobs begin processing before cloud.map() returns--large performance gains. * Persistent user processes has in many cases reduced function overhead by over 50%. * Increased network protocol reliability. * Profiling is now disabled by default, but can be enabled with the _profile keyword. * Bug fixes, and much more! Full service description: PiCloud is a cloud computing platform that integrates into the Python Programming Language. It enables you to leverage the compute power of Amazon Web Services without having to manage, maintain, or configure virtual servers. PiCloud integrates seamlessly into your existing code base through a custom Python library, cloud. To offload the execution of a function to the cloud, all you must do is pass your desired function into the cloud library. PiCloud will then run the function on its high-performance and automatically-scaling cluster. We quickly scale our server capacity to meet your computational needs, and only charge you for the resources you actually consume. Getting on the cloud has never been this easy! PiCloud improves the full cycle of software development and deployment. Functions that are run on PiCloud have their resource usage monitored, performance analyzed, and errors traced; we further aggregate all your functions to give you a bird's eye view of your service. Through these introspective capabilities, PiCloud enables you to develop faster, easier, and smarter. Common use cases for our platform: * Scientific computing * Video and image encoding * Statistical analysis of data sets * Real-time data processing * Charts and graphs generation Cheers, Ken Elkabany PiCloud, Inc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From googler.1.webmaster at spamgourmet.com Sun Jun 6 06:30:50 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Sun, 6 Jun 2010 03:30:50 -0700 (PDT) Subject: Py_single_input and the side-effects... References: <71e9afe5-f64e-4c2a-9c25-d814d13c7d46@t14g2000prm.googlegroups.com> <0d5415fc-d59b-42a2-99da-d1fd49c7a401@11g2000prv.googlegroups.com> Message-ID: thx, thats it! :) From stef.mientki at gmail.com Sun Jun 6 06:42:30 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 06 Jun 2010 12:42:30 +0200 Subject: GUIs - A Modest Proposal In-Reply-To: References: Message-ID: <4C0B7B96.1000902@gmail.com> Aren't all programms going webbased in the near future ? And if so, wouldn't it be better to hook to GWT or something like that (I can't oversee all the conesquences)? cheers, Stef Mientki On 06-06-2010 04:22, ant wrote: > I get the strong feeling that nobody is really happy with the state of > Python GUIs. > Tkinter is not widely liked, but is widely distributed. WxPython and > PyGtk are both > powerful, but quirky in different ways. PyQt is tied to one platform. > And there are > dozens more. > > Whether or not we like graphics programming, it's not going to go > away. I get the > uneasy feeling whenever I start a new project that there should be a > 'better' GUI > than the ones I currently use (WxPython and PyGtk). > > Fragmentation is our enemy. Our resources are being dissipated. Is it > not time to > start again? We have shown that it is possible to do the right thing, > by creating Python3. > > I ask the group; should we try to create a new GUI for Python, with > the following > properties?: > > - Pythonic > - The default GUI (so it replaces Tkinter) > - It has the support of the majority of the Python community > - Simple and obvious to use for simple things > - Comprehensive, for complicated things > - Cross-platform > - Looks good (to be defined) > - As small as possible in its default form > > If so, what are the next steps? > > The Python SIG on GUIs closed years ago. Should that be revived? > > This is "A Modest Proposal" (J. Swift). In a sense, I am suggesting > that > we eat our own babies. > > But don't we owe it to the community? > From steve at REMOVE-THIS-cybersource.com.au Sun Jun 6 06:52:57 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Jun 2010 10:52:57 GMT Subject: GUIs - A Modest Proposal References: Message-ID: <4c0b7e09$0$14135$c3e8da3@news.astraweb.com> On Sun, 06 Jun 2010 12:42:30 +0200, Stef Mientki wrote: > Aren't all programms going webbased in the near future ? Yes, just wait until somebody builds a web-browser that runs in your web- browser! -- Steven From eknath.iyer at gmail.com Sun Jun 6 07:32:10 2010 From: eknath.iyer at gmail.com (Eknath Venkataramani) Date: Sun, 6 Jun 2010 17:02:10 +0530 Subject: Replace in large text file ? In-Reply-To: <4e5b0acc-8073-480a-9a32-72f9c43f0adb@t10g2000yqg.googlegroups.com> References: <4e5b0acc-8073-480a-9a32-72f9c43f0adb@t10g2000yqg.googlegroups.com> Message-ID: On Sat, Jun 5, 2010 at 1:23 PM, Steve wrote: > > Remove all comma's > Replace all @ with comma's > Save as a new file. > Why don't you use 'sed'. It'd be way faster -- Eknath Venkataramani -------------- next part -------------- An HTML attachment was scrubbed... URL: From petite.abeille at gmail.com Sun Jun 6 08:09:44 2010 From: petite.abeille at gmail.com (Petite Abeille) Date: Sun, 6 Jun 2010 14:09:44 +0200 Subject: GUIs - A Modest Proposal In-Reply-To: <4c0b7e09$0$14135$c3e8da3@news.astraweb.com> References: <4c0b7e09$0$14135$c3e8da3@news.astraweb.com> Message-ID: <94F47A88-FB3C-407B-A305-524AB7811108@gmail.com> On Jun 6, 2010, at 12:52 PM, Steven D'Aprano wrote: > Yes, just wait until somebody builds a web-browser that runs in your web- > browser! There you go: "A good browser should be able to reproduce itself. Safari 4, built entirely with valid HTML5 and CSS3." http://general-metrics.com/Safari/ From lie.1296 at gmail.com Sun Jun 6 08:32:31 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 06 Jun 2010 22:32:31 +1000 Subject: GUIs - A Modest Proposal In-Reply-To: References: <4c0b7e09$0$14135$c3e8da3@news.astraweb.com> Message-ID: <4c0b95db$1@dnews.tpgi.com.au> On 06/06/10 22:09, Petite Abeille wrote: > > On Jun 6, 2010, at 12:52 PM, Steven D'Aprano wrote: > >> Yes, just wait until somebody builds a web-browser that runs in your web- >> browser! > > There you go: > > "A good browser should be able to reproduce itself. Safari 4, built entirely with valid HTML5 and CSS3." > Can't wait to see "Download Firefox for Chrome OS" From irmen.NOSPAM at xs4all.nl Sun Jun 6 08:52:01 2010 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sun, 06 Jun 2010 14:52:01 +0200 Subject: GUIs - A Modest Proposal In-Reply-To: <4c0b95db$1@dnews.tpgi.com.au> References: <4c0b7e09$0$14135$c3e8da3@news.astraweb.com> <4c0b95db$1@dnews.tpgi.com.au> Message-ID: <4c0b99f4$0$22943$e4fe514c@news.xs4all.nl> On 6-6-2010 14:32, Lie Ryan wrote: > On 06/06/10 22:09, Petite Abeille wrote: >> >> On Jun 6, 2010, at 12:52 PM, Steven D'Aprano wrote: >> >>> Yes, just wait until somebody builds a web-browser that runs in your web- >>> browser! >> >> There you go: >> >> "A good browser should be able to reproduce itself. Safari 4, built entirely with valid HTML5 and CSS3." >> > > Can't wait to see "Download Firefox for Chrome OS" That would mean that Chrome OS *is* Firefox, because Firefox is written in itself... Just open the following URL in Firefox to see proof of that: chrome://browser/content/browser.xul Irmen From victorsubervi at gmail.com Sun Jun 6 09:22:44 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Sun, 6 Jun 2010 09:22:44 -0400 Subject: Where's the List? In-Reply-To: References: Message-ID: On Sat, Jun 5, 2010 at 4:52 PM, Stephen Hansen wrote: > > cur.execute(sql, [pkg, prodid, tmpTable, quantity] + > list(option_values)) > > Or: > > cur.execute(sql, (pkg, prodid, tmpTable, quantity) + option_values) > > I removed the explicit conversion-to-tuple in the first, because... you > don't need to. Execute takes a sequence. It doesn't have to be a tuple. A > list is fine. In the second one, I just build my first arguments as a tuple > instead of as a list, and then add option_values to it... You'll just have > to go up top and do: > > option_values = () > > In both places where you currently use []. As you can't add a list to a > tuple anymore then a tuple to a list, for the same reasons. > Thanks. I always get tripped up on lists and tuples. In fact, just now I decided to look up the difference again, it's so slight. At any rate, I deliberately checked my variables using isinstance() and they all checked out as tuples, so that's why I couldn't figure out where the list was! Thanks again, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From cjwilliams43 at gmail.com Sun Jun 6 09:55:08 2010 From: cjwilliams43 at gmail.com (Colin J. Williams) Date: Sun, 06 Jun 2010 09:55:08 -0400 Subject: GUIs - A Modest Proposal In-Reply-To: References: Message-ID: On 05-Jun-10 23:03 PM, Benjamin Peterson wrote: > ant uklinux.net> writes: > >> PyQt is tied to one platform. > > What do you mean one platform? > > > > Source Packages This is the latest stable version of PyQt4. PyQt-x11-gpl-4.7.3.tar.gz Linux, UNIX source PyQt-win-gpl-4.7.3.zip Windows source PyQt-mac-gpl-4.7.3.tar.gz MacOS/X source Colin W. From jkordani at intlogsys.com Sun Jun 6 10:04:27 2010 From: jkordani at intlogsys.com (Joshua Kordani) Date: Sun, 06 Jun 2010 10:04:27 -0400 Subject: GUIs - A Modest Proposal In-Reply-To: <4c0b99f4$0$22943$e4fe514c@news.xs4all.nl> References: <4c0b7e09$0$14135$c3e8da3@news.astraweb.com> <4c0b95db$1@dnews.tpgi.com.au> <4c0b99f4$0$22943$e4fe514c@news.xs4all.nl> Message-ID: <4C0BAAEB.2060600@intlogsys.com> "Yo dawg I heard you like browsers, so we put a browser in your browser so you can browse while you browse!" -- Xibit On 6/6/2010 8:52 AM, Irmen de Jong wrote: > On 6-6-2010 14:32, Lie Ryan wrote: >> On 06/06/10 22:09, Petite Abeille wrote: >>> >>> On Jun 6, 2010, at 12:52 PM, Steven D'Aprano wrote: >>> >>>> Yes, just wait until somebody builds a web-browser that runs in your >>>> web- >>>> browser! >>> >>> There you go: >>> >>> "A good browser should be able to reproduce itself. Safari 4, built >>> entirely with valid HTML5 and CSS3." >>> >> >> Can't wait to see "Download Firefox for Chrome OS" > > That would mean that Chrome OS *is* Firefox, because Firefox is written > in itself... > Just open the following URL in Firefox to see proof of that: > chrome://browser/content/browser.xul > > Irmen From wissme at hotmail.com Sun Jun 6 10:05:46 2010 From: wissme at hotmail.com (Franck Ditter) Date: Sun, 06 Jun 2010 16:05:46 +0200 Subject: [RELEASE] Python 2.7 release candidate 1 released References: Message-ID: Just an advice as I see that "old" Python is maintained. When starting with Python (simple programs and GUIs) should I start with Python 3.x ? If it has a decent implementation on Mac/Linux/Windows of course... Thanks, franck From parvini_navid at yahoo.com Sun Jun 6 10:28:34 2010 From: parvini_navid at yahoo.com (Navid Parvini) Date: Sun, 6 Jun 2010 07:28:34 -0700 (PDT) Subject: store .png file in a script Message-ID: <794052.35011.qm@web51002.mail.re2.yahoo.com> Dear All, Would you please let me know that how can I store a .png or .gif or .jpg file, in a python script? Thank you in advance. Navid -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Sun Jun 6 10:32:56 2010 From: aahz at pythoncraft.com (Aahz) Date: 6 Jun 2010 07:32:56 -0700 Subject: [RELEASE] Python 2.7 release candidate 1 released References: Message-ID: In article , Franck Ditter wrote: > >When starting with Python (simple programs and GUIs) should I start >with Python 3.x ? That depends on the extent to which you rely strictly on the standard Python library. If there's any likelihood that you will want to use random third-party libraries, you probably want to stick with 2.x; ditto if you want to rely on your users having their own copy of Python (in which case you probably should target Python 2.4). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra From news1234 at free.fr Sun Jun 6 10:53:19 2010 From: news1234 at free.fr (News123) Date: Sun, 06 Jun 2010 16:53:19 +0200 Subject: Forcing any output (file / stdout) to UTF-8 Message-ID: <4c0bb65f$0$30672$426a34cc@news.free.fr> Hi, I'm having a small python script printing out UTF-8 characters. # -*- coding: utf-8 -*- print sys.stdout.encoding s=u"abcd?fg" # string containing one non ASCII character # just in case nntp kills it for c in s: print c It work perfectly fine on my utf-8 capable terminal. However when trying to redirect its output or to just pipe it through more, then the application fails with 'ascii' codec can't encode character u'\xe9' in position 0: ordinal not in range(128), as encoding has been switched to none. because sys.stdout.encoding is now None The same problem would also occur if I had written directly to a file. So my qusetion are: - How can I force the encoding of stdout to a certain encoding. (UTF-8) - How can I configure the default encoding of any file to be opened to UTF-8? Thanks for any suggestions or other ideas how you solve the problem. A current workaround for forcing UTF-8 output for all output to stdout could be: class UtfStdOut(): def write(self,data): sys.__stdout__.write(data.encode('UTF-8')) sys.stdout = UtfStdOut() but I wonder if there's something better From ian.g.kelly at gmail.com Sun Jun 6 11:01:22 2010 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 6 Jun 2010 09:01:22 -0600 Subject: store .png file in a script In-Reply-To: <794052.35011.qm@web51002.mail.re2.yahoo.com> References: <794052.35011.qm@web51002.mail.re2.yahoo.com> Message-ID: On Sun, Jun 6, 2010 at 8:28 AM, Navid Parvini wrote: > > Dear All, > > Would you please let me know that how can I store a .png or .gif or .jpg file, in a python script? > > Thank you in advance. > > Navid Encode it in base64 and store it in a triple-quoted string literal: import base64 png_data = """ iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAAXNSR0IArs4c 6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9oGBg40CoQ7CHYAAAAZ dEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAADElEQVQI12P4 //8/AAX+Av7czFnnAAAAAElFTkSuQmCC """ png = base64.b64decode(png_data) Cheers, Ian From castor91 at gmail.com Sun Jun 6 11:02:24 2010 From: castor91 at gmail.com (castor91) Date: Sun, 6 Jun 2010 17:02:24 +0200 Subject: Sniffer Linux with Raw Socket Message-ID: Hi all, i try to make a python sniffer for linux using raw socket and not pcap or scapy.. But i have a lot of problems.. I use the code that i found here: http://docs.python.org/library/socket.html import socket # the public network interfaceHOST = socket.gethostbyname(socket.gethostname()) # create a raw socket and bind it to the public interfaces = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)s.bind((HOST, 0)) # Include IP headerss.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1) # receive all packagess.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON) # receive a packageprint s.recvfrom(65565) # disabled promiscuous modes.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF) but the attribute "ioctl" is only for windows platform... and also i must replace "socket.IPPROTO_IP" with "9" because it doesn't work ( i found the answer in a web topic) How do i ??? Thanks and sorry for bad english. --castor91 -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Sun Jun 6 11:07:25 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Sun, 6 Jun 2010 11:07:25 -0400 Subject: Drop Table w/ MySQLdb? Message-ID: Hi; I tried this: cursor.execute('drop table tmp%s', tmpTable) and got this error: Traceback (most recent call last): File "/var/www/html/angrynates.com/cart/cart.py", line 196, in ? cart() File "/var/www/html/angrynates.com/cart/cart.py", line 189, in cart cursor.execute('drop table tmp%s', tmpTable) File "/usr/lib64/python2.4/site-packages/MySQLdb/cursors.py", line 163, in execute self.errorhandler(self, exc, value) File "/usr/lib64/python2.4/site-packages/MySQLdb/connections.py", line 35, in defaulterrorhandler raise errorclass, errorvalue ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''127541158007'' at line 1") But when I print that statement out (exchanging the comma for a %) and manually enter it: mysql> drop table tmp127541158007; Query OK, 0 rows affected (0.00 sec) I am able to successfully drop the table. Why? TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From g.rodola at gmail.com Sun Jun 6 11:11:31 2010 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Sun, 6 Jun 2010 17:11:31 +0200 Subject: Sniffer Linux with Raw Socket In-Reply-To: References: Message-ID: RAW sockets are not recommended for doing such kind of things. It is a lot easier and portable using libpcap. Python has a lot of libpcap bindings you can use (pcapy, pypcap, etc...). Just google for it. --- Giampaolo http://code.google.com/p/pyftpdlib http://code.google.com/p/psutil 2010/6/6 castor91 : > Hi all, i try to make a python sniffer for linux using raw socket and not > pcap or scapy.. But i have a lot of problems.. > I use the code that i found here: > http://docs.python.org/library/socket.html > > import socket > > # the public network interface > HOST = socket.gethostbyname(socket.gethostname()) > > # create a raw socket and bind it to the public interface > s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP) > s.bind((HOST, 0)) > > # Include IP headers > s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1) > > # receive all packages > s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON) > > # receive a package > print s.recvfrom(65565) > > # disabled promiscuous mode > s.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF) > > but the attribute "ioctl" is only for windows platform... and also i must > replace "socket.IPPROTO_IP" with "9" because it doesn't work ( i found the > answer in a web topic) > How do i ??? > Thanks and sorry for bad english. > --castor91 > -- > http://mail.python.org/mailman/listinfo/python-list > > From rantingrick at gmail.com Sun Jun 6 11:16:02 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 6 Jun 2010 08:16:02 -0700 (PDT) Subject: map is useless! Message-ID: <1212ceb7-c1f9-407a-ab9b-b6fef5671839@r27g2000yqb.googlegroups.com> Everyone knows i'm a Python fanboy so nobody can call me a troll for this... Python map is just completely useless. For one it so damn slow why even bother putting it in the language? And secondly, the total "girl- man" weakness of lambda renders it completely mute! Ruby has a very nice map >>> [1,2,3].map{|x| x.to_s} Have not done any benchmarking but far more useful from the programmers POV. And that really stinks because map is such a useful tool it's a shame to waste it. Here are some test to back up the rant. >>> import time >>> def test1(): l = range(10000) t1 = time.time() map(lambda x:x+1, l) t2= time.time() print t2-t1 >>> def test2(): l = range(10000) t1 = time.time() for x in l: x + 1 t2 = time.time() print t2-t1 >>> test1() 0.00200009346008 >>> test2() 0.000999927520752 >>> def test3(): l = range(10000) t1 = time.time() map(str, l) t2= time.time() print t2-t1 >>> def test4(): l = range(10000) t1 = time.time() for x in l: str(x) t2= time.time() print t2-t1 >>> test3() 0.00300002098083 >>> test4() 0.00399994850159 >>> So can anyone explain this poor excuse for a map function? Maybe GVR should have taken it out in 3.0? *scratches head* From python at bdurham.com Sun Jun 6 11:17:37 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 06 Jun 2010 11:17:37 -0400 Subject: GUIs - A Modest Proposal In-Reply-To: <4C0B7B96.1000902@gmail.com> References: <4C0B7B96.1000902@gmail.com> Message-ID: <1275837457.25709.1378717881@webmail.messagingengine.com> Why not a GUI based on HTML, CSS and Javascript? To paraphrase another poster and to borrow from SQLite: Pick any *THREE*: - Simple - Beautiful - Cross-platform Malcolm From python at bdurham.com Sun Jun 6 11:19:46 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 06 Jun 2010 11:19:46 -0400 Subject: GUIs - A Modest Proposal In-Reply-To: <94F47A88-FB3C-407B-A305-524AB7811108@gmail.com> References: <4c0b7e09$0$14135$c3e8da3@news.astraweb.com> <94F47A88-FB3C-407B-A305-524AB7811108@gmail.com> Message-ID: <1275837586.25902.1378718185@webmail.messagingengine.com> > Yes, just wait until somebody builds a web-browser that runs in your web-browser!