From andre.roberge at gmail.com Fri Jan 21 20:01:00 2005 From: andre.roberge at gmail.com (=?UTF-8?B?QW5kcsOpIFJvYmVyZ2U=?=) Date: Fri, 21 Jan 2005 21:01:00 -0400 Subject: finding name of instances created In-Reply-To: <1106353764.19065.89.camel@bucket.localnet> References: <1106352799.481829.279900@c13g2000cwb.googlegroups.com> <1106353764.19065.89.camel@bucket.localnet> Message-ID: Craig Ringer wrote: > On Fri, 2005-01-21 at 16:13 -0800, Andr? wrote: > >>Short version of what I am looking for: >> >>Given a class "public_class" which is instantiated a few times e.g. >> >>a = public_class() >>b = public_class() >>c = public_class() >> >>I would like to find out the name of the instances so that I could >>create a list of them e.g. >>['a', 'b', 'c'] [snip] > > > I'm not really able to grasp what you're trying to do (but others > might). It wouldn't hurt if you could post a description of what you're > actually trying to achieve - /why/ you want this - as that can often be > very helpful both in understanding what you're thinking and in > suggesting a suitable approach or alternative. > Ok, here it goes... I am designing a "learning environment" for Python. (See rur-ple.sourceforge.org for details of a *very early, still buggy* relase). I have a "world" in which a "robot" can accomplish four built-in instructions: move(), turn_left(), pick_beeper(), put_beeper(). turn_left() corresponds to a 90 degree left turn. One can define a function to simulate a 90 degree right turn as follows: def turn_right(): turn_left() turn_left() turn_left() and call it as a built-in instruction thereafter. By giving more and more complicated tasks for the robot to accomplish, one can learn various programming concepts using python syntax: def (as above), while, if, else, elif, ...... I have all of that working well so far (not on sourceforge yet). Next, I want to introduce the concept of classes and objects, again using python's syntax. Behind the scene, I have something like: robot_dict = { 'robot' = CreateRobot( ..., name = 'robot') } and have mapped move() to correspond to robot_dict['robot'].move() (which does lots of stuff behind the scene.) I have tested robot_dict[] with more than one robot (each with its own unique name) and am now at the point where I would like to have the ability to interpret something like: alex = CreateRobot() anna = CreateRobot() alex.move() anna.move() etc. Since I want the user to learn Python's syntax, I don't want to require him/her to write alex = CreateRobot(name = 'alex') to then be able to do alex.move() I have tried various things at the interpreter, found that to a class 'a', I could see the instance 'b' created in locals(): 'a': , 'b': <__main__.a object at 0x011515D0> which tells me that there must be a way to catch b's name as it is created, and do what I want to do. Does this clarify what I am trying to do and why? Andr? From http Sat Jan 22 19:04:46 2005 From: http (Paul Rubin) Date: 22 Jan 2005 16:04:46 -0800 Subject: rotor replacement References: <7x1xcidnp1.fsf@ruckus.brouhaha.com> <41EE24F7.7030303@jessikat.fsnet.co.uk> <7x1xchlpqv.fsf@ruckus.brouhaha.com> <41efeb82$0$27807$9b622d9e@news.freenet.de> <41f1a70b$0$25959$9b622d9e@news.freenet.de> <7xbrbiqdhk.fsf@ruckus.brouhaha.com> <7xllalljah.fsf@ruckus.brouhaha.com> Message-ID: <7xhdl9huxt.fsf@ruckus.brouhaha.com> "A.M. Kuchling" writes: > It was discussed in this thread: > http://mail.python.org/pipermail/python-dev/2003-April/034959.html In that thread, you wrote: > Rubin wanted to come up with a nice interface for the module, and > has posted some notes toward it. I have an existing implementation > that's 2212 lines of code; I like the interface, but opinions may > vary. :) Does that mean you have a 2212-line C implementation of the interface that I proposed? Do you plan to release it? BTW, I just looked at the other messages in that thread and I realize that I've looked at them before, and that's where I saw the concern about importing crypto into some countries including Holland. Again, I think the reasoning is bizarre. I'm sure there are tons of Firefox users in Holland, and Firefox definitely contains an SSL stack that doesn't have to be downloaded separately. From r.roelofsen at tuxed.de Tue Jan 4 19:50:43 2005 From: r.roelofsen at tuxed.de (Roman Roelofsen) Date: Wed, 5 Jan 2005 01:50:43 +0100 Subject: coding conventions, PEP vs. practice Message-ID: <200501050150.43556.r.roelofsen@tuxed.de> Dear python-list, while looking for some coding conventions for python programs, i found the PEP8 at http://www.python.org/peps/pep-0008.html. It defines the rules very well and leaves no space for interpretations. I guess thats a good thing :-) But when i started playing a bit with python and frameworks like Zope, Webworks, etc., i noticed, that a lot frameworks are using a different convention for methodnames. These frameworks are using "mixedCase" but PEP8 suggests "lower_case_with_underscores" except "in contexts where that's already the prevailing style" which is not the case here IMHO. So, are there any specific reasons for breaking the rules here? I think consistent conventions are very important. Being a Java developer in the last couple of years, i learned how practical it can be to have only one naming style. Best regards, Roman From duncan.booth at invalid.invalid Fri Jan 28 10:30:43 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 28 Jan 2005 15:30:43 GMT Subject: a sequence question References: Message-ID: Chris Wright wrote: > 1) I want to iterate over a list "N at a time" > sort of like: > > # Two at a time... won't work, obviously > > >>> for a, b in [1,2,3,4]: > ... print a,b > ... Try this: l = [1, 2, 3, 4] for a, b in zip(*[iter(l)]*2): print a, b zip(*[iter(seq)]*N) will group by N (but if there are any odd items at the end it will ignore them). map(None, *[iter(seq)]*N) will group by N padding the last item with None if it needs to. From davorss at gmail.com Tue Jan 25 18:01:23 2005 From: davorss at gmail.com (Davor) Date: 25 Jan 2005 15:01:23 -0800 Subject: python without OO In-Reply-To: References: <1106689788.676121.48490@c13g2000cwb.googlegroups.com> Message-ID: <1106694083.199064.240680@f14g2000cwb.googlegroups.com> Thanks, I do not hate OO - I just do not need it for the project size I'm dealing with - and the project will eventually become open-source and have additional developers - so I would prefer that we all stick to "simple procedural" stuff rather than having to deal with a developer that will be convincing me that his 50 layers inheritance hierarchy is good since it exists in some weird pattern that he saw somewhere on some Java design patterns discussion board :-) and other "proper" OO design issues... Once I opted for C++ in a very small project and believed everyone will stick with C subset + better type checking offered through C++ - but I simply could not manage to keep them off using OO stuff which was just making program more complicated than it should have been. (note, I am not an experienced developer, nor the others I'll be working with (even though some think they are:-)), so I prefer preemptively dealing with issue of everyone showing off their OO design skills) Davor From gosselit at norwich.edu Tue Jan 11 18:40:36 2005 From: gosselit at norwich.edu (Tim Gosselin) Date: Tue, 11 Jan 2005 23:40:36 +0000 Subject: Detecting shutdown of remote socket endpoint. Message-ID: <1105504107.d645f57ce935d6cb8e82567c0be1e97e@onlynews> I am writing a tcp tunnel but cannot find a way of detecting when a socket shuts down its read end without writing to the socket. For testing the write end of the remote endpoint I just do a: if not sock.recv(buffsize) I cannot write to the socket and check if send returns 0 though, because that involves sending data out of the which may not have come in yet. When I try polling the socket with: r, w, e=select([],[sock],[], 0) w returns with the socket still writable, even if the other end was closed. #For example: s=socket() s.bind(('localhost', 5000)) s.listen(5) s2, addr=s.accept() #then create a socket to connect, s=socket() s.connect(('localhost', 5000)) #then I close the server side, s2.close() #or s2.shutdown(0) #and poll s to see if it's still writable, r, w, e=select([],[s],[], 0) #this returns that the socket is writable! and i can even write to it, s.send('test') #succeeds #but the second write finally throws an exception. Is there any other way to check if a the remote endpoint on a socket has shutdown its read end? Is it difficult to implement a sock.is_shutdown(1) with some additional c code? From dbickett at gmail.com Sun Jan 23 10:57:25 2005 From: dbickett at gmail.com (Daniel Bickett) Date: Sun, 23 Jan 2005 10:57:25 -0500 Subject: how to write a tutorial In-Reply-To: <1106472508.591411.40140@c13g2000cwb.googlegroups.com> References: <1106305730.361540.21010@f14g2000cwb.googlegroups.com> <1106472508.591411.40140@c13g2000cwb.googlegroups.com> Message-ID: <1d6cdae3050123075756536a66@mail.gmail.com> > Most texts in computing are written by authors to defend and showcase > their existence against their peers. When you aren't busy `showcasing' your ignorance, this is *all* i see in everything you write. > In a tutorial, nobody cares how > the language compared to x y and z, or what technicality is it all > about, or some humorous snippet of history only funny to the author > himself. You couldn't be farther from the truth. To preface a document by illustrating it's similarities to other languages is to better prepare a reader who may have experience in those languages. As for the snippet of history, few people desire to live life as cynical as you do, and one would hope even fewer take their own opinion and assume it applies to their peers, as you have just done. > Particularly for texts in a tutorial context, you want to write it as > simple as possible covering the most useful basic functionalities and > concepts, and self-contained. Not showcasing your knowledge of history > of languages or your linguistic lineage byways. You of all people are the least qualified to say this, as you are the most guilty of such a crime. > For example this chapter 9 on Objects, it is not difficult to write it > without making a show of lingoes. One simply write what is of Python, > without thinking about relation to xyz languages or the "computer > science" establishment and their ways of thinkings of namespaces and > scopes and dynamic and statics and inheritances ... fucking bags of > shit. Then please be so kind as to give us all a pleasant surprise, and take the place of the productive reformer rather than the angsty criticizer. Your vision as to the errors in the tutorial is *clearly* less clouded than ours, so only *you* are in the position to write the proper replacement. Daniel Bickett From foo at bar.com Sun Jan 23 01:06:35 2005 From: foo at bar.com (Steve Menard) Date: Sun, 23 Jan 2005 01:06:35 -0500 Subject: JPype and classpath (Was Re: embedding jython in CPython... ) In-Reply-To: <1106446384.384110.25150@z14g2000cwz.googlegroups.com> References: <1106446384.384110.25150@z14g2000cwz.googlegroups.com> Message-ID: > While we are on topic, I am having some trouble understanding JPype > classpath. How do I init the JVM with the folder in which the Python > program is located included in the classpath? > > I tried > t = JPackage('.').test > > That did not work. > > My environment variable includes current folder in the classpath > > I tried passing it as an argument to startJVM. Didn't help. > > I think my main use is going to be using CPython with a few Java custom > classes and if anyone has a snippet on this it would really help me. > Thanks > That's easy. First realise that "." denotes the current working directory, not the "directory where the python program is located". Second, JPackage uses Java package names. So, assuming you java classes are properly stord in a directory called "classes" at the same level as your python script (see how java looks up classes on the filesystem for what "properly" means), here is a snippet that will do what you wanted : #============================================================== import os, os.path, jpype root = os.path.abspath(os.path.dirname(__file__)) jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.class.path=%s%sclasses" % (root, os.sep)) #============================================================== Or alternately, if the Java classes you want to use ar in JAR files, in a lib directory at the same level as your python script : #============================================================== import os, os.path, jpype root = os.path.abspath(os.path.dirname(__file__)) jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.ext.dirs=%s%slib" % (root, os.sep)) #============================================================== The magic in the above script is the __file__ variable, which stores the absolute path to the currently executing Python script. If you have both situation (you classes in the classes directory and some JARS containing stuff that they uses) you can combine the above : #============================================================== import os, os.path, jpype root = os.path.abspath(os.path.dirname(__file__)) jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.class.path=%s%sclasses" % (root, os.sep), "-Djava.ext.dirs=%s%slib" % (root, os.sep)) #============================================================== Hopefully this will help. -- Steve Menard -------------------- Maintainer of http://jpype.sourceforge.net From bokr at oz.net Thu Jan 13 01:26:08 2005 From: bokr at oz.net (Bengt Richter) Date: Thu, 13 Jan 2005 06:26:08 GMT Subject: why are people still using classic classes? References: <7x6522gegg.fsf@ruckus.brouhaha.com> Message-ID: <41e612dc.719526364@news.oz.net> On 12 Jan 2005 20:06:39 -0800, Paul Rubin wrote: >Simon Wittber writes: >> > Is there a reason NOT to use them? If a classic class works fine, what >> > incentive is there to switch to new style classes? >> >> Perhaps classic classes will eventually disappear? > >It just means that the formerly "classic" syntax will define a >new-style class. Try to write code that works either way. > >It would be nice if a __future__ directive were added right now (if >it's not there already) that processes all class definitions as >new-style. Otherwise there's no easy way to test for compatibility. UIAM, it's not so bad: >>> class C: pass ... >>> type(C) >>> class D(object): pass ... >>> type(D) >>> __metaclass__ = type >>> class E: pass ... >>> type(E) So I guess you can put __metaclass__ = type where you would have done the __future__ thing. If you want to do a special metaclass thing (even using a proper class ;-), you can override the global __metaclass__ >>> def MC(*a): print a; return type(*a) ... >>> class F: ... __metaclass__ = MC ... pass ... ('F', (), {'__module__': '__main__', '__metaclass__': }) Regards, Bengt Richter From gurpreet.sachdeva at gmail.com Thu Jan 20 08:23:06 2005 From: gurpreet.sachdeva at gmail.com (Gurpreet Sachdeva) Date: Thu, 20 Jan 2005 18:53:06 +0530 Subject: Problem in importing MySQLdb Message-ID: I am using Mysql version 5.0.2-alpha on RedHat 9.0 (python2.2) When I try to import MySQldb I get: Python 2.2.2 (#1, Feb 24 2003, 19:13:11) [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import MySQLdb Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.2/site-packages/MySQLdb/__init__.py", line 27, in ? import _mysql ImportError: /usr/lib/libmysqlclient.so.10: symbol errno, version GLIBC_2.0 not defined in file libc.so.6 with link time reference Is there any problem in library files?? Do I need to install anything I have installed MySQL-shared-3.23.54a-1.i386.rpm, MySQL-devel-5.0.2-0.i386.rpm, MySQL-client-5.0.2-0.i386.rpm, MySQL-server-5.0.2-0.i386.rpm Please help, Garry From ianb at colorstudy.com Fri Jan 7 16:52:27 2005 From: ianb at colorstudy.com (Ian Bicking) Date: Fri, 07 Jan 2005 15:52:27 -0600 Subject: Exception report library In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3398134@exchange.hqamor.amorhq.net> References: <3A81C87DC164034AA4E2DDFE11D258E3398134@exchange.hqamor.amorhq.net> Message-ID: <41DF049B.2070003@colorstudy.com> Robert Brewer wrote: >>I've been using one of several systems to catch unexpected exceptions >>and log them (e.g., write to a file, display on web page, email me, >>etc). But many are built into a particular system, or have an >>interesting but incomplete set of features. E.g., many web >>frameworks have exception reporters (and the stdlib includes cgitb), >>but I want to handle non-web exceptions in the same way as exceptions >>from web requests, and that's not generally easy. > > ... > >>I feel like there must be something out there, since every Python >>programmer has to deal with this sort of thing to some degree...? > > > I feel that way, too, but haven't found it. I broke my webapp framework > out of my ORM late last year, and quickly realized how small the core > framework really is (22k, versus 250k for the web bits). Features like > the logging handler could be provided as separate modules, rather than > built into the Application object, and I've been meaning to get around > to that. If we could put our many heads together, I think this would be > doable for the stdlib. I'm not optimistic about a good exception handler in the standard library; development slows down a lot at that point, and it's not a reasonable candidate until it is designed and used (in part because of that slowdown -- if it's not mature, it is a diservice to the project to calcify the interface with such strong backward compatibility requirements). But anyway, hopefully multiple people/frameworks/projects could use such a library, done well, as a start. > Here are the pieces of the framework, by the way, which might also > benefit from some standardization (I was thinking about them all at > once): > > 1. Thread-safe application state > 2. Logging (+ exception handling) > 3. Configuration data (reading from various sources) > 4. Registry of Workers for getting things done on a schedule, > possibly recurring > 5. Registry of startup/shutdown functions > 6. Registry of active user interfaces > > I think the first three are all good candidates for a standard. If we > had a standard, thread-safe Application object, the rest could be > registerable plugins for that. You'd basically register callbacks for > app.startup and .shutdown methods to iterate over. Hmm... I'm confused by these bits. Are you talking about libraries for other parts of a web framework, besides exception handling? If so, you might want to look into WSGI and then discuss these things on the web-sig list (WSGI as a starting point; it doesn't specifically relate to many of these ideas, but provides a context in which to develop them). Some of these have been discussed there, like logging, configuration, and perhaps aspects of the registration you are thinking about. -- Ian Bicking / ianb at colorstudy.com / http://blog.ianbicking.org From dalke at dalkescientific.com Sat Jan 8 20:30:15 2005 From: dalke at dalkescientific.com (Andrew Dalke) Date: Sun, 09 Jan 2005 01:30:15 GMT Subject: Python Operating System??? References: <10trb0mgiflcj4f@corp.supernews.com> <10tteh884ivk6c9@corp.supernews.com> <7xr7kx0w4m.fsf@ruckus.brouhaha.com> <7xhdlss0tl.fsf@ruckus.brouhaha.com> <7x8y734jlq.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin: > Lately there are people trying to program PC's to > simulate the Lisp hardware and to get the Lisp Machine software > released (now that the commercial market for it has long since dried > up). However, both of those projects have a ways to go. There's a video of someone demoing how to use a Lisp Machine at http://lemonodor.com/archives/000103.html Andrew dalke at dalkescientific.com From bjourne at gmail.com Thu Jan 13 14:14:39 2005 From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=) Date: Thu, 13 Jan 2005 20:14:39 +0100 Subject: Refactoring; arbitrary expression in lists In-Reply-To: References: Message-ID: <740c3aec05011311141ce10b8e@mail.gmail.com> > # do other non-extension-related tests here > if basename.find( "Makefile" ) != -1: > return "text/x-makefile" I believe this can be nicelier written as: if "Makefile" in basename: -- mvh Bj?rn From stephane.bronsart at bea.be Fri Jan 28 05:02:38 2005 From: stephane.bronsart at bea.be (StepH) Date: Fri, 28 Jan 2005 11:02:38 +0100 Subject: How to test that an exception is raised ? Message-ID: <41fa0da9$0$2018$6c56d894@feed0.news.be.easynet.net> Hi, I've this module : from optparse import OptionParser import re _version = "P1" def writeVar(f, line): """Output a line in .xml format in the file f.""" f.write('\t\n') name = line.split()[0] adr = line.split()[3] f.write('\t\t' + name + '\n') f.write('\t\t' + adr + '\n') f.write('\t\n') def mps2xml(mps,verbose): """Convert '.mps' to '.xml'.""" try: f = open(mps) f.close() xmlfile = mps + ".xml" f = open(xmlfile, "w+") f.write('\n') f.writelines('\n') pat = re.compile(".*Var.*g.*0x00.*") lines = list(open(mps)) nbScan = nbFound = 0 for line in lines: nbScan = nbScan + 1 if pat.match(line): writeVar(f, line) nbFound = nbFound + 1 f.writelines('\n') f.close() if verbose: print "Output to file %s..." % xmlfile print "Lines scanned:", nbScan print "Lines found:", nbFound except: if verbose: print "FileError" if __name__ == "__main__": usage = "usage: %prog [options] filename" parser = OptionParser(usage) parser.add_option("-v", "--verbose", action="store_true", dest="verbose") parser.add_option("-q", "--quiet", action="store_false", dest="verbose") (options, args) = parser.parse_args() if len(args) != 1: parser.error("incorrect number of arguments") exit(1) if options.verbose: print "mps2xml -", _version mps2xml(args[0],options.verbose) And this "unittest" module : import mps2xml import os import unittest class Tests(unittest.TestCase): def setUp(self): self.mps = "test.mps" def tearDown(self): pass def test_badFile(self): """Check that an exception is raised if a bad filename is passed to mps2xml""" self.assertRaises((IOError),mps2xml.mps2xml, "thisfiledoesntexists", False) def test_writeVar_Output(self): """Check the output of the 'writeVar' method""" line = " irM1slotnoisePPtmp Var. g 0x0002F6" file = open("testWriteVar.xml","w+") mps2xml.writeVar(file, line) file.close() outputlines = list(open("testWriteVar.xml")) goodlines = list(open("testWriteVar.xml.good")) self.assertEquals(outputlines, goodlines, 'bad output format') def test_mps2xml_Creation(self): """Check if test.mps.xml is created""" mps2xml.mps2xml(self.mps, False) self.assert_(os.path.exists(self.mps + ".xml"), 'test.mps.xml not created') if __name__ == '__main__': unittest.main() But i've prob with the 1st test : test_badFile. When I run the test, unittest say that no error is Raised. But when I run the mps2xml module with a bad file as arg., the exception is well Raised. What i'm doing wrong ? It is because the exception in catched in the mps2xml module ? Thanks for your helps. StepH. From peter at engcorp.com Wed Jan 12 11:01:20 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 12 Jan 2005 11:01:20 -0500 Subject: 2 versions of python on 1 machine In-Reply-To: <4446BD725249914A801A2C8ED5BFA4CADE2D59@cernne02.cern.ch> References: <4446BD725249914A801A2C8ED5BFA4CADE2D59@cernne02.cern.ch> Message-ID: flupke wrote: > I searched with Google and on this newsgroups and i didn't find any info > regarding this. If there is more info, please redirect me to that info. [snip] The above looks like a glitch or accidental repost of the post that started this thread: http://groups.google.ca/groups?threadm=YLedndIVKMWwhn3cRVn-rA%40powergate.ca (Was it just on my server or did others get this strange repost?) -Peter From john at grulic.org.ar Thu Jan 13 19:14:53 2005 From: john at grulic.org.ar (John Lenton) Date: Thu, 13 Jan 2005 21:14:53 -0300 Subject: how to control the mouse pointer with python? In-Reply-To: <1105650438.311153.167410@f14g2000cwb.googlegroups.com> References: <1105650438.311153.167410@f14g2000cwb.googlegroups.com> Message-ID: <20050114001453.GC3727@grulic.org.ar> On Thu, Jan 13, 2005 at 01:07:18PM -0800, oglycans at yahoo.com wrote: > Hi. > Anybody know a way to control the mouse pointer > (move it around and click on things) using python? in X11, you could use Xlib to do so. In debian unstable, that's "apt-get install python-xlib{,-doc}", and start reading. -- John Lenton (john at grulic.org.ar) -- Random fortune: Obviously I was either onto something, or on something. -- Larry Wall on the creation of Perl -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From f.geiger at vol.at Thu Jan 13 01:50:18 2005 From: f.geiger at vol.at (F. GEIGER) Date: Thu, 13 Jan 2005 07:50:18 +0100 Subject: java 5 could like python? References: Message-ID: "vegetax" schrieb im Newsbeitrag news:mailman.568.1105544231.22381.python-list at python.org... > I was a java developer one year ago ,before i moved to python i realy liked > it at the beggining, but i got very disapointed lately since my > previus two python proyects where relatively big,and python didnt feel > well suited for the task. > > The reasons are mainly due to the standard library,the language > performance was aceptable, but the library, in my opinion has several grave > issues: > > -No naming convention. The speech of "it fits in my head" is no longer valid > when i use a lot of functionality,modules,classes in a large proyect. > > For example if i remember a function i want ie:get attribute, i dont > remember if the module implementer coded it as > getAttribute,GetAttribute,get_attribute, then i have to go and check the > doc, every time,which is a waste of time. Too many getters indicate bad design. But, ok, that's not the point here. I ask myself all the time, how people can dev software in *any* language w/o an IDE offering Intellisense (besides a decent clas browser, of course). You simply type "myObj.get" and the IDE looks the proper names up for you. Then you choose the right one and you are done with. WingIDE is such an IDE, and Kommodo too, I think. HTH Franz GEIGER From mahs at telcopartners.com Sat Jan 22 17:06:22 2005 From: mahs at telcopartners.com (Michael Spencer) Date: Sat, 22 Jan 2005 14:06:22 -0800 Subject: What YAML engine do you use? In-Reply-To: <7xoefhtavd.fsf@ruckus.brouhaha.com> References: <35a6tpF4gmat2U1@individual.net> <35csm7F4l57inU1@individual.net> <46ednYMe9-q4Om_cRVn-tQ@comcast.com> <35fo4iF4maov2U1@individual.net> <35fpq0F4mh1ffU1@individual.net> <7xoefhtavd.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > YAML looks to me to be completely insane, even compared to Python > lists. I think it would be great if the Python library exposed an > interface for parsing constant list and dict expressions, e.g.: > > [1, 2, 'Joe Smith', 8237972883334L, # comment > {'Favorite fruits': ['apple', 'banana', 'pear']}, # another comment > 'xyzzy', [3, 5, [3.14159, 2.71828, []]]] > > I don't see what YAML accomplishes that something like the above wouldn't. > > Note that all the values in the above have to be constant literals. > Don't suggest using eval. That would be a huge security hole. Not hard at all, thanks to compiler.ast: >>> import compiler ... >>> class AbstractVisitor(object): ... def __init__(self): ... self._cache = {} # dispatch table ... ... def visit(self, node,**kw): ... cls = node.__class__ ... meth = self._cache.setdefault(cls, ... getattr(self,'visit'+cls.__name__,self.default)) ... return meth(node, **kw) ... ... def default(self, node, **kw): ... for child in node.getChildNodes(): ... return self.visit(child, **kw) ... >>> class ConstEval(AbstractVisitor): ... def visitConst(self, node, **kw): ... return node.value ... ... def visitName(self,node, **kw): ... raise NameError, "Names are not resolved" ... ... def visitDict(self,node,**kw): ... return dict([(self.visit(k),self.visit(v)) for k,v in node.items]) ... ... def visitTuple(self,node, **kw): ... return tuple(self.visit(i) for i in node.nodes) ... ... def visitList(self,node, **kw): ... return [self.visit(i) for i in node.nodes] ... >>> ast = compiler.parse(source,"eval") >>> walker = ConstEval() >>> walker.visit(ast) [1, 2, 'Joe Smith', 8237972883334L, {'Favorite fruits': ['apple', 'banana', 'pear']}, 'xyzzy', [3, 5, [3.1415899999999999, 2.71828, []]]] Add sugar to taste Regards Michael From tim at zeos.net Tue Jan 25 03:45:21 2005 From: tim at zeos.net (Timothy Babytch) Date: Tue, 25 Jan 2005 10:45:21 +0200 Subject: ANN: LJ pyGTK clien Zapys-0.3 released Message-ID: Usable simple app for posting messages to LiveJournal. Easy extandable. Main feature: character substitution. I mean (tm) to ?, (c) to ?, quote to matching pairs and so on. The list can be easily extended with your own regexps. submit on Ctrl+Enter. Edit/delete last entry. screenshot: http://img.lj.com.ua/ilishin/zapys-3.png download: http://firefox.org.ua/misc/zapys-0.3.tar.bz2 From emschwar at fc.hp.com Wed Jan 26 20:19:49 2005 From: emschwar at fc.hp.com (Eric Schwartz) Date: Wed, 26 Jan 2005 18:19:49 -0700 Subject: [perl-python] 20050126 find replace strings in file References: <1106767140.027944.93380@c13g2000cwb.googlegroups.com> Message-ID: To follow up on Jurgen Exner's critique, I present Xah Lee's version, and then my rewritten version. "Xah Lee" writes: > if (scalar @ARGV != 4) {die "Wrong arg! Unix BNF: $0 > \n"} > $stext=$ARGV[0]; > $rtext=$ARGV[1]; > $infile = $ARGV[2]; > $outfile = $ARGV[3]; > open(F1, "<$infile") or die "Perl fucked up. Reason: $!"; > open(F2, ">$outfile") or die "Perl fucked up. Reason: $!"; > while ($line = ) { > chomp($line); > $line =~ s/$stext/$rtext/g; > print F2 "$line\n"; > } > close(F1) or die "Perl fucked up. Reason: $!"; > close(F2) or die "Perl fucked up. Reason: $!"; #!/usr/bin/perl use warnings; use strict; if (@ARGV != 4) { die "Wrong arg! Unix BNF: $0 " } my ($stext, $rtext, $infile, $outfile) = @ARGV; open my $infh, '<', $infile or die "Error opening input file [$infile]: $!"; open my $outfh, '>', $outfile or die "Error opening output file [$outfile]: $!"; while(<$infh>) { s/$stext/$rtext/g; print { $outfh } $_; } close($infh) or die "Error closing input file [$infile]: $!"; close($outfh) or die "Error closing output file [$outfile]: $!"; My version takes up more lines, but I don't count whitespace-- whitespace is not expensive, and when used properly adds greatly to the readability of your program. I've set followups to the only appropriate group for Mr. Lee's postings. -=Eric -- Come to think of it, there are already a million monkeys on a million typewriters, and Usenet is NOTHING like Shakespeare. -- Blair Houghton. From ramen at lackingtalent.com Tue Jan 18 12:53:43 2005 From: ramen at lackingtalent.com (Dave Benjamin) Date: Tue, 18 Jan 2005 10:53:43 -0700 Subject: One-Shot Property? In-Reply-To: <20050118115456510-0500@braeburn.themorgue.org> References: <20050118115456510-0500@braeburn.themorgue.org> Message-ID: <%2cHd.21965$ql2.16363@okepread04> Kevin Smith wrote: > I have many cases in my code where I use a property for calculating a > value on-demand. Quite a few of these only need to be called once. > After that the value is always the same. In these properties, I set a > variable in the instance as a cached value and return that value on > subsequent calls. It would be nice if there was a descriptor that would > do this automatically. Actually, what would be really nice is if I > could replace the property altogether and put the calculated value in > its place after the first call, but the property itself prevents me from > doing that. Is this possible? I was going to recommend taking a look at the "memoize" example on the Python wiki, but it seems to be missing at the moment. In any case, here's the URL: http://www.python.org/moin/PythonDecoratorLibrary There are also a few examples on the Cookbook, like this one: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/325205 It shouldn't be too difficult to adapt this technique so that it can be used to create properties. I wouldn't bother replacing the property with an attribute unless you have a specific reason to do so (performance, perhaps). HTH, Dave From fredrik at pythonware.com Sun Jan 23 08:15:59 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 23 Jan 2005 14:15:59 +0100 Subject: compile python to binary References: Message-ID: "sam" wrote: > I have seen some software written in python and delivered as binary form. > > How does these binary code get generated by python compiler? see section 6.1.2 in the tutorial: http://docs.python.org/tut/node8.html From donn at u.washington.edu Tue Jan 11 16:33:57 2005 From: donn at u.washington.edu (Donn Cave) Date: Tue, 11 Jan 2005 13:33:57 -0800 Subject: Securing a future for anonymous functions in Python References: <1105098890.358721.279550@f14g2000cwb.googlegroups.com> <1105289391.534192.74060@c13g2000cwb.googlegroups.com> <1105357625.835608.299560@c13g2000cwb.googlegroups.com> <10u5fu3o7v4h9e3@corp.supernews.com> <10u8e65lju3atbd@corp.supernews.com> Message-ID: In article <10u8e65lju3atbd at corp.supernews.com>, Jeff Shannon wrote: ... > From the sounds of it, you may have the opposite experience with > reading map/lambda vs. reading list comps, though, so we could go back > and forth on this all week without convincing the other. :) I'm with him. List incomprehensions do not parse well in my eyes. I am reduced to guessing what they mean by a kind of process of elimination. map is simply a function, so it doesn't pose any extra reading problem, and while lambda is awkward it isn't syntactically all that novel. Donn Cave, donn at u.washington.edu From jaydonnell at gmail.com Fri Jan 21 20:19:49 2005 From: jaydonnell at gmail.com (Jay donnell) Date: 21 Jan 2005 17:19:49 -0800 Subject: why am I getting a segmentation fault? In-Reply-To: <1106351339.457714.214940@f14g2000cwb.googlegroups.com> References: <1106330476.419418.46920@f14g2000cwb.googlegroups.com> <1106351339.457714.214940@f14g2000cwb.googlegroups.com> Message-ID: <1106356789.748649.259090@f14g2000cwb.googlegroups.com> >### Have you looked in your database to see if the >script has actually >updated item.goodImage? Do you have a test plan? Thank you for the help. Sorry for the messy code. I was under time constraints. I had class, and I was rushing to get this working before class. I should waited a day and read over it before I asked. Sorry again. From cbfalconer at yahoo.com Fri Jan 21 11:30:55 2005 From: cbfalconer at yahoo.com (CBFalconer) Date: Fri, 21 Jan 2005 16:30:55 GMT Subject: how to write a tutorial References: <1106305730.361540.21010@f14g2000cwb.googlegroups.com> Message-ID: <41F12912.3748FFB7@yahoo.com> Xah Lee wrote: > > i've started to read python tutorial recently. > http://python.org/doc/2.3.4/tut/tut.html > > Here are some quick critique: This has absolutely nothing to do with c.l.c, nor most of the cross-posted groups. F'ups set. Why did you do such a foul cross-posting in the first place. -- "If you want to post a followup via groups.google.com, don't use the broken "Reply" link at the bottom of the article. Click on "show options" at the top of the article, then click on the "Reply" at the bottom of the article headers." - Keith Thompson From reinhold-birkenfeld-nospam at wolke7.net Mon Jan 17 14:03:16 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Mon, 17 Jan 2005 20:03:16 +0100 Subject: Assigning to self In-Reply-To: References: Message-ID: <352gfkF4gq9a2U1@individual.net> Frans Englich wrote: > Hello, > > I am having trouble with throwing class instances around. Perhaps I'm > approaching my goals with the wrong solution, but here's nevertheless a > stripped down example which demonstrates my scenario: > > #------------------------------------------------------------------------------------------ > > class foo: > tests = {} > def __init__( self, id ): > > try: > me = self.__class__.tests[ id ] > > except KeyError: > print "Did not exist, initializing myself.." > self.attr = "exists" > self.__class__.tests[ id ] = self > > else: > print "Already exists! Re-using existing instance" > self = me > > print "Me", self.attr + "!" # line 18 > > def yo(self): > return self.attr # line 21 As 'self' is a method parameter, changing it only affects the current function. When __init__ is called, the instance is already created, so you can't change it. What you are looking for is a class factory (is this term correct?), here is a sample implementation (using 2.4 decorators): class foo: tests = {} @classmethod def get_test(cls, id): if cls.tests.has_key(id): return cls.tests[id] else: inst = cls() inst.attr = "exists" cls.tests[id] = inst return inst def yo(self): return self.attr Here you define get_test as a classmethod, that is, it does not receive the instance as first argument, but the class. It can be called from the class (foo.get_test) or an instance (foo().get_test). An alternative might be to override __new__, but I'm sure someone other will suggest this. Reinhold From francis.girard at free.fr Tue Jan 25 16:11:41 2005 From: francis.girard at free.fr (Francis Girard) Date: Tue, 25 Jan 2005 22:11:41 +0100 Subject: Another scripting language implemented into Python itself? In-Reply-To: References: <1106624803.825442.73870@f14g2000cwb.googlegroups.com> Message-ID: <200501252211.43386.francis.girard@free.fr> Hi, I'm really not sure but there might be some way to embed Java Script within Jython. Or to run Jython from inside Java much like the jEdit editor. You then have Python to make some glue code between the C++ core and the Java Script. Java Script must be secure since it runs in browsers everywhere from my worst sex web sites ! I'm not really sure why the original poster want to use Python, I think it's to make the glue between C++ and the scripting engine. Nor am I really sure why java runs inside my browser ... Francis Girard FRANCE Le mardi 25 Janvier 2005 18:08, Cameron Laird a ?crit?: > In article <1106624803.825442.73870 at f14g2000cwb.googlegroups.com>, > Carl Banks wrote: > . > . > . > > >> Python, or Perl, or TCL, or Ruby, or PHP, > > > >Not PHP. PHP is one of the better (meaning less terrible) examples of > >what happens when you do this sort of thing, which is not saying a lot. > >PHP was originally not much more than a template engine with some > >crude operations and decision-making ability. Only its restricted > >problem domain has saved it from the junkheap where it belongs. > > > >TCL isn't that great in this regard, either, as it makes a lot of > >common operations that ought to be very simple terribly unweildy. > > . > . > . > I've lost track of the antecedent by the time of our arrival at > "this regard". I want to make it clear that, while Tcl certainly > is different from C and its imitators, and, in particular, insists > that arithmetic be expressed more verbosely than in most languages, > the cause is quite distinct from the imperfections perceived in > PHP. PHP is certainly an instance of "scope creep" in its semantics. > Tcl was designed from the beginning, though, and has budged little in > over a decade in its fundamentals; Tcl simply doesn't bother to "make > a lot of common operations ..." concise. From tim.golden at viacom-outdoor.co.uk Wed Jan 12 10:50:31 2005 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Wed, 12 Jan 2005 15:50:31 -0000 Subject: Excel module for Python Message-ID: <9A28C052FF32734DACB0A288A35339910359B1@vogbs009.gb.vo.local> [Simon Brunning] [sam ] wrote: | > No, I don't use MS windows. I need to generate Excel file | by printing | > data to it, just like Perl module Spreadsheet::WriteExcel. | | If you need to write out formulae, formratting, that kind of thing, | then I think you'll need to write a 'real' Excel file. I don't have a | clue how to do that - sorry. I think http://sourceforge.net/projects/pyxlwriter/ will do it; haven't used it myself, mind you. You need to know that the magic search term is "BIFF" which is -- for some reason -- the name of the Excel file format. TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From fredrik at pythonware.com Mon Jan 24 11:21:24 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 24 Jan 2005 17:21:24 +0100 Subject: Python 2.1 - 2.4 differences References: Message-ID: "BOOGIEMAN" wrote: >I found some e-book about Python 2.1, I want to print it but just to check > first if sintax of Python 2.1 is same as 2.4 ? almost everything that works under 2.1 works under 2.4. the opposite isn't always true, though. for more information on new stuff, see: http://www.python.org/doc/2.2.3/whatsnew/ http://www.python.org/doc/2.3.4/whatsnew/ http://www.python.org/doc/2.4/whatsnew/whatsnew24.html and http://effbot.org/zone/librarybook-py21.htm http://effbot.org/zone/librarybook-py22.htm http://effbot.org/zone/librarybook-py23.htm From jacek.generowicz at cern.ch Mon Jan 10 11:45:25 2005 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 10 Jan 2005 17:45:25 +0100 Subject: Securing a future for anonymous functions in Python References: <1105098890.358721.279550@f14g2000cwb.googlegroups.com> <1105289391.534192.74060@c13g2000cwb.googlegroups.com> <1105357625.835608.299560@c13g2000cwb.googlegroups.com> Message-ID: "Anna" writes: > Jacek Generowicz wrote: > > "Anna" writes: > > > > > With class and def, I at least have a *name* to start with - class > > > Square pretty obviously is going to have something to do with > > > geometric shapes, I would hope (or maybe with boring people...). > > > > Or maybe with multiplying something by itself. Or maybe the author > > made some changes in his program, and forgot to rename the class > > sensibly, and the class' functionality has nothing to do with squares > > of any sort any more. Or maybe he felt the name "Square" was very > > appropriate for something else in his program and inadvertently gave > > the same name to two different entities thereby clobbering the one > > whose use was intended at this point. > > Idjits abound. ;-) Yup ... which is one reason why lambda is so useful. Everything there is to know about it is right in front of your eyes. There is no chance that some idjit changed the meaning of lambda, or the code which appears within it (unless that refers to some external names, of course). > > So, IIUC, you consider > > > > def add_one(x): > > return x+1 > > > > map(add_one, seq) > > > > to be clearer than > > > > map(lambda x:x+1, seq) > > Completely, totally, and unambiguously: Curious. It's very much the other way around for me. > the version with the defined function is immediately clear to me; > the version with the lambda is decipherable, but requires > deciphering (even at 2nd and 3rd glance). But first, wouldn't > something like: > > [x+1 for x in seq] > > be even clearer? I'm glad you mentioned that. My next question was going to be something along the lines of what you think of the equivalent list comprehension, which is spectacularly devoid of any names to give you any hints whatsoever. As to whether it is clearer. That depends. I would venture to suggest that, given a pool of laboratory rats with no previous exposure to Python, more of them would understand the map-lambda than the list comprehension. There are no words in the list comprehension at all (besides the common "seq"): it's all syntax. Even if "map" and "lambda" ring no bells by association with anything you might have learned outside of Python, they sure are a lot easier to look up in the documentation. > Given an example more complex (which you must admit, lambdas usually > are) Well, they can't be _that_ much more complex in Python :-) But I'll grant you, they are often more complex that the one above. > - the name of the function is something my brain can hold on to to > represent the group of operations; where with the lambda, I need to > mentally go through each operation each time I try to read it. And the > more complex f is, the harder time I have holding it all in my head > while I figure out how to get from the beginning value x to the ending > value f(x). lambda is an O(N*N) problem for my brain. Fair enough. If I understand the code just by looking at it, then I prefer to see it inline. If its meaning isn't obvious immediately, then I'd go for the named function too. But I still value the ability to inline-define the function while developing ... even if the inline function will be outlined in the final product. But, how do you feel about the individual lines of code in the body of a multi-line function? They don't have individual names. > I could see someone more mathematically-minded being happier with > lambda. It's not, after all, the word "lambda" itself; Aaah ... you did suggest (upthread) that it was the word itself which gave you problems ... which is what piqued my interest. From invalidemail at aerojockey.com Fri Jan 21 12:57:24 2005 From: invalidemail at aerojockey.com (Carl Banks) Date: 21 Jan 2005 09:57:24 -0800 Subject: Funny Python error messages In-Reply-To: References: <1106315907.551660.276380@c13g2000cwb.googlegroups.com> Message-ID: <1106330244.724582.226020@z14g2000cwz.googlegroups.com> Peter Hansen wrote: > Will Stuyvesant wrote: > > Perhaps this will even be a useful thread, to brighten the > > life of the brave people doing the hard work of providing us > > with error messages. > > > > My first one (i'm learning, i'm learning) is > > > > TypeError: 'callable-iterator' object is not callable > > > > # >>> it = iter(lambda:0, 0) > > # >>> it() > > # TypeError: 'callable-iterator' object is not callable > > Given that the supposed humour depends on the *name* of > the object, which is "callable-iterator", I'd say it's > probably not hard to come up with lots of "funny" error > messages this way. The mildly amusing nature of this error message is due to Will's finding a name, "callable-iterator" (where callable is a name, not a description), appearing in a different context from where it was coined that causes us to parse it differently (where callable is a description, not a name), and accidentally stating an absurdity. I'd say it's actually a nice bit of subtlety. -- CARL BANKS From noreply at python.org Tue Jan 18 07:38:33 2005 From: noreply at python.org (Mail Administrator) Date: Tue, 18 Jan 2005 13:38:33 +0100 Subject: MDaemon Warning - virus found: Returned mail: Data format error Message-ID: <20050118123933.971AB1E4003@bag.python.org> ******************************* WARNING ****************************** Este mensaje ha sido analizado por MDaemon AntiVirus y ha encontrado un fichero anexo(s) infectado(s). Por favor revise el reporte de abajo. Attachment Virus name Action taken ---------------------------------------------------------------------- instruction.zip I-Worm.Mydoom.m Removed ********************************************************************** Your message was undeliverable due to the following reason: Your message was not delivered because the destination server was unreachable within the allowed queue period. The amount of time a message is queued before it is returned depends on local configura- tion parameters. Most likely there is a network problem that prevented delivery, but it is also possible that the computer is turned off, or does not have a mail system running right now. Your message could not be delivered within 8 days: Mail server 169.58.69.124 is not responding. The following recipients did not receive this message: Please reply to postmaster at python.org if you feel this message to be in error. From Scott.Daniels at Acm.Org Wed Jan 12 10:04:38 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 12 Jan 2005 07:04:38 -0800 Subject: Help Optimizing Word Search In-Reply-To: <7xacrfl78y.fsf@ruckus.brouhaha.com> References: <1105486769.730769.165710@c13g2000cwb.googlegroups.com> <7xacrfl78y.fsf@ruckus.brouhaha.com> Message-ID: <41e53998$1@nntp0.pdx.net> Paul Rubin wrote: > "Case Nelson" writes: > >>Basically, the program needs to take in a random list of no more than >>10 letters, and find all possible mutations that match a word in my >>dictionary (80k words). However a wildcard letter '?' is also an >>acceptable character which increases the worst case time significantly. > > > For that size pattern and dictionary, simply compiling the pattern to > a regexp, joining the dictionary together into one big string ("abc > def ghijk..."), and matching the regexp against the big string, may > well be faster than using some fancy algorithm coded completely in > python. If these queries happen often, build a dictionary of sorted letters to lists-of-words. The setup will be slow, but use of such a secondary dictionary should be quite fast, with relatively easy dealing with ?s by iterations. --Scott David Daniels Scott.Daniels at Acm.Org From stephen.thorne at gmail.com Thu Jan 13 04:26:54 2005 From: stephen.thorne at gmail.com (Stephen Thorne) Date: Thu, 13 Jan 2005 19:26:54 +1000 Subject: newbie q In-Reply-To: <34mku4F4c8bdkU1@individual.net> References: <34mgq0F4dq4buU1@individual.net> <34mku4F4c8bdkU1@individual.net> Message-ID: <3e8ca5c8050113012633ac6155@mail.gmail.com> On Thu, 13 Jan 2005 17:05:39 +1000, Egor Bolonev wrote: > > "Stephen Thorne" ???????/???????? ? ???????? > ?????????: news:mailman.611.1105598828.22381.python-list at python.org... > On Thu, 13 Jan 2005 15:55:10 +1000, Egor Bolonev wrote: > > how to get rid of 'for' operator in the code? > > > > import os, os.path > > > > def _test(): > > src = 'C:\\Documents and Settings\\????\\My Documents\\My Music\\' > > > > for i in [x for x in os.listdir(src) if > > os.path.isfile(os.path.join(src, > > x)) and len(x.split('.')) > 1 and x.split('.')[-1].lower() == 'm3u']: > > os.remove(os.path.join(src, i)) > > > > if __name__ == '__main__': > > _test() > > import glob > for x in glob.glob("*.m3u"): > os.remove(x) > > i want to wipe out 'for x in []: f(x)' using map, lambda, reduce, filter and > List > Comprehensions [x for x in []] > just don't get how to add string to all elements of list Here's a few ways, map(os.remove, glob.glob("*.m3u")) [os.remove(x) for x in glob.glob("*.m3u")] [os.remove(x) for x in os.listdir(src) if os.path.isfile(os.path.join(src, x)) and len(x.split('.')) > 1 and x.split('.')[-1].lower() == 'm3u'] def myfilter(x): return os.path.isfile(os.path.join(src, x)) and len(x.split('.')) > 1 and x.split('.')[-1].lower() == 'm3u' map(os.remove, filter(myfilter, os.listdir(src))) Regards, Stephen Thorne. From bulba at bulba.com Tue Jan 4 12:55:43 2005 From: bulba at bulba.com (Bulba!) Date: Tue, 04 Jan 2005 18:55:43 +0100 Subject: The Industry choice References: <1104425916.615972.97530@z14g2000cwz.googlegroups.com> <86ekh3qv1o.fsf@guru.mired.org> Message-ID: <03mlt0di3rcntvu7rlrk9k2m9bq8435bs5@4ax.com> On Sun, 02 Jan 2005 17:18:43 -0600, Mike Meyer wrote: >> This "free software" (not so much OSS) notion "but you can >> hire programmers to fix it" doesn't really happen in practice, >> at least not frequently: because this company/guy remains >> ALONE with this technology, the costs are unacceptable. > >Yes, but fixing python software - even sloppily written python >software - is pretty easy. I regularly see contracts to add a feature >to or fix a bug in some bit of OSS Python. That's remarkable, first time I see smth like this - out of curiosity, could you say a word where was that? -- Real world is perfectly indifferent to lies that are the foundation of leftist "thinking". From enleverlesO.OmcO at OmclaveauO.com Fri Jan 28 08:25:34 2005 From: enleverlesO.OmcO at OmclaveauO.com (Do Re Mi chel La Si Do) Date: Fri, 28 Jan 2005 14:25:34 +0100 Subject: How to post news articles with NNTPlib References: <1106911698.786860.109450@z14g2000cwz.googlegroups.com> Message-ID: <41fa577c$0$25809$8fcfb975@news.wanadoo.fr> Hi ! nntplib.NNTP(newsserver,port,user,passe) -- Michel Claveau From tchur at optushome.com.au Mon Jan 31 16:15:08 2005 From: tchur at optushome.com.au (Tim Churches) Date: Tue, 01 Feb 2005 08:15:08 +1100 Subject: python and gpl In-Reply-To: References: Message-ID: <41FE9FDC.4080808@optushome.com.au> John Hunter wrote: >I have a question about what it takes to trigger GPL restrictions in >python code which conditionally uses a GPL library. > >Here is the context of my question. matplotlib, which I develop, is a >plotting module which is distributed under a PSF compatible license, >and hence we avoid using GPLd code so as to not trigger the GPL >requirements. matplotlib has rigid segregation between the front end >(plotting commands, figure objects, etc) and backends (gtk, wx, ps, >svg, etc). The backend is chosen dynamically at runtime -- eg the >same python script could trigger the import gtk, wx, or ps, depending >an some rc settings or command line opts. > >The question is: does shipping a backend which imports a module that >links with GPL code make some or all of the library GPL. > We sought formal legal advice on this issue from a lawyer with expertise in open source licensing - in our case, our application which is licensed under a (very slightly) modifided version of the Mozilla Public License v1.1 imports a GPLed Python module (RPy) which wraps a GPLed library (R). The answer was that the GPL does not apply to combination of code at run-time. Specifically, Section 0., Para 1 (assuming zero-based paragraph numbering...) says: "Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted,..." Furthermore, Section 2 para 1 says: "These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. ..." and Section 2 para 3 says: "In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License." On the basis of these clauses, the legal advice to us was that merely including "import rpy" and making calls to RPy-wrapped R functions does not invoke the provisions of the GPL because these calls only relate to run-time linking, which is not covered by the GPL. However, combining GPLed source code or static linking would invoke the GPL provisions. Additionally, we were advised to (re-)distribute any GPLed components required by our application in clearly separate packages i.e as separate tarballs or zip files, and not to bind them together in an omnibus distribution or installation file. However, putting them on the same CD-ROM or other media is fine. Note that the formal advice was specific to Australian law, and did mention some Australian case law regarding fair use under the Copyright Act with respect to making API calls - that relates to our application making API calls to the GPLed library which is imported at runtime. The opinion was that we were on safe ground here, but you might want to investigate this aspect wrt copyright laws in other countries. My understanding is that most copyright law provides for "fair use" which may cover use of parts of an API to a GPLed library (as distinct from complete incorporation of the entire API into another application - which would invoke the GPL). IANAL, and the above constitutes mangled paraphrasing of carefully worded formal legal advice, the scope of which was restricted to Australian law. However, the sections of the GPL quoted above are pretty unambiguous. The other, informal advice, was to ignore the FAQs and other opinions on the FSF web site regarding intepretation of the GPL - it's only the license text which counts. Tim C From invalidemail at aerojockey.com Sat Jan 8 19:25:50 2005 From: invalidemail at aerojockey.com (Carl Banks) Date: 8 Jan 2005 16:25:50 -0800 Subject: python3: 'where' keyword In-Reply-To: <7xk6qnzd3d.fsf@ruckus.brouhaha.com> References: <3480qqF46jprlU1@individual.net> <1105228549.608275.148740@c13g2000cwb.googlegroups.com> <7xk6qnzd3d.fsf@ruckus.brouhaha.com> Message-ID: <1105230350.861683.265970@c13g2000cwb.googlegroups.com> Paul Rubin wrote: > "Carl Banks" writes: > > You misunderstand. BTW, Peter, I guess I should have said "I misunderstand, but it can be legal if you consider it part of the statements", since it appears the author did intend it to be part of an expression. > > There "where" is not part of the expression but the > > statement. The above example would be a modified print statement, a > > print...where statement, if you will. Under this suggestion, there > > would be modified versions of various simple statements. > > You mean I can't say > > # compute sqrt(2) + sqrt(3) > x = (sqrt(a) where: > a = 2.) \ > + sqrt (a) where: > a = 3. > > Hmmm. What would be the advantage of that over this? . x = sqrt(a) + sqrt(b) where: . a = 2.0 . b = 3.0 Where would making "where" part of an expression rather than part of the statement help? Can you think of a place? ("That it makes Python more like LISP" is not a good enough answer for me, BTW. But feel free to try. :) -- CARL BANKS From bokr at oz.net Fri Jan 21 20:29:09 2005 From: bokr at oz.net (Bengt Richter) Date: Sat, 22 Jan 2005 01:29:09 GMT Subject: What YAML engine do you use? References: <35a6tpF4gmat2U1@individual.net> <7x1xcfwbab.fsf@ruckus.brouhaha.com> <35csm7F4l57inU1@individual.net> Message-ID: <41f1a3e6.1477492061@news.oz.net> On Fri, 21 Jan 2005 12:04:10 -0600, "A.M. Kuchling" wrote: >On Fri, 21 Jan 2005 18:30:47 +0100, > rm wrote: >> Nowadays, people are trying to create binary XML, XML databases, >> graphics in XML (btw, I'm quite impressed by SVG), you have XSLT, you >> have XSL-FO, ... . > >Which is an argument in favor of XML -- it's where the activity is, so it's >quite likely you'll encounter the need to know XML. Few projects use YAML, >so the chance of having to know its syntactic details is small. > I thought XML was a good idea, but IMO requiring quotes around even integer attribute values was an unfortunate decision. I don't buy their rationale of keeping parsing simple -- as if extracting a string with no embedded space from between an equal sign and terminating white space were that much harder than extracting the same delimited by double quotes. The result is cluttering SVG with needless cruft around numerical graphics parameters. OTOH, I think the HTML XML spec is very readable, and nicely designed. At least the version 1.0 spec I snagged from W3C a long time ago. ... I see the third edition at http://www.w3.org/TR/REC-xml/ is differently styled, (I guess new style sheets) but still pretty readable (glancing at it now). Regards, Bengt Richter From friedmud at gmail.com Mon Jan 31 13:13:00 2005 From: friedmud at gmail.com (friedmud at gmail.com) Date: 31 Jan 2005 10:13:00 -0800 Subject: Relocatable binary installs.... Message-ID: <1107195180.462949.222980@z14g2000cwz.googlegroups.com> Hello all, I'm currently working on a software package that is going to be distributed in binary form (with accompanying source) for lot of different unixes (Linux, AIX, HP-UX and others). Parts of the package are written in Python... so we are going to want to distribute our own version of python. Right now we are just distributing the Python tarball and building it at install time. This works ok, but we are running into some problems on some machines with weird default installs (DEC Alphas in particular).... some of them won't build all the python modules we want (although our in house machines will). What I want to do is compile python statically into binaries and then plop them wherever our customers choose to do an install (we will provide the source tarballs on a cd as well). The problem we are running into is that when we do this python continues to think it's still installed where it was initially compiled and not where it has been placed (which causes some problems with traceback and some other functions). Is there a way to make a relocateable python binary... that is... a python installation that won't care where it is on the machine... and won't care if it gets put somewhere else besides / ? Sorry for the long winded post... just want to make sure you understand my problem. Thanks in advance for any help! Derek From forestiero at qwest.net Tue Jan 11 23:04:20 2005 From: forestiero at qwest.net (DogWalker) Date: Tue, 11 Jan 2005 20:04:20 -0800 Subject: Python.org, Website of Satan In-Reply-To: <1105500724.648914.213880@z14g2000cwz.googlegroups.com> References: <1105495569.479185.166340@z14g2000cwz.googlegroups.com> <1105500724.648914.213880@z14g2000cwz.googlegroups.com> Message-ID: <20050112040212.8028.64816@linux.local> "Luis M. Gonzalez" said: >humblythegreat... at usa.com wrote: >> python.org = 194.109.137.226 >> >> 194 + 109 + 137 + 226 = 666 >> >> What is this website with such a demonic name and IP address? What >> evils are the programmers who use this language up to? >You dared to unveil our secret. >Now we'll have to kill you... > But is 194.109.137.226 the only one? What other sites are in league with the python? From josh at yucs.org Tue Jan 11 12:33:35 2005 From: josh at yucs.org (josh at yucs.org) Date: Tue, 11 Jan 2005 12:33:35 -0500 Subject: why not datetime.strptime() ? In-Reply-To: <16867.59681.423983.244528@montanaro.dyndns.org> References: <20050111021152.GA20127@yucs.org> <16867.59681.423983.244528@montanaro.dyndns.org> Message-ID: <20050111173335.GB26246@yucs.org> On Tue, Jan 11, 2005 at 08:56:33AM -0600, Skip Montanaro wrote: > * The seventh item returned from time.strptime() is the day of the week. > You're passing it into the microsecond arg of the datetime constructor Thanks! > and ignoring the timezone info (ninth item returned from > time.strptime(), eighth arg to the datetime constructor). > This is intentional. time.strptime() doesn't expose the timezone (only the daylight savings flag), so i'd have to duplicate its logic in order to distinguish between local time and utc. Since it's easy to explicitly call somedatetime.replace(tzinfo=sometzinfo), having strptime() always create "naive" datetimes seemed most sensible. > * It would be nice if the import happened only once and was cached: > > static PyObject *time_module; > ... > if (time_module == NULL && > (time_module = PyImport_ImportModule("time")) == NULL) > return NULL; > obj = PyObject_CallMethod(time_module, ...); The datetime is full of these calls. Would it make sense to make this a separate patch? (Or maybe the PyImport_ImportModule could implement such a cache :) ?) -------------- next part -------------- *** Modules/datetimemodule.c.orig 2003-10-20 10:34:46.000000000 -0400 --- Modules/datetimemodule.c 2005-01-11 12:19:36.839337336 -0500 *************** *** 3774,3779 **** --- 3774,3819 ---- return result; } + /* Return new datetime from time.strptime(). */ + static PyObject * + datetime_strptime(PyObject *cls, PyObject *args) + { + PyObject *result = NULL, *obj, *module; + const char *string, *format; + + if (!PyArg_ParseTuple(args, "ss:strptime", &string, &format)) + return NULL; + + if ((module = PyImport_ImportModule("time")) == NULL) + return NULL; + obj = PyObject_CallMethod(module, "strptime", "ss", string, format); + Py_DECREF(module); + + if (obj != NULL) { + int i, good_timetuple = 1; + long int ia[6]; + if (PySequence_Check(obj) && PySequence_Size(obj) >= 6) + for (i=0; i < 6; i++) { + PyObject *p = PySequence_GetItem(obj, i); + if (PyInt_Check(p)) + ia[i] = PyInt_AsLong(p); + else + good_timetuple = 0; + Py_DECREF(p); + } + else + good_timetuple = 0; + if (good_timetuple) + result = PyObject_CallFunction(cls, "iiiiii", + ia[0], ia[1], ia[2], ia[3], ia[4], ia[5]); + else + PyErr_SetString(PyExc_ValueError, + "unexpected value from time.strptime"); + Py_DECREF(obj); + } + return result; + } + /* Return new datetime from date/datetime and time arguments. */ static PyObject * datetime_combine(PyObject *cls, PyObject *args, PyObject *kw) *************** *** 4385,4390 **** --- 4425,4435 ---- PyDoc_STR("timestamp -> UTC datetime from a POSIX timestamp " "(like time.time()).")}, + {"strptime", (PyCFunction)datetime_strptime, + METH_VARARGS | METH_CLASS, + PyDoc_STR("strptime -> new datetime parsed from a string" + "(like time.strptime()).")}, + {"combine", (PyCFunction)datetime_combine, METH_VARARGS | METH_KEYWORDS | METH_CLASS, PyDoc_STR("date, time -> datetime with same date and time fields")}, *** Doc/lib/libdatetime.tex.orig 2003-09-06 01:36:56.000000000 -0400 --- Doc/lib/libdatetime.tex 2005-01-11 12:02:30.000000000 -0500 *************** *** 624,629 **** --- 624,636 ---- ignored. \end{methoddesc} + \begin{methoddesc}{strptime}{date_string, format} + Return the date corresponding to date_string, parsed according + to format. This is equivalent to \code{datetime(*(time.strptime( + date_string, format)[0:6]))}. \exception{ValueError} is raised if + \code{time.strptime()} returns a value which isn't a timetuple. + \end{methoddesc} + Class attributes: \begin{memberdesc}{min} *** Lib/test/test_datetime.py.orig 2005-01-11 11:56:36.000000000 -0500 --- Lib/test/test_datetime.py 2005-01-11 12:28:30.268243816 -0500 *************** *** 1351,1356 **** --- 1351,1365 ---- # Else try again a few times. self.failUnless(abs(from_timestamp - from_now) <= tolerance) + def test_strptime(self): + import time + + string = '2004-12-01' + format = '%Y-%m-%d' + expected = self.theclass(*(time.strptime(string, format)[0:6])) + got = self.theclass.strptime(string, format) + self.assertEqual(expected, got) + def test_more_timetuple(self): # This tests fields beyond those tested by the TestDate.test_timetuple. t = self.theclass(2004, 12, 31, 6, 22, 33) From gurpreet.sachdeva at gmail.com Thu Jan 6 02:47:11 2005 From: gurpreet.sachdeva at gmail.com (Gurpreet Sachdeva) Date: Thu, 6 Jan 2005 13:17:11 +0530 Subject: file.readlines() - gives me error (bad file descriptor) In-Reply-To: <2b7d8b42050105232546083758@mail.gmail.com> References: <1104992568.755808.326490@f14g2000cwb.googlegroups.com> <003801c4f3b9$af17fa20$0800a8c0@vishnu> <2b7d8b42050105232546083758@mail.gmail.com> Message-ID: On Thu, 6 Jan 2005 12:55:22 +0530, Binu K S wrote: >>>The file's current position moves as you write into it. I concure and have figured out the solution BUT while reading from the file from the position where the file handler is, should return "Null/Blank/Anything in this world" BUT should not write into the file... The information written was that in the Buffer of the handler... Does that mean reading a file will actually release the buffer by throwing the contents in the file??? Please Comment... >>>You normally wouldn't read from the file that you are writing into. May be applicable in handling logs... Regards, Garry From wittempj at hotmail.com Mon Jan 17 11:07:04 2005 From: wittempj at hotmail.com (wittempj at hotmail.com) Date: 17 Jan 2005 08:07:04 -0800 Subject: pychecker - sets.Set need to be overridden In-Reply-To: References: Message-ID: <1105978024.706237.304360@c13g2000cwb.googlegroups.com> mport sets class Foo: def __init__(self): self.x = sets.Set() x = Foo() print x, getattr(x, 'x') gives for me: <__main__.Foo instance at 0x00C578A0> Set([]) on 2.4. on WinXP. What environment do you run in? From mahs at telcopartners.com Tue Jan 25 15:05:53 2005 From: mahs at telcopartners.com (Michael Spencer) Date: Tue, 25 Jan 2005 12:05:53 -0800 Subject: limited python virtual machine (WAS: Another scripting language implemented into Python itself?) In-Reply-To: References: Message-ID: Steven Bethard wrote: > > I wish there was a way to, say, exec something with no builtins and > with import disabled, so you would have to specify all the available > bindings, e.g.: > > exec user_code in dict(ClassA=ClassA, ClassB=ClassB) > > but I suspect that even this wouldn't really solve the problem, > because you can do things like: > > py> class ClassA(object): > ... pass > ... > py> object, = ClassA.__bases__ > py> object > > py> int = object.__subclasses__()[2] > py> int > > > so you can retrieve a lot of the builtins. I don't know how to > retrieve __import__ this way, but as soon as you figure that out, you > can then do pretty much anything you want to. > > Steve Steve Safe eval recipe posted to cookbook: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469 Couldn't safe exec be programmed similarly? 'import' and 'from' are syntax, so trivially avoided Likewise, function calls are easily intercepted As you say, attribute access to core functions appears to present the challenge. It is easy to intercept attribute access, harder to know what's safe. If there were a known set of 'dangerous' objects e.g., sys, file, os etc... then these could be checked by identity against any attribute returned Of course, execution would be painfully slow, due to double - interpretation. Michael From fumanchu at amor.org Thu Jan 20 11:46:26 2005 From: fumanchu at amor.org (Robert Brewer) Date: Thu, 20 Jan 2005 08:46:26 -0800 Subject: QOTW from Ryan Tomayko Message-ID: <3A81C87DC164034AA4E2DDFE11D258E339822D@exchange.hqamor.amorhq.net> http://naeblis.cx/rtomayko/2005/01/20/getters-setters-fuxors "...Many people coming to Python can't believe no one uses IDEs. The automatic assumption is that Python is for old grey beards who are comfortable with vi and Emacs and refuse to accept breakthroughs in programming productivity like IDEs. Then they write a little Python code and realize that an IDE would just get in their way." FuManChu From bokr at oz.net Sat Jan 22 08:32:37 2005 From: bokr at oz.net (Bengt Richter) Date: Sat, 22 Jan 2005 13:32:37 GMT Subject: default value in a list References: <1106349263.943972.72710@f14g2000cwb.googlegroups.com> <10v39ald6em3u6f@corp.supernews.com> Message-ID: <41f24e9a.1521192118@news.oz.net> On Fri, 21 Jan 2005 17:04:11 -0800, Jeff Shannon wrote: >TB wrote: > >> Hi, >> >> Is there an elegant way to assign to a list from a list of unknown >> size? For example, how could you do something like: >> >> >>>>> a, b, c = (line.split(':')) >> >> if line could have less than three fields? > >(Note that you're actually assigning to a group of local variables, >via tuple unpacking, not assigning to a list...) > >One could also do something like this: > > >>> l = "a:b:c".split(':') > >>> a, b, c, d, e = l + ([None] * (5 - len(l))) > >>> print (a, b, c, d, e) >('a', 'b', 'c', None, None) > >>> Or >>> a, b, c, d, e = ('a:b:c'.split(':')+[None]*4)[:5] >>> print (a, b, c, d, e) ('a', 'b', 'c', None, None) You could even be profligate and use *5 in place of that *4, if that makes an easier idiom ;-) Works if there's too many too: >>> a, b = ('a:b:c'.split(':')+[None]*2)[:2] >>> print (a, b) ('a', 'b') > >Personally, though, I can't help but think that, if you're not certain >how many fields are in a string, then splitting it into independent >variables (rather than, say, a list or dict) *cannot* be an elegant >solution. If the fields deserve independent names, then they must >have a definite (and distinct) meaning; if they have a distinct >meaning (as opposed to being a series of similar items, in which case >you should keep them in a list), then which field is it that's >missing? Are you sure it's *always* the last fields? This feels to >me like the wrong solution to any problem. > >Hm, speaking of fields makes me think of classes. > > >>> class LineObj: >... def __init__(self, a=None, b=None, c=None, d=None, e=None): >... self.a = a >... self.b = b >... self.c = c >... self.d = d >... self.e = e >... > >>> l = "a:b:c".split(':') > >>> o = LineObj(*l) > >>> o.__dict__ >{'a': 'a', 'c': 'c', 'b': 'b', 'e': None, 'd': None} > >>> > >This is a bit more likely to be meaningful, in that there's almost >certainly some logical connection between the fields of the line >you're splitting and keeping them as a class demonstrates that >connection, but it still seems a bit smelly to me. > That gives me an idea: >>> def foo(a=None, b=None, c=None, d=None, e=None, *ignore): ... return a, b, c, d, e ... >>> a, b, c, d, e = foo(*'a:b:c'.split(':')) >>> print (a, b, c, d, e) ('a', 'b', 'c', None, None) But then, might as well do: >>> def bar(nreq, *args): ... if nreq <= len(args): return args[:nreq] ... return args+ (nreq-len(args))*(None,) ... >>> a, b, c, d, e = bar(5, *'a:b:c'.split(':')) >>> print (a, b, c, d, e) ('a', 'b', 'c', None, None) >>> a, b = bar(2, *'a:b:c'.split(':')) >>> print (a, b) ('a', 'b') >>> a, b, c = bar(3, *'a:b:c'.split(':')) >>> print (a, b, c) ('a', 'b', 'c') But usually, I would like n + tail, where I know n is a safe bet, e.g., >>> def ntail(n, *args): ... return args[:n]+(args[n:],) ... >>> a, b, t = ntail(2, *'a:b:c:d:e'.split(':')) >>> print (a, b, t) ('a', 'b', ('c', 'd', 'e')) >>> a, b, t = ntail(2, *'a:b'.split(':')) >>> print (a, b, t) ('a', 'b', ()) People have asked to be able to spell that as a, b, *t = 'a:b:c:d:e'.split(':') Regards, Bengt Richter From gsakkis at rutgers.edu Mon Jan 24 11:47:24 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Mon, 24 Jan 2005 11:47:24 -0500 Subject: Tuple slices Message-ID: <35kn4mF4o44ufU1@individual.net> Why does slicing a tuple returns a new tuple instead of a view of the existing one, given that tuples are immutable ? I ended up writing a custom ImmutableSequence class that does this, but I wonder why it is not implemented for tuples. George From craig at postnewspapers.com.au Sat Jan 1 05:51:20 2005 From: craig at postnewspapers.com.au (Craig Ringer) Date: Sat, 01 Jan 2005 18:51:20 +0800 Subject: exposing C array to python namespace: NumPy and array module. In-Reply-To: References: Message-ID: <1104576679.24895.41.camel@rasputin.localnet> On Sat, 2005-01-01 at 08:18, Bo Peng wrote: > Python's array module is built-in, easy to use, but *without* a > FromLenAndData function! Even the buffer interface provides only 'get > buffer' but no 'set buffer' functions. Could anyone tell me how I can > create an array object from existing data? Python has no array objects in the core language, only lists. The distinction is important when discussing numarray etc, because Python lists and NumPy etc arrays are very different. While you can build a Python list from a subsection of your C array, changes made in Python won't be pushed back to the C array it was created from. If this is OK, you can probably build the list using just a for loop - I'm not sure if there are any more efficient methods for variable length lists. If the Python user needs to be able to change the underlying array, I'd probably drop the use of the built-in list class entirely and write my own class that looks like a list (and smells like a list, and tastes like a list - lucky we didn't step in it!). It can be pretty simple, providing as few of the list protocol methods as: __getitem__ (a PyList_GetItem equivalent) __setitem__ (a PyList_SetItem equivalent) and preferably: __len__ __iter__ or as much of the list protocol as documented on the Python/C API page as you need. I'd probably implement the class in Python, and have my extension module provide a couple of simple functions to the underlying C array. These could be considered private to your list class. That'd make writing things like the __iter__ method much nicer, while still letting you implement __len__, __getitem__, __setitem__, etc in C. For example, I might write: class CArray(object): def __init__(self, ...): ... def __getitem__(self, index): _carray_getitem(self, index) def __len__(self): _carray_len(self, index) def __iter__(self): # build and return an interator using Python ... If you want to write part of your extension module in Python and part in C, there are two main ways to do it. The usual way is to write a 'wrapper' in Python that imports the C parts, wraps them where necessary or just pushes them into its own namespace, etc. The less common way is to import __builtins__ and __main__ into your C extension module's namespace then PyRun_String() python code in it to set things up. I find this approach MUCH more useful when embedding Python in an app and I only want to write small bits of my module in Python. The other alternative is to code your class entirely in C, implementing all the __methods__ as C functions. Unattractive as far as I'm concerned, but then I find constructing classes using Python's C API irritating and less clear than it could be. Here's the code -- hideously reformatted to avoid wrapping in the mail - in my initmodule() function that I use to set up the module so that Python code can execute in its namespace. You can ignore the const_cast<> stuff, chances are your compiler will ignore the const problems. ---- // 'd' is the dictionary of the extension module, as obtained // with PyModule_GetDict(module) PyObject* builtinModule = PyImport_ImportModuleEx( const_cast("__builtin__"), d, d, Py_BuildValue(const_cast("[]")) ); if (builtinModule == NULL) { // Error handling will not be shown; it'll depend on your module anyway. } PyDict_SetItemString(d, const_cast("__builtin__"), builtinModule); PyObject* exceptionsModule = PyImport_ImportModuleEx( const_cast("exceptions"), d, d, Py_BuildValue(const_cast("[]")) ); if (exceptionsModule == NULL) {} PyDict_SetItemString(d, const_cast("exceptions"), exceptionsModule); // We can now run Python code in the module's namespace. For // example (untested), as my real examples wouldn't do you any // good, they're too bound to the internal API of my module: QString python_code = ""; python_code += "def sample_function():\n"; python_code += " print \"See, it worked\"\n"; // My app sets sysdefaultencoding to utf-8, hence: char* python_code_cstring = python_code.utf8(); // Note that we pass our module dictionary as both // locals and globals. This makes the code effectively // run "in" the extension module, as if it was being // run during loading of a Python module after an // 'import' statement. PyObject* result = PyRun_String(python_code_cstring, Py_file_input, d,d); if (result == NULL) { qDebug("Python code to declare sample_function failed!"); PyErr_Print(); // also clears the exception } // Because 'result' may be NULL, not a PyObject*, we must call PyXDECREF not Py_DECREF Py_XDECREF(result); -- Ugh - I'd forgotten how ugly C code limited to 80 cols and without syntax highlighting really was. Especially when the reformatting is done as badly as I've done it. I hope you can make some sense out of that, anyway. Note that once the setup is done you can run as many python code snippets as you want, for declaring variables, functions, classes, etc. In my case, its easier to execute snippets as shown above than it is to worry about the module search path and wrapping things using a Python module. If you're doing substantial amounts of Python coding for your module, you'll almost certainly be better off writing a Python module that uses your C module internally (see PIL for a good example of this). -- Craig Ringer From wittempj at hotmail.com Mon Jan 17 12:19:47 2005 From: wittempj at hotmail.com (wittempj at hotmail.com) Date: 17 Jan 2005 09:19:47 -0800 Subject: How to prevent the script from stopping before it should In-Reply-To: <1105981979.853318.269300@c13g2000cwb.googlegroups.com> References: <1105981979.853318.269300@c13g2000cwb.googlegroups.com> Message-ID: <1105982387.852448.298900@c13g2000cwb.googlegroups.com> #import urllib, sys #pages = ['http://www.python.org', 'http://xxx'] #for i in pages: # try: # u = urllib.urlopen(i) # print u.geturl() # except Exception, e: # print >> sys.stderr, '%s: %s' % (e.__class__.__name__, e) will print an error if a page fails opening, rest opens fine From steven.bethard at gmail.com Mon Jan 10 01:12:58 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Sun, 09 Jan 2005 23:12:58 -0700 Subject: Python3: on removing map, reduce, filter In-Reply-To: <1105314195.310792.163170@c13g2000cwb.googlegroups.com> References: <34csn1F4a46hqU1@individual.net> <7xekguof4a.fsf@ruckus.brouhaha.com> <34ctkpF4b9ijlU1@individual.net> <-7mdndrwD_1qOHzcRVn-qQ@comcast.com> <1105314195.310792.163170@c13g2000cwb.googlegroups.com> Message-ID: John Machin wrote: > Steven Bethard wrote: >> Note that list comprehensions are also C-implemented, AFAIK. > > Rather strange meaning attached to "C-implemented". The implementation > generates the code that would have been generated had you written out > the loop yourself, with a speed boost (compared with the fastest DIY > approach) from using a special-purpose opcode LIST_APPEND. See below. Fair enough. ;) So you basically replace the SETUP_LOOP, CALL_FUNCTION, POP_TOP and POP_BLOCK with a DUP_TOP and a LIST_APPEND. Steve From quentel.pierre at wanadoo.fr Sat Jan 8 05:22:19 2005 From: quentel.pierre at wanadoo.fr (Pierre Quentel) Date: Sat, 08 Jan 2005 11:22:19 +0100 Subject: Another look at language comparisons Message-ID: <41dfb45d$0$19405$8fcfb975@news.wanadoo.fr> http://khason.biz/blog/2004/12/why-microsoft-can-blow-off-with-c.html From mesteve_bpleaseremovethis at hotmail.com Sun Jan 2 12:26:02 2005 From: mesteve_bpleaseremovethis at hotmail.com (StvB) Date: Sun, 02 Jan 2005 17:26:02 GMT Subject: Python! Is! Truly! Amazing! References: <1104657461.868175.252380@c13g2000cwb.googlegroups.com> <1104657909.340055.283710@z14g2000cwz.googlegroups.com> <1104668455.691428.12670@c13g2000cwb.googlegroups.com> Message-ID: you did this with pygame!!?? "Erik Bethke" wrote in message news:1104668455.691428.12670 at c13g2000cwb.googlegroups.com... > somehow lost my j's: > > www.erikbethke.com/Python/screenshot02.jpg > www.erikbethke.com/Python/screenshot03.jpg > www.erikbethke.com/Python/screenshot04.jpg > www.erikbethke.com/Python/screenshot05.jpg > From quentel.pierre at wanadoo.fr Sat Jan 22 03:31:04 2005 From: quentel.pierre at wanadoo.fr (Pierre Quentel) Date: Sat, 22 Jan 2005 09:31:04 +0100 Subject: Comments in configuration files Message-ID: <41f20f4a$0$6599$8fcfb975@news.wanadoo.fr> Bonjour, I am developing an application and I have a configuration file with a lot of comments to help the application users understand what the options mean I would like it to be editable, through a web browser or a GUI application. With ConfigParser I can read the configuration file and edit the options, but when I write the result all the comments are lost Are there modules that work on the same kind of ini files (for the needs of my application, I prefer this format to XML or YAML) and don't remove the comments ? TIA, Pierre From martin at v.loewis.de Sun Jan 16 04:41:40 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 16 Jan 2005 10:41:40 +0100 Subject: deleting from tarfile In-Reply-To: References: Message-ID: <41EA36D4.6090409@v.loewis.de> Mark McEahern wrote: > It doesn't appear so. A workaround, of course, is to create a new file > with the subset of files from the old file: That is actually the *only* way to do that. tarfiles cannot be "sparse", in the sense that parts of the file can be marked as deleted. So in order to delete a file, you have to copy the entire tarfile, and skip the file you want to delete - whether you do this yourself, or whether tarfile.py does it for you. Regards, Martin From jcarlson at uci.edu Sat Jan 22 15:40:18 2005 From: jcarlson at uci.edu (Josiah Carlson) Date: Sat, 22 Jan 2005 12:40:18 -0800 Subject: IDLE Problem in Windows XP In-Reply-To: <41F03130.4080709@cc.gatech.edu> References: <41F03130.4080709@cc.gatech.edu> Message-ID: <20050122123747.F647.JCARLSON@uci.edu> Branden Smith wrote: > > Hi, > > I am a teaching assistant for an introductory course at Georgia Tech > which uses Python, and I have a student who has been unable to start > IDLE on her Windows XP Home Edition machine. Clicking on the shortcut > (or the program executable) causes the hourglass to appear momentarily > (and the process to momentarily appear in the process monitor), but > nothing happens thereafter. ... > Does anyone have any ideas as to what might cause this problem? It shows > up with both Python 2.4 and 2.3. Version 2.2 works as it should. It is probably the socket issue. To get past the socket issue, according to the idle docs: Running without a subprocess: If IDLE is started with the -n command line switch it will run in a single process and will not create the subprocess which runs the RPC Python execution server. This can be useful if Python cannot create the subprocess or the RPC socket interface on your platform. However, in this mode user code is not isolated from IDLE itself. Also, the environment is not restarted when Run/Run Module (F5) is selected. If your code has been modified, you must reload() the affected modules and re-import any specific items (e.g. from foo import baz) if the changes are to take effect. For these reasons, it is preferable to run IDLE with the default subprocess if at all possible. That is, have the student modify the shortcut to pass a '-n' argument (without the quotes) to the command. If it works, great, if it doesn't, a traceback would be helpful. - Josiah From irmen at -nospam-remove-this-xs4all.nl Mon Jan 3 18:39:41 2005 From: irmen at -nospam-remove-this-xs4all.nl (Irmen de Jong) Date: Tue, 04 Jan 2005 00:39:41 +0100 Subject: How to access database? In-Reply-To: References: Message-ID: <41d9d7bd$0$6219$e4fe514c@news.xs4all.nl> Florian Lindner wrote: > AFAIK python has a generic API for database access which adapters are > supposed to implement. How can I found API documentation on the API? http://www.python.org/topics/database/ --Irmen From mike.kreiner at gmail.com Tue Jan 25 00:45:07 2005 From: mike.kreiner at gmail.com (mike kreiner) Date: 24 Jan 2005 21:45:07 -0800 Subject: scipy.signal.convolve2d() clips off part of my image Message-ID: <1106631907.600618.324390@c13g2000cwb.googlegroups.com> I'm using the convolve2d(image, mask) function from scipy to blur an image. The image I'm using is 512 by 384. When I display the image that convolve2d returns, the the left-most square of pixels (388 by 388) turn out fine, blurred and everything, however the right side of the image is all black. I've uploaded the practice image to: http://tinypic.com/1g3iox The output image is: http://tinypic.com/1g3iv9 here's what I entered at the intereactive window: >>> import scipy >>> img = scipy.imread("c:\\practice.jpg",flatten=True) >>> img.shape (384, 512) >>> mask = (1.0/115)*scipy.array([[2,4,5,4,2],[4,9,12,9,4],[5,12,15,12,5],[4,9,12,9,4],[2,4,5,4,2]]) >>> blurredImg = scipy.signal.convolve2d(img, mask) >>> scipy.imsave("c:\\blurred.jpg",blurredImg) Also, I noticed that the shape attribute is (384, 512), even though windows and my image editor say the image is 512 by 384. Could this have something to do with the reason convolve2d() only works right on the left-most 388 by 388 pixels? Thanks for any help. -Mike Kreiner From fredrik at pythonware.com Sun Jan 23 14:10:27 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 23 Jan 2005 20:10:27 +0100 Subject: on the way to find pi! References: <20050123184955.25121.qmail@web61005.mail.yahoo.com> Message-ID: Ali Polatel wrote: > write the code type str(pi(5)) and see what I mean it helps if you post the code you want help with in your first post, so people don't have to guess. the pi function doesn't return anything, it prints the value to stdout (that's what the stdout.write things are doing). if a function doesn't return anything, Python automagically inserts a "return None", which explains the "None" you're seeing (well, it prints 3.1415None after your modification, so you probably did something else to get "3.1415'None'"). if you want the digits, you have to change the stdout.write calls to something else. say: def pi(n=-1): output = "" printed_decimal = False r = f((1,0,1,1)) while n != 0: if len(r) == 5: output += str(r[4]) if not printed_decimal: output += '.' printed_decimal = True n -= 1 r = f(r[:4]) return output (this returns a string. to convert it to a Python float, use float(pi(x)). if x is large enough, that gives you the same thing as math.pi). From http Tue Jan 4 19:46:36 2005 From: http (Paul Rubin) Date: 04 Jan 2005 16:46:36 -0800 Subject: Embedding a restricted python interpreter References: Message-ID: <7xacrohfdf.fsf@ruckus.brouhaha.com> Rolf Magnus writes: > I would like to embed a python interpreter within a program, but since that > program would be able to automatically download scripts from the internet, > I'd like to run those in a restricted environment, which basically means > that I want to allow only a specific set of modules to be used by the > scripts, so that it wouldn't be possible for them to remove files from the > hard drive, kill processes or do other nasty stuff. > Is there any way to do that with the standard python interpreter? Don't count on it. From philippecmartin at sbcglobal.net Tue Jan 18 05:45:28 2005 From: philippecmartin at sbcglobal.net (Philippe C. Martin) Date: Tue, 18 Jan 2005 11:45:28 +0100 Subject: Tkinter in thread hangs on windows but not on Linux Message-ID: <1106045128.6665.9.camel@localhost> Hi, I need to pop-up in a "modless" manner some windows from an existing Tkinter loop. The following code works OK under Linux: the second window opens, shows the information, and quits cleanly when destroyed. However, under windows, I get the second window without the content (so I hang in run I guess), and both the thread and the calling process hang. Any clue ? Thanks Philippe #******************************************************************************* class SC_DOCS(threading.Thread): __m_smg = None __m_title = None def __init__(self,p_msg,p_title): threading.Thread.__init__(self) self.__m_msg = p_msg self.__m_title = p_title #******************************************************************************* def run (self): l_r = Tk() l_r.title(self.__m_title) l_f = Frame(l_r) l_f.pack(side=TOP, expand=YES, fill=BOTH) l_st = ScrolledText(l_f) l_st.pack(side=TOP, expand=YES, fill=BOTH) l_st.insert(END,self.__m_msg) l_r.mainloop() . . . l_d = SC_DOCS('A MESSAGE', 'A TITLE') l_d.start() . . . -- *************************** Philippe C. Martin SnakeCard LLC www.snakecard.com *************************** From phr at localhost.localdomain Thu Jan 27 10:48:20 2005 From: phr at localhost.localdomain (phr at localhost.localdomain) Date: Thu, 27 Jan 2005 15:48:20 GMT Subject: What's so funny? WAS Re: rotor replacement References: <7x1xchlpqv.fsf@ruckus.brouhaha.com> <41efeb82$0$27807$9b622d9e@news.freenet.de> <41f1a70b$0$25959$9b622d9e@news.freenet.de> <7xllalcmqc.fsf@ruckus.brouhaha.com> <7xbrbhosh7.fsf@ruckus.brouhaha.com> <7xzmz0lw6h.fsf@ruckus.brouhaha.com> <41f4324a$0$1547$9b622d9e@news.freenet.de> <41f589f9$0$3357$9b622d9e@news.freenet.de> <41f6a8ef$0$27790$9b622d9e@news.freenet.de> <41f7efc2$0$11596$9b622d9e@news.freenet.de> Message-ID: Skip Montanaro writes: > phr> It is not a whizbang module. It is a stripped-down, basic > phr> implementation of a well-accepted set of standards that are being > phr> used in thousands of other applications in other languages. > > Then there should be a library already out there already. All you > should need to do is wrap it (manually, with SWIG, whatever). I'm currently using something wrapped with SWIG, but my understanding is that core modules are not supposed to depend on SWIG. So a core module will likely use some existing primitives wrapped by hand. That is what I've offered to do, along with providing a somewhat more Pythonic interface (though still a straightforward one) than directly wrapping a C library intended for use from C applications. > phr> There is demand for it. Look at how this thread started: some > phr> crypto user noticed that rotor was gone and wanted to know what to > phr> do instead. > > Yes, and putting rotor back would be the wrong thing to do. Correct. The right thing is to replace rotor with something reasonable that follows standards. > phr> The issue of whether there's enough desire for a crypto module to > phr> warrant including one in the stdlib was decided a long time ago. > phr> The proof of that somebody decided to accept the rotor module into > phr> the distro. > > No, rotor was added in Python's early days (July 1992). Times have changed. I don't see that. There's surely even more demand for crypto now than there was in 1992. > As long as we are discussing cryptography, what's wrong with m2crypto? > > http://sandbox.rulemaker.net/ngps/m2/ It's a good package but it's pretty heavyweight. It depends on both SWIG and OpenSSL. I think it's still under development--there's an occasional flurry of messages about it on python-crypto, but I haven't been following it closely. I'd have a hard time making a case for accepting it into the core given the difficulty I'm having making the case for something as simple as a block cipher wrapper. m2crypto+OpenSSL is at least 100 times as much code as the module I've proposed. I think the Python lib should someday have its own pure-Python SSL/TLS implementation sort of like the one Java has. But if m2crypto went into the lib, I'd use it. > Why not incorporate it into the standard distribution? I don't have the authority to incorporate anything into the standard distribution. All I can do is offer to contribute stuff that I write, and let the distro maintainers decide whether to incorporate it. I don't have the authority to offer m2crypto, since I'm not the author. Only the authors can do that. They haven't done so, as far as I know. > Or, what about Andrew Kuchling's crypto toolkit? > > http://www.amk.ca/python/code/crypto.html This is perhaps more suitable than m2crypto but as far as I know, Andrew hasn't offered to contribute it. Whatever his reasons are, I have to respect them. I think it has more stuff than a core crypto module really needs (e.g. numerous semi-obsolete algorithms that aren't in widespread use so aren't needed for interoperability) but the extra stuff doesn't really get in the way. If it were in the core, it would completely fulfill my desires and I would be transported with ecstacy. But I've never seen any indication that it's headed there. > I believe both have been around awhile. If crypto-in-the-core is > really what's needed why not see if one of them is ready to go? I don't think m2crypto is the answer, though maybe I'm wrong. And if Andrew's package is the answer, he would have submitted it already. > phr> Have you ever used a crypto library in a serious way? > > Nope, never directly. Don't make this about me. I'm interested in the > Python development process and how you'd like to turn it on its head. Either you're the one turning the actual process on its head, or else it's already on its head and needs to be turned rightside up. Either way, the existing process has certainly been a total failure so far at producing good crypto support in the lib. > phr> It's already the category king, because there are precisely zero > phr> other entrants in the category. > > See my above references. Note, I don't use crypto at all, yet I was aware > of both of these (no Googling required). The authors have not offered to contribute them, so they're not in the category. The category consists of crypto modules that have actually been offered. As I keep saying, I'd love it if someone else offered one. I'm not eager for this headache. I just saw that somebody really ought to do it, and nobody was doing it, so I decided I was elected. > My guess would be they are substantially more mature than your > proposed module. This may sound a little strange, since my module is not yet written, but if we take maturity to mean lower future maintenance needs, then I wouldn't say m2crypto is precisely more mature. m2crypto uses SWIG and is intimately connected to an immensely complex package (OpenSSL) anpd has to track new OpenSSL and SWIG releases. OpenSSL has all kinds of OS dependencies, has high performance math subsystems written in assembly code for various different cpu's, etc. So my guess is that m2crypto has a longer development curve and will always need significant amounts of maintenance. My module is more like a basic portable math library that computes square roots, cosines, etc. and is OS and CPU independent. Once written and tested, it's intended to be pretty solid and not need much attention. Andrew's package is along the same lines as mine, except Andrew's is already done, so Andrew's is definitely more mature. I like to think that my module's API incorporates some lessons from Andrew's and improves on it, but that's not that important in practice. > phr> I read those as saying that no crypto module will be > phr> considered for inclusion whether or not it's the category > phr> king, because any such module might conflict with crypto > phr> regulations in some countries. > > That may be a problem, sure. I'm not sure how the discussion here changes > that. That's just life as we know it. It doesn't change it. However, it does change my level of interest in writing a module, as is reasonable since the only important characteristics of my module that are different from existing ones is that mine is designed specifically to be suitable for the core and has been offered for distribution in the core. Outside the core, the existing modules work ok so I use them. > Why in the heck is inclusion in the standard library a requirement > for you to write this thing? There's no other reason to write it. Outside the stdlib, there are other modules that are already useable, like the ones you mentioned, so I use those. > If it's useful to you, write it and get on with your life. It's not worth doing unless it's intended for the stdlib. How many times do I have to explain this? > phr> Tell me again how rotor got into the distribution. > > Python's user community was probably a few hundred people. Guido > likely had no thoughts of world domination with the little language that > could. Times have changed. If Python is aiming for world domination, it needs to be able to compete with Java in security features. Java ships with the whole JSSE system and a much fancier low level crypto architecture than the one we've been discussing. So I think the Python folks should figure out how to incorporate crypto without getting crushed under the iron boot (or at least the wooden shoe) of the Dutch government or whatever it is that they're worried about. > You seem think there was a PEP process and distutils and Wikis. I > suspect some of the algorithms one might include in a robust crypto > toolkit today weren't even invented in 1992. AES wasn't invented then. DES became a US federal standard around 1977. > So throw away the rotor crutch and put your money where your mouth is. If you mean write yet another crypto module knowing ahead of time that it won't go into the stdlib, that would be more like throwing my money down the drain. From john at grulic.org.ar Tue Jan 18 13:33:10 2005 From: john at grulic.org.ar (John Lenton) Date: Tue, 18 Jan 2005 15:33:10 -0300 Subject: One-Shot Property? In-Reply-To: <20050118115456510-0500@braeburn.themorgue.org> References: <20050118115456510-0500@braeburn.themorgue.org> Message-ID: <20050118183245.GA13370@grulic.org.ar> On Tue, Jan 18, 2005 at 04:54:56PM +0000, Kevin Smith wrote: > > I have many cases in my code where I use a property for calculating a > value on-demand. Quite a few of these only need to be called once. > After that the value is always the same. In these properties, I set a > variable in the instance as a cached value and return that value on > subsequent calls. It would be nice if there was a descriptor that would > do this automatically. Actually, what would be really nice is if I > could replace the property altogether and put the calculated value in > its place after the first call, but the property itself prevents me from > doing that. Is this possible? consider this: 1 >>> class C: 2 ... x = property(str) 3 ... 4 >>> c = C() 5 >>> c.x 6 '<__main__.C instance at 0x4008d92c>' 7 >>> setattr(c, 'x', c.x) 8 >>> c.x 9 '<__main__.C instance at 0x4008d92c>' 10 >>> C.x 11 12 >>> c.x = 2 13 >>> in line 5 you see that the x property so defined works. In line 7 you remove it, replacing it with the computed value of the property. Line 9 shows that it worked, line 11 shows that it didn't break the class, and line 13 (through the absence of an exception) shows that it no longer is 'special' (as it shouldn't be). -- John Lenton (john at grulic.org.ar) -- Random fortune: You can tune a piano, but you can't tuna fish. You can tune a filesystem, but you can't tuna fish. -- from the tunefs(8) man page -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From xah at xahlee.org Fri Jan 14 22:34:41 2005 From: xah at xahlee.org (Xah Lee) Date: 14 Jan 2005 19:34:41 -0800 Subject: [perl-python] 20050114 if statement Message-ID: <1105760081.771782.140700@f14g2000cwb.googlegroups.com> . # here's an example of if statement in python. . . x=-1 . if x<0: . print 'neg' . elif x==0: . print 'zero' . elif x==1: . print 'one' . else: . print 'other' . . # the elif can be omitted. . ------------------------------ . # here's an example of if statement in perl . . $x=31; . if ($x<0) { . print 'neg' . } elsif ($x==0) { . print 'zero' . } elsif ($x==1) { . print 'one' . } else { . print 'other' . } . . . --------------------------- . . Note: this post is from the Perl-Python a-day mailing list at . http://groups.yahoo.com/group/perl-python/ . to subscribe, send an email to perl-python-subscribe at yahoogroups.com . if you are reading it on a web page, program examples may not run . because html conversion often breaks the code. . . Xah . xah at xahlee.org . http://xahlee.org/PageTwo_dir/more.html From klapotec at chello.at Wed Jan 5 01:44:30 2005 From: klapotec at chello.at (Christopher Koppler) Date: Wed, 05 Jan 2005 06:44:30 GMT Subject: % operation References: Message-ID: On Wed, 05 Jan 2005 15:36:30 +0900, Daewon YOON wrote: > ==== > Python 1.5.2 (#1, Jul 5 2001, 03:02:19) [GCC 2.96 20000731 (Red Hat > Linux 7.1 2 on linux-i386 > Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam > >>> x=9 > >>> y=4 > >>> x%y > 1 > >>> for z in range(44): > ... z%9 > File "", line 2 > z%9 > ^ > SyntaxError: invalid syntax > > ==== > What's wrong with the above operation and how can I get the correct > modulo result with Python? There's nothing wrong with the operation, but it looks like you forgot to indent your loop body (which the interactive shell doesn't automagically do for you): >>> for z in range(44): ... z%9 ... [result snipped] -- Christopher raise OutofSigError From daniel at bowettsolutions.com Wed Jan 26 03:27:34 2005 From: daniel at bowettsolutions.com (Daniel Bowett) Date: Wed, 26 Jan 2005 08:27:34 +0000 Subject: MySQLdb In-Reply-To: References: Message-ID: Dennis Lee Bieber wrote: > On Tue, 25 Jan 2005 20:43:54 +0000, Daniel Bowett > declaimed the following in > comp.lang.python: > > >>As a test I have written a script that executes 3000 insert statements >>on a table. The table contains 10 fields with a mix of text and numbers >>- its a product table for a website eg UPC, ProductName, Price etc. >> > > How many indices? > > >>The problem I have is that it takes just over two minuted to execute the >>3000 insert statements which seems really slow! I am running it on a > > > I recall reading that, for some RDBMs, when doing such batch > inserts, they recommend turning off the indices at the start, do the > inserts, then reactivate the indices -- apparently it is faster to > rebuild an index after the data has been inserted, then to continually > update the index. > UPC is my only index - its a varchar with 20 characters. I am only opening the connection once, then doing 3000 execute statements in a for loop. I do have two "TEXT" fields in the table which contain the long and short description. The average length of the long description is about 167 characters, the longest is 1800 characters. Is this whats making it slow? From asbach at ient.rwth-aachen.de Wed Jan 12 16:34:53 2005 From: asbach at ient.rwth-aachen.de (Mark Asbach) Date: Wed, 12 Jan 2005 22:34:53 +0100 Subject: GTK libs don't get events when wrapped for Python Message-ID: <1gqaqim.5ba4rn159bm4gN%asbach@ient.rwth-aachen.de> Hi list, I've got a crazy problem: an application fully written C and using a third-party library that itself uses GTK to draw some GUI widgets works as expected. But if I wrap the lib with SWIG and use it in Python, everythings works but the GUI parts. In fact, it looks like the library doesn't get events / messages from the window manager or these events have a significant delay. For example, I want to open a window and draw an image into it. This means two library calls. The first one should draw the window (but it only does when calling it from a C-only binary), the second one should resize the window and draw the image, but when called from python just draws the window. Occasionally, resize and in rare circumstances drawing of the image occur on subsequent calls of the library. Really strange and I don't have a clue where to look for a remedy. Is there anybody who could help me, please? FYI: the library used is Intel's OpenCV / HighGui, OS is debian/Sarge, python2.3 Thanks in advance, Mark -- Dipl.-Ing. Mark Asbach Tel +49 (0)241 80-27677 Institute of Communications Engineering RWTH Aachen University, Germany http://www.ient.rwth-aachen.de From bokr at oz.net Thu Jan 20 01:51:18 2005 From: bokr at oz.net (Bengt Richter) Date: Thu, 20 Jan 2005 06:51:18 GMT Subject: rotor replacement References: <7x1xcidnp1.fsf@ruckus.brouhaha.com> <41EE24F7.7030303@jessikat.fsnet.co.uk> <41EEF691.20706@jessikat.fsnet.co.uk> <7xacr4ewjk.fsf@ruckus.brouhaha.com> Message-ID: <41ef4a7a.1323588509@news.oz.net> On 19 Jan 2005 17:09:19 -0800, Paul Rubin wrote: >Robin Becker writes: >> > Presumably he is talking about crypo-export rules. In the past strong >> > cryptography has been treated as munitions, and as such exporting it >> > (especially from the USA) could have got you into very serious >> > trouble. >> >> well since rotor is a german (1930's) invention it is a bit late for >> Amricans (Hollywood notwithstanding) to be worried about its export > >1. I think the concern was not about exporting from the US, but rather >importing into some countries that restrict the use of crypto. But >the cat is out of the bag on that one too. Just about every web >browser includes an SSL stack and those browsers are in use >everywhere. Isn't the SSL dependent on OS or at least shared lib support? Wasn't there a default 40-bit version that was ok (weak), but you had to declare yourself US resident to download 128-bit support? I dimly recall encountering this sort of thing installing Netscape a long time ago, I think. Is 128 just standard now? And now that 128 is wobbly(?), will the same thing be replayed with the ante upped? > >2. It's irrelevant for the purpose of export rules how old an >invention is or where it was invented. I don't know where machine >guns were invented, but they're at least 100 years old and you can't >export those without a license either. My gripe with the crypto rules >are not about the age or nationality of crypto rotor machines (rotor >is not a clone of the Enigma by the way; it just operates on related >principles) but rather on the control of information in general. I can easily conceive of information that I'd rather not see publicized without severe access controls. But in general I do believe in open sharing of free information as the most productive for everyone. >Exporting a machine gun is much different from publishing a >description of one. Software is just a precise type of description. Yeah, but ... ;-) Regards, Bengt Richter From grig.gheorghiu at gmail.com Mon Jan 10 13:42:22 2005 From: grig.gheorghiu at gmail.com (Grig Gheorghiu) Date: 10 Jan 2005 10:42:22 -0800 Subject: Importing Problem on Windows References: <1105379352.302141.264580@f14g2000cwb.googlegroups.com> Message-ID: <1105382542.552797.125200@c13g2000cwb.googlegroups.com> What version of Python are you running on Linux vs. Windows? From richie at entrian.com Tue Jan 25 05:03:02 2005 From: richie at entrian.com (Richie Hindle) Date: Tue, 25 Jan 2005 10:03:02 +0000 Subject: Weakref.ref callbacks and eliminating __del__ methods In-Reply-To: <1f7befae05012411376821bb92@mail.gmail.com> References: <41F427EB.3000200@rogers.com> <1f7befae0501231720428ca3c@mail.gmail.com> <5lr9v0tg2i16irskb798f7rcti955j0c64@4ax.com> <1f7befae05012411376821bb92@mail.gmail.com> Message-ID: [Tim] > there's no 100% guarantee that a __del__ method will ever get called Can anyone point me to any definitive documentation on why this is the case? I was under the impression that __del__ would always be called: 1. for objects not in cycles and with no references 2. for objects whose only references are from cycles which themselves have no external references and no __del__methods, assuming that garbage collection runs. > __del__ methods (weakref callbacks too, for that matter) triggered > while Python is tearing itself down at exit may suffer bizarre > exceptions (due to trying to use facilities in partially-torn down > modules, including the module the __del__ method appears in). Good point. > In general, __del__ is a user-visible method like any other, and user > code may call it explicitly. For that reason, it's safest to write > __del__ methods in library objects such that they can be invoked > multiple times gracefully. Another good point - thanks. -- Richie Hindle richie at entrian.com From dmerrillq at usaq.netq Sat Jan 8 15:56:21 2005 From: dmerrillq at usaq.netq (Dave Merrill) Date: Sat, 8 Jan 2005 15:56:21 -0500 Subject: Installing IPython on win2k References: Message-ID: <4JqdnUwQgOFr1X3cRVn-gg@rcn.net> Fernando replied to a similar post of mine on the IPython list, and had a suggestion that for some unknown reason, worked. Or rather, what's unknown is why normal setup failed. For the benefit of anyone else who has this issue, I unzipped the files into C:\Program Files\ipython-0.6.6 ...then opened a DOS window, and did the following two cmds: cd C:\Program Files\ipython-0.6.6 "C:\Program Files\Python23\python.exe" setup.py install Tons of DOS cmds spat out, the shortcut was created, and launching it brought up the config wizard, then ipython. I'd really love it if ipython could be invoked in the current debugger context in PyDev under Eclipse. Is there any way to do that? Thanks again, Dave Merrill From fredrik at pythonware.com Sun Jan 23 17:52:29 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 23 Jan 2005 23:52:29 +0100 Subject: Set parity of a string References: <1f060c4c050123140310e6f887@mail.gmail.com> Message-ID: "snacktime" wrote: > Is there a module that sets the parity of a string? I have an > application that needs to communicate with a host using even parity > So what I need is before sending the message, convert it from space to > even parity. And when I get the response I need to convert that from > even to space parity. umm. shouldn't the communication library do this for you? From bulba at bulba.com Wed Jan 5 21:27:25 2005 From: bulba at bulba.com (Bulba!) Date: Thu, 06 Jan 2005 03:27:25 +0100 Subject: No typical loops, and other crazy ideas Message-ID: OK. I have reworked this program (below) to use just the data manipulation capabilities of Python (training was largely the motivation). I've tried to manipulate the data just in Python and not in typical loops. One thing that may not be entirely crazy in this, IMHO, is the attempt to use built-in capabilities of the language as much as possible instead of doing it "manually". Anyway, Python is the only language I've seen (apart from functional languages probably, but I have yet to get unconventional enough to wet my feet there) where it is possible. Still, it was not as easy as I wish it were: I've had to use 3 types of data structures (dictionaries, sets, lists) and arguably 6 "stages" (marked in comments below) to get it done. And it still dies when the source terms are not unique. And I haven't figured out the way of producing a list of dictionaries that would have this particular key as unique across all the dictionaries in this list. [Also, for some reason the advice by another poster, to use: oldl=list(orig) instead of: oldl=[x for x in orig] ..somehow didn't work. The first instruction has produced only empty lists.] #---------Code follows----------- import sys import csv from sets import Set as set class excelpoldialect(csv.Dialect): delimiter=';' doublequote=True lineterminator='\r\n' quotechar='"' quoting=0 skipinitialspace=False epdialect=excelpoldialect() csv.register_dialect('excelpol',epdialect) try: ofile=open(sys.argv[1],'rb') except IOError: print "Old file %s could not be opened" % (sys.argv[1]) sys.exit(1) try: tfile=open(sys.argv[2],'rb') except IOError: print "New file %s could not be opened" % (sys.argv[2]) sys.exit(1) titles=csv.reader(ofile, dialect='excelpol').next() orig=csv.DictReader(ofile, titles, dialect='excelpol') transl=csv.DictReader(tfile, titles, dialect='excelpol') cfile=open('cmpfile.csv','wb') titles.append('New') titles.append('RowChanged') cm=csv.DictWriter(cfile,titles, dialect='excelpol') cm.writerow(dict(zip(titles,titles))) print titles print "-------------" # 1. creating lists of old & new translations #oldl=list(orig) #newl=list(orig) oldl=[x for x in orig] newl=[x for x in transl] # oldl is a list of dictionaries like: # [{'Polish': 'Zarzadzanie', 'TermID': '5', 'English': 'Administration'}, # {'Polish': 'Zarzadzanie systemem', 'TermID': '4', 'English': 'System Administration'}, # {'Polish': 'Testowanie', 'TermID': '5', 'English': 'Testing'}] # 2. creation of intersection of sets of old and new English strings to find the common source strings oldeng=set([item['English'] for item in oldl]) neweng=set([item['English'] for item in newl]) matcheng = list(oldeng & neweng) # 3. eliminating items not containing the common source strings oldl=[x for x in oldl if x['English'] in matcheng] newl=[x for x in newl if x['English'] in matcheng] # 4. sorting lists oldl.sort(lambda a, b: cmp(a['English'], b['English'])) newl.sort(lambda a, b: cmp(a['English'], b['English'])) # 5. defining comparison function def matchpol(old,new): retval={'TermID': old['TermID'], 'English': old['English'], 'Polish': old['Polish'], 'New': new['Polish'], 'RowChanged': ''} if old['Polish'] != new['Polish']: retval['RowChanged']='CHANGED' return retval # 6. Constructing list of target dictionaries chglist=map(matchpol, oldl, newl) # 7. Writing to a target file cm.writerows(chglist) # the end.. cfile.close() ofile.close() tfile.close() -- It's a man's life in a Python Programming Association. From alipolatel at yahoo.com Sat Jan 29 19:23:29 2005 From: alipolatel at yahoo.com (Ali Polatel) Date: Sat, 29 Jan 2005 16:23:29 -0800 (PST) Subject: Proxy Message-ID: <20050130002329.4200.qmail@web61003.mail.yahoo.com> is it possible to connect to somewhere through a proxy while using sockets module of Python to connect? If yes can you show me some basic examples? regards --------------------------------- Do you Yahoo!? Yahoo! Search presents - Jib Jab's 'Second Term' -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin at v.loewis.de Sun Jan 23 18:29:55 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 24 Jan 2005 00:29:55 +0100 Subject: Alternative Ways to install Python 2.4? In-Reply-To: References: Message-ID: <41F43373.4020003@v.loewis.de> Michael Goettsche wrote: > I convinced my CS teacher to use Python in school. We currently have 2.2 > installed on a Windows 2000 Terminal server. I asked the system administrator > to upgrade to Python 2.4, but he didn't succeed in doing it. He used the > microsoft installer package, which according to him crashed when starting. > So my question is if there's an alternative way to install it(must be easy). > Would it be an option to remove 2.2 first and then try to install 2.4 again? That would be an option, but I doubt it helps. Please have a look at http://www.python.org/2.4/bugs.html Most likely, you need to upgrade Visual Basic on that machine. Of course, without a precise error description, it is hard to tell. Regards, Martin From sjmachin at lexicon.net Mon Jan 3 14:30:23 2005 From: sjmachin at lexicon.net (John Machin) Date: 3 Jan 2005 11:30:23 -0800 Subject: Py2exe and extension issues References: <1104763249.008031.100100@f14g2000cwb.googlegroups.com> Message-ID: <1104780623.038891.25810@z14g2000cwz.googlegroups.com> kdahlhaus at yahoo.com wrote: > Is anyone aware of issues with Py2exe and extensions compiled with > cygwin/mingw for Python 2.3? I have an extension that wraps access to > some C DLLs. The generated executable always segfaults at startup, > although things work fine when running through the normal python > interpreter. I had a guess that perhaps the issue stems from my > extension being compiled with cygwin and py2exe compiled with Visual > C++? Some questions: 1. Did it work before (e.g. with Python 2.2, or an earlier version of py2exe), or has it never worked? 2. Where at start-up does it "segfault"? Doesn't the "Dr Watson" log file tell you anything? You may need to sprinkle prints and printfs around your code. 3. Those C DLLs: supplied by whom -- you or an nth party? compiled with which compiler? 4. Which version(s) of which Windows are you using? Some hints: 1. Ask on the py2exe mailing list. 2. Your guess may be correct. The usual cause of such a problem is getting a run-time-library resource on one side of the chasm and trying to use it on the other side. When the resource is a pointer to a data structure whose contents are not defined by some standard, anything can go wrong, and usually does. Examples: (a) malloc() on one side and free() on the other (b) fopen() on one side and fanything() on the other. However I would expect these problems to show up under normal interpreter use. 3. Using py2exe instead of python may merely be exposing a bug in your code caused by e.g. an uninitialised variable. (-: When you say "things work fine" in normal interpreter mode, where does this lie in the continuum between "it ran regression tests and volume tests happily all night" and "I fired it up and it didn't fall over"? :-) HTH, John From removethis.kartic.krishnamurthy at gmail.com Mon Jan 31 20:38:19 2005 From: removethis.kartic.krishnamurthy at gmail.com (Kartic) Date: Tue, 01 Feb 2005 01:38:19 GMT Subject: "Mail receiver server" In-Reply-To: <41feb541$0$27942$636a15ce@news.free.fr> References: <41feaff2$0$2068$626a14ce@news.free.fr> <41feb541$0$27942$636a15ce@news.free.fr> Message-ID: manatlan said the following on 1/31/2005 5:46 PM: > > I like the idea, but how to connect the virtual smtp and a python script ? > > but ... There should be a way to be python only ... because i don't want > to be very complex, i just want to get the subject of the email, to run > some commands (and perhaps get a attachment file) ... but that's all > i am pretty sure that a recipe exists ... that a man has already done > that ! > But i don't know what to query on google ... Hi, What you are trying to do is what is called a mail filter. So google for python mail filter and see what you get. With this setup, lets say Computer B sends an email to user controluser on Computer A , the email is actually passed off to a script (in your case python script) to process the incoming email, instead of actually delivering the email to the user's inbox on "A". I don't have the faintest the idea how you would do this on IIS's virtual SMTP server; there is probably a setup user panel. In any case, on UNIXish systems, there are a few ways of doing it of which one way is to setup a user in a file called /etc/aliases and put an entry like this: controluser: | /usr/local/bin/mailprocessor.py which tells the SMTP server to pass off the email to script after the | (pipe) when controluser gets an email. So, see if the SMTP control panel provides you with some such feature. If IIS does not, my suggestion to you will be to install Cygwin from cygwin.com and use the Exim Mail transfer agent available with Cygwin (You will have to choose that when installing Cygwin, it is not automatically installed) or please google for Windows SMTP Server and see if something piques your interest. Now, coming to the Python related part. Your SMTP server will invoke your script by sending the incoming email data on your script's sysin. So, from python you will do... #!/usr/local/bin/python import sys, email, os em = email.message_from_file(sys.stdin) # Read message from Std Input subject = em.get('Subject') # Get the subject from em object if subject.startswith('reboot'): os.system('shutdown -r') # reboot the Server For more information, please read the email module in the Python Module Docs. Hope that will help you get started! Thanks, --Kartic From jlrodilla at gmail.com Sun Jan 30 14:19:30 2005 From: jlrodilla at gmail.com (jlrodilla at gmail.com) Date: 30 Jan 2005 11:19:30 -0800 Subject: search engine Message-ID: <1107112770.301449.49070@c13g2000cwb.googlegroups.com> hi all, i?m doing a search engine using python for the spider and php to make a web for the search. The Database i have choosen is postgreSQL. Do you think it is a good choosen? Any suggestion? if anybody in interested in colaborate please send an e-mail to jlrodilla at gmail.com In a few weeks i will upload all the code to one domain and so i can be able to send you information about this project. The idea is to build a search engine like "google", but my/our search engine only look for tech pages, i also wants that users can select if they want to search a web, faqs/howto, manuals/tutorials... Thanks. From fuzzyman at gmail.com Thu Jan 27 07:38:39 2005 From: fuzzyman at gmail.com (Fuzzyman) Date: 27 Jan 2005 04:38:39 -0800 Subject: Please suggest on the book to follow In-Reply-To: <1106828422.318953.166680@f14g2000cwb.googlegroups.com> References: <1106828422.318953.166680@f14g2000cwb.googlegroups.com> Message-ID: <1106829519.540737.164210@z14g2000cwz.googlegroups.com> We've only just had Python 2.4. Based on previous experience that means it will be about 18 months before python 2.5..... I learned to program from 'Programming Python'. Particularly the stuff on Tkinter is very helpful. I don't think you'll have much to 'unlearn', although obviously there is stuff it doesn't cover (like new style classes). Regards, Fuzzyman http://www.voidspace.org.uk/python/index.shtml From __peter__ at web.de Mon Jan 17 16:04:41 2005 From: __peter__ at web.de (Peter Otten) Date: Mon, 17 Jan 2005 22:04:41 +0100 Subject: Assigning to self References: <200501172055.33962.frans.englich@telia.com> Message-ID: Frans Englich wrote: >> > >>> class Foo(object): >> > >> > ... cache = {} >> > ... def __new__(cls, id): >> > ... try: >> > ... return cls.cache[id] >> > ... except KeyError: >> > ... pass >> > ... cls.cache[id] = result = object.__new__(cls, id) >> > ... return result >> > ... def __init__(self, id): >> > ... self.id = id >> > ... def __repr__(self): >> > ... return "Foo(id=%r)" % self.id >> > ... >> >> I'm not sure, but I think this code misses one thing: that __init__ is >> called each time __new__ returns it, as per the docs Peter posted. > > Ahem, John I ment :) You are right -- just put the initialization into the __new__() method, then. Peter From rkern at ucsd.edu Thu Jan 6 00:37:10 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 05 Jan 2005 21:37:10 -0800 Subject: Python evolution: Unease In-Reply-To: <41dcc35a$0$3872$afc38c87@news.optusnet.com.au> References: <1gpxk87.zeszum1hfa220N%aleaxit@yahoo.com> <41dcc35a$0$3872$afc38c87@news.optusnet.com.au> Message-ID: Mike Thompson wrote: > Alex Martelli wrote: > >> Carlos Ribeiro wrote: >> ... >> >>>> - IDE: Better than what? Than IDLE? Than Eclipse? Than SPE? Than >>>> Pythonwin? >>> >>> >>> I would like to seee Eric3, with some polish & opensourced on Win >>> (which means solving the Qt licensing problem). Perhaps someone could >>> convince Trolltech to release a special Qt Win version just for it >>> (Eric3). Eclipse is also an interesting approach. >> >> >> >> I love eric3, but if you're an eclipse fan, look at enthought's >> "envisage" IDE -- it seems to me that it has superb promise. >> > > I've tried both the SciPy and Enthought WWW sites and I can't find much > on "Envisage". At SciPy.org there is one set of powerpoint slides on it > but nothing more. > > Is it available for download somewhere? Alex is, I think, jumping the gun a bit. Envisage isn't quite ready for prime time as your day to day IDE. It might be useful to you right now as a platform to build a dynamic GUI application (Envisage's intended use) if you are willing to get your hands dirty and help us build Envisage. Hence, it is not being advertised widely. But Alex is right; Envisage does hold a lot of promise. -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From ola.natvig at infosense.no Tue Jan 18 09:16:04 2005 From: ola.natvig at infosense.no (Ola Natvig) Date: Tue, 18 Jan 2005 15:16:04 +0100 Subject: generator expressions: performance anomaly? In-Reply-To: <354jhnF4gk8l6U1@individual.net> References: <377Hd.77904$Jk5.30235@lakeread01> <354gj7F4etgn8U1@individual.net> <354h9gF4fgsqgU1@individual.net> <354jhnF4gk8l6U1@individual.net> Message-ID: > > What makes the leftmost expression different from the iterable returning > expression inside the for? The same arguments apply there. > It's not different, but it's a requirement that the iterable returns the same data every time. I know that anyone can type range = fancyRange and make this return a random number of random items. But if that happens the expression cannot be transformed into a static list / tuple. Thats obvious. From ncoghlan at iinet.net.au Wed Jan 19 05:34:56 2005 From: ncoghlan at iinet.net.au (Nick Coghlan) Date: Wed, 19 Jan 2005 20:34:56 +1000 Subject: Dictionary keys (again) (was Re: lambda) In-Reply-To: References: <1105633239.316956.262140@f14g2000cwb.googlegroups.com> <41EBA021.5060903@holdenweb.com> Message-ID: <41EE37D0.70108@iinet.net.au> Antoon Pardon wrote: > A rule of thumb is context sensitive. If circumstances change, > so do the rules of thumb. Principles have a broader field > of application. > > IMO there is nothing principally wrong with using a mutable object > as a dictionary key. But avoiding doing so is a good rule of > thumb if you have a python-like implementation of a dictionary. For a 'mutable key' to make sense, the following: lst = [] dct = {l: "Hi!"} print dct[[]] print dct[lst] lst.append(1) print dct[[1]] print dct[lst] Should print: Hi Hi Hi Hi That's completely impractical though - for any sane implementation, at least one of the above print statements will throw a KeyError. Your example of a 'safe_dict' that copies mutable keys means that the final print statement is the one that fails. My suggestion of an "identity_dict" means that both of the same-value based lookups would fail. Notice that both of these approaches take a mutable key and make it immutable (either by holding the sole reference to a copy, or retrieving an immutable property of the mutable object). There's also your solution of "I promise not to mutate the key while it is in the dictionary". Workable, but opens the door to some entertaining bug hunts when the promise is broken. Which solution is the best default behaviour? Well, the Zen of Python states "In the face of ambiguity, refuse the temptation to guess". So that's the policy the builtin dict follows - it doesn't try to guess when to make a copy, or whether or not to use identity based semantics in the face of mutability. Instead, it raises an exception at key entry time, asking the programmer to clarify their intent. The principle is *certainly* that hash tables should contain immutable keys. Your own 'safe_dict' example implicitly concedes this point by making copies 'when required'. 'When required' for what? When required to preserve immutability, perhaps? In short, sane hash tables require immutable keys, and how mutable keys acquire the requisite immutability is going to be application dependent. Provision of a safe_dict or identity_dict would merely allow a programmer to state their intent at the time the container is created, rather than having to state it whenever keys are generated or referenced. Cheers, Nick. -- Nick Coghlan | ncoghlan at email.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.skystorm.net From steve at holdenweb.com Mon Jan 31 13:55:34 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 31 Jan 2005 13:55:34 -0500 Subject: Relocatable binary installs.... In-Reply-To: References: <1107195180.462949.222980@z14g2000cwz.googlegroups.com> Message-ID: <41FE7F26.1090209@holdenweb.com> Fredrik Lundh wrote: > friedmud at gmail.com wrote: > > >>Is there a way to make a relocateable python binary... that is... a >>python installation that won't care where it is on the machine... and >>won't care if it gets put somewhere else besides / ? > > > the standard CPython interpreter is 100% "relocatable". If you think > it isn't, you have to be a bit more specific. > Is it possible that you are using "relocatable" in the standard sense of "code can be located anywhere in physical memory", where the OP is using the same term to mean "can live anywhere in the filestore"? I suspect the problem the OP is seeing is because the --prefix configuration parameter will cause an interpreter to look in a specific place for standard libraries. Clearly if you "relocate" the libraries to another directory entirely then an interpreter without any further nouse (and no symbolic links to help it) is going to crap out badly. But I could be wrong. always-prepared-to-at-least-admit-the-possibility-ly y'rs - steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 From http Sat Jan 22 07:32:30 2005 From: http (Paul Rubin) Date: 22 Jan 2005 04:32:30 -0800 Subject: Zen of Python References: <972ec5bd050119111359e358f5@mail.gmail.com> <1106177050.630141.33090@c13g2000cwb.googlegroups.com> <972ec5bd0501191641166972b0@mail.gmail.com> <7xis5szpdj.fsf@ruckus.brouhaha.com> <7xekggbrns.fsf@ruckus.brouhaha.com> <7x651rwbib.fsf@ruckus.brouhaha.com> <7xfz0uqe1d.fsf@ruckus.brouhaha.com> Message-ID: <7xu0p9lk4h.fsf@ruckus.brouhaha.com> Dave Benjamin writes: > Can we get a show of hands for all of those who have written or are > currently maintaining code that uses the leaky listcomp "feature"? It's really irrelevant whether anyone is using a feature or not. If the feature is documented as being available, it means that removing it is an incompatible change that can break existing code which currently conforms to the spec. If the "feature" is described as the bug that it is, anything that relies on it is nonconformant. I do remember seeing some cute tricks (i.e. capable of becoming idioms) that depend on the leakage. From xah at xahlee.org Mon Jan 17 12:45:01 2005 From: xah at xahlee.org (Xah Lee) Date: 17 Jan 2005 09:45:01 -0800 Subject: [perl-python] 20050117, filter, map In-Reply-To: <1105930139.513977.91740@c13g2000cwb.googlegroups.com> References: <1105930139.513977.91740@c13g2000cwb.googlegroups.com> Message-ID: <1105983901.353590.83310@c13g2000cwb.googlegroups.com> erratum: the Mathematica Apply should've been Select. ... Xah xah at xahlee.org http://xahlee.org/PageTwo_dir/more.html From godoy at ieee.org Wed Jan 19 12:17:55 2005 From: godoy at ieee.org (Jorge Luiz Godoy Filho) Date: Wed, 19 Jan 2005 15:17:55 -0200 Subject: Accessing MDB files on Windows References: <1635068.ZTfiooUzB4@strongwill.g2ctech> <4262806.PViGKJWPeZ@strongwill.g2ctech> <57wHd.80954$Jk5.41342@lakeread01> Message-ID: <1116749.2eGh3JeIRy@strongwill.g2ctech> Steve Holden, Quarta 19 Janeiro 2005 14:38, wrote: > Note that DAO is a very old library, and nowadays ADO would probably be > the preferred method in the Windows environment (can DAO even *use* > oledb providers?). ADO libraries are available - see > > http://www.markcarter.me.uk/computing/python/ado.html > > for example, or Google for "python ado". Bottom line, there are many > ways to skin this particular cat. Hmmm... I see. I'm trying to avoid having to install external modules at my client's server. Should I use, given that both DAO and ODBC are available with the win32all extensions, DAO or ODBC? Or would ADO give me so much more performance that I should really use it? -- Godoy. From mauriceling at acm.org Sun Jan 2 16:34:58 2005 From: mauriceling at acm.org (Maurice LING) Date: Sun, 02 Jan 2005 21:34:58 GMT Subject: How to make executable file ? In-Reply-To: <33r5gcF449bt0U1@individual.net> References: <33r5gcF449bt0U1@individual.net> Message-ID: <41d868ff@news.unimelb.edu.au> Hi all, This may be OT but is there a way to do the same for *nix type of system? Like cast a python interpreter with scripts together? I'm running Mac OSX here. The only remote idea I have is to use jythonc to convert everything into .class files and package that as a .jar file but I can't do that with C bindings. Any suggestions? Thanks, Maurice From xah at xahlee.org Sat Jan 15 21:31:18 2005 From: xah at xahlee.org (Xah Lee) Date: 15 Jan 2005 18:31:18 -0800 Subject: python mode indentation problem In-Reply-To: <1105802644.939051.229990@f14g2000cwb.googlegroups.com> References: <1105802644.939051.229990@f14g2000cwb.googlegroups.com> Message-ID: <1105842678.044409.270450@z14g2000cwz.googlegroups.com> ? ok, here's the ordeal. ? ? for i in range(5): ? print i ? for i in range(2): ? print i, 'tt' ? for i in [3]: ? print i ? for i in [32]: ? print i ? ? # 1 level, 4 space ? # 2 level, 1 tab ? # 3 level, 1 tab, 4 spaces ? # 4 level, 2 tabs. ? ? who the fuck coded the python mode in emacs? fuckhead please peruse: ? http://xahlee.org/UnixResource_dir/writ/responsible_license.html ? ? PS Thanks for the tip on (setq-default indent-tabs-mode nil). ? ? Xah ? xah at xahlee.org ? http://xahlee.org/PageTwo_dir/more.html From fredrik at pythonware.com Sat Jan 22 19:21:59 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 23 Jan 2005 01:21:59 +0100 Subject: rotor replacement References: <7x1xcidnp1.fsf@ruckus.brouhaha.com><41EE24F7.7030303@jessikat.fsnet.co.uk><7x1xchlpqv.fsf@ruckus.brouhaha.com><41efeb82$0$27807$9b622d9e@news.freenet.de><41f1a70b$0$25959$9b622d9e@news.freenet.de><7xbrbiqdhk.fsf@ruckus.brouhaha.com><7xllalljah.fsf@ruckus.brouhaha.com><7xekgdmpll.fsf@ruckus.brouhaha.com><7xpszxcnfa.fsf@ruckus.brouhaha.com> <7xllalcmqc.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: >> you really don't have a fucking clue about anything, do you? > > You're not making any bloody sense. oh, I make perfect sense, and I think most people here understand why I found your little "lecture" so funny. if you still don't get it, maybe some- one can explain it to you. From orwin42 at mail.be Sun Jan 9 08:54:23 2005 From: orwin42 at mail.be (Nyx42) Date: Sun, 09 Jan 2005 08:54:23 -0500 Subject: Pygame and pyopengl with py2exe ? Message-ID: Hi, I have 2 programs which run without problems, but after building them with py2exe, they don't work (program opens the window and closed it immediately) First program (uses only pygame): screen = pygame.display.set_mode((W_WIDTH_F, W_HEIGHT)) This line refuses to be compiled correctly. Why ? Second program (pygame + pyopenGL): Py2exe can't import OpenGL.GL and OpenGL.GLU :( From apardon at forel.vub.ac.be Mon Jan 17 10:20:01 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 17 Jan 2005 15:20:01 GMT Subject: lambda References: <1105633239.316956.262140@f14g2000cwb.googlegroups.com> <41EBA021.5060903@holdenweb.com> Message-ID: Op 2005-01-17, John Lenton schreef : > > > --vni90+aGYgRvsTuO > Content-Type: text/plain; charset=us-ascii > Content-Disposition: inline > Content-Transfer-Encoding: quoted-printable > > On Mon, Jan 17, 2005 at 11:41:20AM +0000, Antoon Pardon wrote: >> Op 2005-01-17, Steve Holden schreef : >> > Antoon Pardon wrote: >> > [...] >> >>>"A foolish consistency is the hobgoblin of little minds". Rules are ma= > de=20 >> >>>to be broken. >> >>=20 >> >>=20 >> >> Like only use immutables as dictionary keys. >> >>=20 >> > Fair enough, but don;t go advising newbies to do this. >>=20 >> How about something like this. >>=20 >> Because of the extra precautions one has to take when >> using mutables as hash keys, we advise newbies >> to stick with immutable keys until they have gathered >> enough knowledge and experience to adequatly weight >> the pro and cons of a mutable key solution against >> an immutable key solution. > > knowledgeable and experienced users know when to ignore the rules. Then why seems there to be so few acknowledgement that these rules may indeed be broken by users. My experience is that anyone who suggests so runs the risk of being branded a (python) heretic. -- Antoon Pardon From hans at zephyrfalcon.org Fri Jan 28 11:09:16 2005 From: hans at zephyrfalcon.org (Hans Nowak) Date: Fri, 28 Jan 2005 11:09:16 -0500 Subject: Dynamic class methods misunderstanding In-Reply-To: References: Message-ID: Bill Mill wrote: > Hello all, > > I have a misunderstanding about dynamic class methods. I don't expect > this behavior: > > In [2]: class test: > ...: def __init__(self, method): > ...: self.method = method > ...: self.method() > ...: > > In [3]: def m(self): print self > ...: [...] > > TypeError: m() takes exactly 1 argument (0 given) > ----------------------------------------------------------------------------- > > Why doesn't m get the implicit self parameter in the self.method() > call? How would I make it a proper member of the class, so that a > self.method() call would work with the above "m" function? m is a function. When you assign it to self.method, it's still a function. You don't create a new method that way; all you have is a new attribute called 'method' containing the function. To add m as a new method to the *class*, do this: >>> class test: ... def __init__(self, method): ... self.__class__.method = method ... self.method() ... >>> def m(self): print self ... >>> test(m) <__main__.test instance at 0x0192ED78> <__main__.test instance at 0x0192ED78> >>> To add m as a new method to the *instance*, use new.instancemethod, as Diez B. Roggisch already pointed out. HTH, -- Hans Nowak http://zephyrfalcon.org/ From theller at python.net Tue Jan 4 13:57:11 2005 From: theller at python.net (Thomas Heller) Date: Tue, 04 Jan 2005 19:57:11 +0100 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 30) References: <1gpoaq3.1trkc8e1bxl9h4N%aleaxit@yahoo.com> <1104846212.355098.186400@c13g2000cwb.googlegroups.com> <1104849206.111461.70500@c13g2000cwb.googlegroups.com> <41dae3c3$0$228$edfadb0f@dread12.news.tele.dk> Message-ID: Max M writes: > Thomas Heller wrote: > >> It seems also the error messages aren't too helpful: >> >>>>>"?".encode("latin-1") >> Traceback (most recent call last): >> File "", line 1, in ? >> UnicodeDecodeError: 'ascii' codec can't decode byte 0x84 in position 0: ordinal not in range(128) >> Hm, why does the 'encode' call complain about decoding? > > Because it tries to print it out to your console and fail. While > writing to the console it tries to convert to ascii. Wrong, same error without trying to print something: >>> x = "?".encode("latin-1") Traceback (most recent call last): File "", line 1, in ? UnicodeDecodeError: 'ascii' codec can't decode byte 0x84 in position 0: ordinal not in range(128) >>> > > Beside, you should write: > > u"?".encode("latin-1") to get a latin-1 encoded string. I know, but the question was: why does a unicode string has a encode method, and why does it complain about decoding (which has already been answered in the meantime). Thomas From jerf at jerf.org Tue Jan 4 21:12:40 2005 From: jerf at jerf.org (Jeremy Bowers) Date: Tue, 04 Jan 2005 21:12:40 -0500 Subject: Python evolution: Unease References: <7xacrpdxy3.fsf@ruckus.brouhaha.com> <7x652che6z.fsf@ruckus.brouhaha.com> Message-ID: On Tue, 04 Jan 2005 17:12:04 -0800, Paul Rubin wrote: > Irrelevant, the issue isn't what docs can be written if someone wants to > do it, it's what docs are actually already there.... > I just see various other free software projects as > trying to live up to higher standards and I think Python should aspire to > the same thing. So, nobody should have to write the docs because they should already be there, but "somebody" should have to write the docs? You need to think more clearly about the pronouns you are slinging around. Who is this "they" that should write the docs? (Yes, I know you didn't use that exact word but the concept is clearly there.) And what right do you have to demand this action from "they"? Are you willing to pay me to do it? From jurgenex at hotmail.com Sun Jan 30 03:09:54 2005 From: jurgenex at hotmail.com (Jürgen Exner) Date: Sun, 30 Jan 2005 08:09:54 GMT Subject: [perl-python] sending email References: <1107041765.890014.112530@c13g2000cwb.googlegroups.com> Message-ID: Xah Lee wrote: [...] > Here's how the situation stands as of 2001 March: ^^^^^^^^^^ Well, at least now we know why Mr. Lee is a little bit behind .... jue From oglycans at yahoo.com Thu Jan 13 17:49:41 2005 From: oglycans at yahoo.com (oglycans at yahoo.com) Date: 13 Jan 2005 14:49:41 -0800 Subject: how to control the mouse pointer with python? References: <1105650438.311153.167410@f14g2000cwb.googlegroups.com> <34o9npF4et4hiU1@individual.net> <1105654593.637145.321290@z14g2000cwz.googlegroups.com> <41e6f6db$0$5416$a1866201@visi.com> Message-ID: <1105656581.837894.142790@z14g2000cwz.googlegroups.com> >What environment? It's X. From jtr at ofb.net Sun Jan 2 22:38:04 2005 From: jtr at ofb.net (John Reese) Date: Mon, 3 Jan 2005 03:38:04 +0000 (UTC) Subject: using HTTP Digest auth with arbitrary HTTP methods? References: Message-ID: In comp.lang.python, [I] wrote: > Hello there. I've run into some missing functionality with HTTP Digest > authentication in the 2.3 library and I was wondering if I'm just > missing something. > > Missing functionality the first: urllib2 > > 1a. You can add "handlers" to your opener indicating that you want to > use HTTP Digest auth. This is nice way to handle it, but I don't > see any way to use a custom verb in your URLOpener -- it always > uses either GET or POST depending on whether you provided data. > Is there any way to specify an arbitrary method? This would allow > urllib2 to be used to write WebDAV clients. > > 1b. HTTPDigestAuthHandler is initialized with an HTTPPasswordMgr > object, which unfortunately deals in cleartext passwords. Digest > authentication can be computed using only a hash of username, > password, and realm; it would be nice if there was an alternate > version of HTTPPasswordMgr that let you deal in hashes instead of > or in addition to plaintext passwords. Well, I figured out a workaround, but it requires changing urllib2.py since the bugs are in base classes. I instead copied it (to urllib3.py) and made the following changes: a. in AbstractDigestAuthHandler.get_authorization, call req.get_method() instead of req.has_data() and 'POST' or 'GET' (python has a ternary operator, who knew) b. in AbstractHTTPHandler.do_open, call req.get_method instead of the hard-coded if-logic which is the same as that in req.get_method Both of these seem like bugs in urllib2. Then I overrode urllib2.Request and made it possibly to set the method, and then passed an instance of my custom Request class (the one that shouldn't have to exist, since Request should allow method to be set explicitly) to OpenerDirector.open(). I'd like to see these changes make it into the standard library -- after being vetted by whoever's in charge of urllib2. Anybody know who I should talk to? From gsakkis at rutgers.edu Tue Jan 25 19:25:55 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Tue, 25 Jan 2005 19:25:55 -0500 Subject: Tuple slices References: <35kn4mF4o44ufU1@individual.net> <35lckuF4kbtbfU1@individual.net> <10vb3enf8qvld4@corp.supernews.com> <35lm6dF4hr4t2U1@individual.net> <1106669254.838248.317170@z14g2000cwz.googlegroups.com> <10vdj4s9ib19fe3@corp.supernews.com> Message-ID: <35o6cdF4qe45fU1@individual.net> "Jeff Shannon" wrote in message news:10vdj4s9ib19fe3 at corp.supernews.com... > George Sakkis wrote: > > > An iterator is perfectly ok if all you want is to iterate over the > > elements of a view, but as you noted, iterators are less flexible than > > the underlying sequence. The view should be (or at least appear) > > identical in functionality (i.e. public methods) with its underlying > > sequence. > > So, what problem is it, exactly, that you think you'd solve by making > tuple slices a view rather than a copy? > > As I see it, you get the *possibility* of saving a few bytes (which It all comes down on what you mean by "a few bytes". Since many (most?) slices are linear wrt to the original sequence's length, it is not hard to think of algorithms that involve the creation of *many* slices (e.g. most recursive divide-and-conquer algorithms). Implementing these using slices simply does not scale as the input sequence gets larger. Of course, you can always use the standard C/C++ approach and pass the original sequence along with the (start,stop,step) indices of the slice, as Terry Reedy mentioned, but then you lose in expressiveness. > may go in the other direction) at a cost of complexity and speed. You > have greater dependence of internal objects on each other, you can't > get rid of the original tuple while any slice views of it exist, you > gain nothing in the way of syntax/usage simplicity... so what's the > point? > > To my mind, one of the best things about Python is that (for the most > part) I don't have to worry about actual memory layout of objects. I > don't *care* how tuples are implemented, they just work. It seems to > me that you're saying that they work perfectly fine as-is, but that > you have a problem with the implementation that the language tries its > best to let you not care about. Is this purely abstract philosophy? No, it's called "scalability", and it's not purely abstract philosophy AFAIK. I fully agree that for the most part you don't have to care about it, and I'm grateful that python does all its magic trasparently. However if you do care about it, and at the same time you are unwilling to sacrifice the elegance of slices, the current implementation is not ideal. > Jeff Shannon > Technician/Programmer > Credit International George From ncoghlan at iinet.net.au Sun Jan 2 02:22:14 2005 From: ncoghlan at iinet.net.au (Nick Coghlan) Date: Sun, 02 Jan 2005 17:22:14 +1000 Subject: PEP 288 ponderings In-Reply-To: <41D794BA.8090408@colorstudy.com> References: <41D794BA.8090408@colorstudy.com> Message-ID: <41D7A126.4060808@iinet.net.au> Ian Bicking wrote: > Using a one-element list is kind of annoying, because it isn't clear out > of context that it's just a way of creating shared state. But it's > okay, work right now, and provides the exact same functionality. Uh, isn't shared state what classes were invented for? Py> class mygen(object): ... def __init__(self, data): ... self.data = data ... def __iter__(self): ... while 1: ... print self.data ... yield None ... Py> g = mygen(0) Py> giter = iter(g) Py> giter.next() 0 Py> g.data = 1 Py> giter.next() 1 Cheers, Nick. -- Nick Coghlan | ncoghlan at email.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.skystorm.net From peter at engcorp.com Sun Jan 9 09:50:51 2005 From: peter at engcorp.com (Peter Hansen) Date: Sun, 09 Jan 2005 09:50:51 -0500 Subject: time module precision In-Reply-To: <1105268967.629064.154850@c13g2000cwb.googlegroups.com> References: <1105268967.629064.154850@c13g2000cwb.googlegroups.com> Message-ID: janeaustine50 at hotmail.com wrote: > So the problem (waiting tens to hundreds of us without busy looping) > still remains... That's actually not a "problem", it's your solution to a problem. Can you describe the _real_ problem, what you are trying to do? _Why_ do you want to wait such brief amounts of time? I ask as someone with fairly extensive background in realtime software (which is basically what it sounds like you are trying to write here), and I suspect that you are either trying to achieve something that's not really possible on Windows XP, or that you are simply doing something that is entirely unnecessary, probably for good reasons but with too little experience of the issues involved. Can you expand on your situation? -Peter From jelle.feringa at ezct.net Tue Jan 11 11:31:07 2005 From: jelle.feringa at ezct.net (Jelle Feringa // EZCT / Paris) Date: Tue, 11 Jan 2005 17:31:07 +0100 Subject: os.spawnv & stdin trouble Message-ID: <20050111163036.808E91C00CE9@mwinf0108.wanadoo.fr> ##I know I should be using 2.4 and os.Popen, I know, I know. ##However, since most modules I need, I'm using 2.3 for this script I'm having troubles executing a shell script. The thing is that I'm produing material and geometry files that need to be compiled to a binary description (for those familiar to Radiance, oconv) The trouble I'm having is that when python goes through my loop, files are overwritten before os.system was able to process these! (who ways complaining python is slow, well I'm not!! ;-) So the obvious thing to do is to swap os.system for os.spawnv. Here's where I run into trouble. In my os.system version, I'm perfectly able to pipe into another file, since the process has no real connection to python whatsoever. Would someone be able to explain me how to do this, all the tools I'm using for this script are unix-like tools and heavily rely on piping. program = 'xform.exe' path = 'c:\Radiance\bin\' args = ['-t 0 8 0', 'wall0.rad', '>', 'wall0.TRANS.rad'] os.spawnv(os.P_WAIT, path, ('xform', args)) here's the cmd error message: xform: cannot find file ">" ##for your info I'm on win/xp, python 2.3.4 Cheers, Jelle. -------------- next part -------------- An HTML attachment was scrubbed... URL: From foo at bar.com Sun Jan 23 22:48:27 2005 From: foo at bar.com (Steve Menard) Date: Sun, 23 Jan 2005 22:48:27 -0500 Subject: JPype and classpath (Was Re: embedding jython in CPython... ) In-Reply-To: <1106517122.552509.318400@f14g2000cwb.googlegroups.com> References: <1106446384.384110.25150@z14g2000cwz.googlegroups.com> <1106517122.552509.318400@f14g2000cwb.googlegroups.com> Message-ID: johng2001 at rediffmail.com wrote: > Thanks for the response. However, I continue to have problems. Allow me > to give some more detail. > > For simplicity of testing, I hard coded the classpath and JVM path > (BTW getDefaultJVMPath() returns None on my system) > > import os, os.path > from jpype import * > > startJVM("C:/jdk1.5.0/jre/bin/client/jvm.dll", > "-Djava.class.path=D:/Temp/classes") > ... > shutdownJVM() > > > I have setup a classes folder in the script folder (D:/Temp) and have > placed test.class in it. > I run the script from the script folder (working directory is the same > as script's root path in this case) > > Now how do I load the class test? I am afraid I cannot make that out > from the docs. > > The simple test class is > public class test > { > public int i = 100; > } > > > What do I have to do before I can write > test().i > ? > > Thank you for your time. > About the getDefaultJVMPath(), could you send me your system information? On windows, JPype uses the contents of the registry to find the JVM. Of course, the usefulness of this mechanism is limited byt he sample of configurations i can test (I have only one machine). So any info you can provide me on yours can only help. About the classpath. JPype 0.4 currently cannot import classes that are in the "default" package. The fix is easy, simply put your "test" class in a package. For exmaple, if you put the class in the package "test", the code to load it would be : test = jpype.JPackage("test").test -- Steve Menard -------------------- Maintainer of http://jpype.sourceforge.net From robin at SPAMREMOVEjessikat.fsnet.co.uk Wed Jan 19 19:12:44 2005 From: robin at SPAMREMOVEjessikat.fsnet.co.uk (Robin Becker) Date: Thu, 20 Jan 2005 00:12:44 +0000 Subject: rotor replacement In-Reply-To: <41EEF691.20706@jessikat.fsnet.co.uk> References: <7x1xcidnp1.fsf@ruckus.brouhaha.com> <41EE24F7.7030303@jessikat.fsnet.co.uk> <41EEF691.20706@jessikat.fsnet.co.uk> Message-ID: <41EEF77C.6030400@jessikat.fsnet.co.uk> Robin Becker wrote: >> Presumably he is talking about crypo-export rules. In the past strong >> cryptography has been treated as munitions, and as such exporting it >> (especially from the USA) could have got you into very serious >> trouble. > So Python is an American Language and must obey American Law. Luckily I seem to have escaped that fate. -- Robin Becker From steven.bethard at gmail.com Mon Jan 24 13:00:48 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Mon, 24 Jan 2005 11:00:48 -0700 Subject: Tuple slices In-Reply-To: References: <35kn4mF4o44ufU1@individual.net> Message-ID: Fredrik Lundh wrote: > George Sakkis wrote: > >>Why does slicing a tuple returns a new tuple instead of a view of the existing one, given that >>tuples are immutable ? > > really? > > >>>>a = 1, 2, 3 >>>>b = a[:] >>>>a is b > True My impression was that full tuple copies didn't actually copy, but that slicing a subset of a tuple might. Not exactly sure how to test this, but: py> a = 1, 2, 3 py> a[:2] is a[:2] False So _something_ at least is different between the two slices... Steve From pedro.werneck at terra.com.br Mon Jan 24 13:21:41 2005 From: pedro.werneck at terra.com.br (Pedro Werneck) Date: Mon, 24 Jan 2005 16:21:41 -0200 Subject: Tuple slices In-Reply-To: References: <35kn4mF4o44ufU1@individual.net> Message-ID: <20050124162141.0903e6c6.pedro.werneck@terra.com.br> On Mon, 24 Jan 2005 18:45:46 +0100 "Fredrik Lundh" wrote: > George Sakkis wrote: > > > Why does slicing a tuple returns a new tuple instead of a view of > > the existing one, given that tuples are immutable ? > > really? Well... seems like this case (slicing the whole tuple) is optimized to return the original tuple just incrementing its reference count and returning tupleobject.c, 330-335 if (ilow == 0 && ihigh == a->ob_size && PyTuple_CheckExact(a)) { Py_INCREF(a); return (PyObject *)a; } > > >>> a = 1, 2, 3 > >>> b = a[:] > >>> a is b > True > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list From peter at engcorp.com Wed Jan 5 15:05:27 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 05 Jan 2005 15:05:27 -0500 Subject: Python 2.4 on Windows XP In-Reply-To: <1104946252.430332.226930@z14g2000cwz.googlegroups.com> References: <1104946252.430332.226930@z14g2000cwz.googlegroups.com> Message-ID: DavidHolt wrote: > I have a problem that I see on two different machines, one running XP > SP1 and one XP SP 2. Works fine here. (First time I've run it though... don't use it.) > On both I installed Python 2.4. > > I can't seem to start IDLE. When I try to start it, I get an hourglass > cursor for a short time then nothing more happens. This happens whether > I click the IDLE shortcut or click the pythonw.exe directly, or attempt > to launch pythonw from a command line. Try python.exe instead of pythonw.exe, also from the command line. That should give you *some* kind of additional detail. > I don't have any trouble running the python command line version. Do you mean "python.exe" here? Are you saying that you can run IDLE using python.exe, but not using pythonw.exe? Or something else? It's not clear. -Peter From FBatista at uniFON.com.ar Wed Jan 5 13:12:43 2005 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Wed, 5 Jan 2005 15:12:43 -0300 Subject: Python 2.4 on Windows XP Message-ID: [DavidHolt] #- I have a problem that I see on two different machines, one running XP #- SP1 and one XP SP 2. #- #- On both I installed Python 2.4. #- #- I can't seem to start IDLE. When I try to start it, I get an IDLE uses sockets to communicate its windows. Check if the integrated firewall in WinXP is not blocking you.... . Facundo Bit?cora De Vuelo: http://www.taniquetil.com.ar/plog PyAr - Python Argentina: http://pyar.decode.com.ar/ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ADVERTENCIA. La informaci?n contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener informaci?n confidencial o propietaria, cuya divulgaci?n es sancionada por la ley. Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no est? autorizado a divulgar, copiar, distribuir o retener informaci?n (o parte de ella) contenida en este mensaje. Por favor notif?quenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magn?tico) que pueda haber realizado del mismo. Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telef?nica Comunicaciones Personales S.A. o alguna empresa asociada. Los mensajes electr?nicos pueden ser alterados, motivo por el cual Telef?nica Comunicaciones Personales S.A. no aceptar? ninguna obligaci?n cualquiera sea el resultante de este mensaje. Muchas Gracias. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ncoghlan at iinet.net.au Sat Jan 8 00:13:10 2005 From: ncoghlan at iinet.net.au (Nick Coghlan) Date: Sat, 08 Jan 2005 15:13:10 +1000 Subject: Getting rid of "self." In-Reply-To: References: Message-ID: <41DF6BE6.1080807@iinet.net.au> Roy Smith wrote: > It's actually kind of neat, but boy does it play headgames with me when > I switch back and forth between that and Python. Switching back and forth betwen C++ and Python plays headgames *anyway* }:> Cheers, Nick. Hardware control with Python is nice. . . -- Nick Coghlan | ncoghlan at email.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.skystorm.net From kendall at monkeyfist.com Mon Jan 3 07:52:52 2005 From: kendall at monkeyfist.com (Kendall Clark) Date: Mon, 3 Jan 2005 07:52:52 -0500 Subject: Continuations Based Web Framework - Seaside. In-Reply-To: <41D8F86E.6030300@colorstudy.com> References: <41d7dad7$0$9355$afc38c87@news.optusnet.com.au> <7aTBd.11928$H%6.521997@twister1.libero.it> <20050102183402.GC8357@monkeyfist.com> <41D8F86E.6030300@colorstudy.com> Message-ID: <20050103125251.GA12713@monkeyfist.com> On Mon, Jan 03, 2005 at 01:46:54AM -0600, Ian Bicking wrote: > Kendall Clark wrote: > >Between this pressure (which isn't new, since as Steve points out, I > >was talking about this in Python community last year, and I wasn't > >nearly the first) and the growing popularity of Ruby on Rails, there's > >some small hint that Ruby is gaining on Python re: non-Java web app > >mind share. I think that's a v. important niche for Python and would > >like to see us remain strong there (though I've not *done* much about > >this, alas). > > I think that's probably true -- at least in terms of mindshare, even > though that might not reflect on actual work done. But, Rails is really > not a very experimental framework, and the existance of > continuation-based frameworks for Ruby is an aside. If such frameworks > happen at all for Python, I think they will be an aside as well. There's no sense whatever in which Rails is "experimental" -- who suggested such a thing? No, Rails hits a sweet spot, for a class (I suspect) of simple to mediumly-complex web app. Which is what most web apps *are*, after all. I don't begrudge Rails any popularity, I just want us to defend our turf. Sometimes that means ignoring what the other guy does, but sometimes it means aping him. I suspect in this case some aping would be a good thing. As for continuation-based frameworks, as you point out to Steve, that's largely an implementation technique and similar results may be achieved with other techniques (though I, unlike you, did *not* favor Steve's technique, as I recall). Continuations are certainly not experimental, nor are continuation-based modal web frameworks. The latter are *en vogue* and being seen to be *en vogue* is often an important technological virtue, especially for a perceived market niche leader. Kendall Clark -- Sometimes it's appropriate, even patriotic, to be ashamed of your country. -- James Howard Kunstler From janeaustine50 at hotmail.com Mon Jan 10 03:02:50 2005 From: janeaustine50 at hotmail.com (janeaustine50 at hotmail.com) Date: 10 Jan 2005 00:02:50 -0800 Subject: time module precision In-Reply-To: References: <1105268967.629064.154850@c13g2000cwb.googlegroups.com> Message-ID: <1105344170.575115.230820@c13g2000cwb.googlegroups.com> Peter Hansen wrote: > janeaustine50 at hotmail.com wrote: > > So the problem (waiting tens to hundreds of us without busy looping) > > still remains... > > That's actually not a "problem", it's your solution > to a problem. Can you describe the _real_ problem, what > you are trying to do? _Why_ do you want to wait such > brief amounts of time? > > I ask as someone with fairly extensive background in > realtime software (which is basically what it sounds like > you are trying to write here), and I suspect that you are > either trying to achieve something that's not really possible > on Windows XP, or that you are simply doing something that > is entirely unnecessary, probably for good reasons but > with too little experience of the issues involved. Can > you expand on your situation? > > -Peter What I am trying to do is sending binary data to a serial port. Since the device attached to the port cannot handle a continous in-flow of data, I need to make an artificial tiny delay in-between data chunks(a few hundreds of KBs). The delay might be a few tens to hundreds of us. I'd like to make the transmission as fast as possible, uh.. well.. reasonably fast. [I sort of posted this already but hasn't got it through so am reposting it now] Thanks From jello at comics.com Wed Jan 12 10:48:58 2005 From: jello at comics.com (rzed) Date: Wed, 12 Jan 2005 15:48:58 GMT Subject: ConfigParser - add a stop sentinel? Message-ID: I am working with PythonCard in one of my apps. For its purposes, it uses an .ini file that is passed to ConfigParser. For my app, I also need configuration information, but for various reasons, I'd rather use a syntax that ConfigParser can't handle. I know I can maintain two separate configuration files, and if I have to I will, but I'd rather avoid that, if possible, and a solution that suits my purposes is quite straightforward. I insert a sentinel in the ini file and modify my local ConfigParser's _read method to stop accepting input when it encounters that value. I handle my app's portion of the configuration myself. This all works fine, but I was wondering whether it might be worthwhile to add a standard stop flag in ConfigParser itself. Am I the only one with this sort of use case? If there were a standard way of doing this, I'd much rather use that, particularly if I ever have reason to distribute the app elsewhere. -- rzed From richardjones at optushome.com.au Fri Jan 28 19:34:30 2005 From: richardjones at optushome.com.au (richard) Date: Sat, 29 Jan 2005 11:34:30 +1100 Subject: move bugs from Zope BITS into Bugzilla? References: <1106956988.391329.320610@z14g2000cwz.googlegroups.com> Message-ID: <41fada16$0$25421$afc38c87@news.optusnet.com.au> lmhaskins at yahoo.com wrote: > I inherited a bug reporting system at work, and it's currently in Zope > BITS (Bug Information Tracking System). This version of BITS uses ZODB > -- not the RDBMS version. I would like to export all the incident > reports from BITS to later import into Bugzilla, but as of yet I > haven't quite figured it out. As soon as I'm done with this, that's it > for BITS and Zope, so I'd like to avoid writing a Zope app just for > this. > > Anyone solved this problem, or at least the part about exporting from > BITS? I'd hand-enter the open issues, but they also want the closed > ones for tracking & posterity. I'm not helping you with your problem, just plugging my own tracker ;) Use Roundup! It's Pure Python :) http://roundup.sf.net/ Richard From invalidemail at aerojockey.com Sun Jan 9 20:13:10 2005 From: invalidemail at aerojockey.com (Carl Banks) Date: 9 Jan 2005 17:13:10 -0800 Subject: python3: 'where' keyword In-Reply-To: <7xr7ku26zs.fsf@ruckus.brouhaha.com> References: <3480qqF46jprlU1@individual.net> <1105228549.608275.148740@c13g2000cwb.googlegroups.com> <7xk6qnzd3d.fsf@ruckus.brouhaha.com> <1105230350.861683.265970@c13g2000cwb.googlegroups.com> <7x3bxbe97m.fsf@ruckus.brouhaha.com> <7xsm5b2m93.fsf@ruckus.brouhaha.com> <7xr7ku26zs.fsf@ruckus.brouhaha.com> Message-ID: <1105319590.641211.191630@c13g2000cwb.googlegroups.com> Paul Rubin wrote: > Nick Coghlan writes: > > Trying to push it a level further (down to expressions) would, IMO, be > > a lot of effort for something which would hurt readability a lot. > > I think we should just try to do things in a simple and general way > and not try to enforce readability. For example, the > slightly-overcomplex code that I proposed might have been generated by > a macro, or even by a compiler from some other language. No human > would ever have to look at it, so it doesn't matter whether it's > easily readable. There's no reason to add needless constraints on the > language just to make writing ugly code difficult. The main goal > should be to make writing clear code easy, not to worry about whether > someone might also write ugly code. I couldn't disagree more. I belive in the Zen of Python. I believe the Zen of Python is the major factor responsible for Python's success. I believe that moving away from the Zen of Python will only diminish the language. And I think allowing a where statement inside in expression goes against the Zen in so many ways it isn't even funny. Beautiful is better than ugly. Simple is better than complex. (Note that simple means different things to different people: for me, and I believe, for the Zen of Python, it means simple for a human to understand.) Flat is better than nested. (Seems to be the official Zen if effect here.) Readability counts. (Yes, if something's unreadable enough, I hope it's not in the language, not merely that no one uses it.) Special cases aren't special enough to break the rules. (Heretofore, Python has never had a nested block inside an expression; doing that would make it a special case.) I don't want Python to be LISP. I don't think it's an admirable goal for Python to strive to be like LISP for the sake of being like LISP, or for the sake of being general or pure. If Python borrows something from LISP, it should be because that aspect of LISP supports the Zen of Python. If I wanted to use LISP, I'd be using LISP. But I like my statements and expressions distinct. I like things that belong in statements to stay in statements, and things that belong in expressions to stay in expressions. And a suite, be it a def statement, a where block, or whatever, belongs in a statement, not an expression. -- CARL BANKS From scott at hcsprogramming.com Mon Jan 17 10:56:51 2005 From: scott at hcsprogramming.com (Scott) Date: 17 Jan 2005 07:56:51 -0800 Subject: help with wxSlider & wxPython Message-ID: <1105977411.527188.198370@f14g2000cwb.googlegroups.com> I have the code below. I have changed the background of the frame to white, but I cannot get the wxSlider to not be the ugly gray color. Can someone tell me how to change it to a transparent background (I tried wxTRANSPARENT_WINDOW without success)? import os from wxPython.wx import * ID_ABOUT=101 ID_EXIT=110 class MainWindow(wxFrame): def __init__(self,parent,id,title): wxFrame.__init__(self,parent,wxID_ANY, title, size = ( 800,600),style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE) #self.control = wxTextCtrl(self, 1, style=wxTE_MULTILINE) wxStaticText(self, -1, "Distance to Move", (30, 40)) slider = wxSlider(self, 100, 25, 0, 3600, (30, 60), (400, -1),wxSL_HORIZONTAL | wxSL_TOP | wxSL_AUTOTICKS | wxSL_LABELS | wxTRANSPARENT_WINDOW) slider.SetTickFreq(1, 1) slider.SetValue(1800) self.CreateStatusBar() # A StatusBar in the bottom of the window # Setting up the menu. filemenu= wxMenu() filemenu.Append(ID_ABOUT, "&About"," Version 001") filemenu.AppendSeparator() filemenu.Append(ID_EXIT,"E&xit"," Terminate the program") # Creating the menubar. menuBar = wxMenuBar() menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame content. EVT_MENU(self, ID_ABOUT, self.OnAbout) # attach the menu-event ID_ABOUT to the EVT_MENU(self, ID_EXIT, self.OnExit) # attach the menu-event ID_EXIT to the self.SetBackgroundColour(wxWHITE) self.Show(true) self.Center(wxBOTH) def OnAbout(self,e): d= wxMessageDialog( self, "test","About test", wxOK) d.ShowModal() # Shows it d.Destroy() # finally destroy it when finished. def OnExit(self,e): self.Close(true) # Close the frame. app = wxPySimpleApp() frame = MainWindow(None, -1, "test") app.MainLoop() TIA, Scott From tchur at optushome.com.au Sat Jan 15 17:36:28 2005 From: tchur at optushome.com.au (Tim Churches) Date: Sun, 16 Jan 2005 09:36:28 +1100 Subject: hash patent by AltNet; Python is prior art? In-Reply-To: <41e96949$0$44082$5fc3050@dreader2.news.tiscali.nl> References: <41e96949$0$44082$5fc3050@dreader2.news.tiscali.nl> Message-ID: <41E99AEC.1020008@optushome.com.au> GerritM wrote: > ZDnet features an article about the had patent at AltNet > http://news.zdnet.com/2100-9588_22-5534087.html . Apparantly this issue > plays already for some time, now the p2p companies are threatened, becuase > they use hashing to recognize files. I find it incredibly annoying when journalists reporting on patent issues don't bother to quote the patent numbers (or patent application numbers) concerned (failure to do so probably means they haven't bothered to examine the patent or patent application themselves). In this case, a search is made doubly difficult because the patent was purchased from someone else, so a name serach can't be done. A quick keyworfd search on the USPTO web site revealed some related patents issued to Apple and Sony, but hard to identify this particular patent. > As far as I know hasing is a very old technique used to quickly look up > information. The use of hashing always requires an idnetity check, because > the lookup is not unique (mapping a very big amount of possibilities on a > limited amount of entries). This is a fast and robust way of finding > information, if the right hashing function is used. > > How can this type of fundamental knowledge be patented? I am afraid this is > again an example of a total failure of the current patent system. > Unfortunately these ridiculous examples endanger smaller companies, open > software activities amd innovation in general. What you have to remember is that the US (and some countries which have been stupid enough to follow its lead, like Japan, Australia and now it seems India) permits patents not just on software algorithms and techniques, but also on business methods. Thus the "novel" application of a well-known and widely-used technique such as hashing to a particular field of endeavour (like file sharing on the Internet) can be patented (in the US). To be novel, there must be no published prior art - but the prior art needs to be specific to the claims of the patent. So if the patent says "use of hashing to uniquely identify files in a peer-to-peer network via IP over the Internet", then the prior art needs to describe exactly that. The Australian government recently passed legislation which tightened this test of novelty (thank goodness) by allowing separate bits of prior art which describe aspects of a patent claim to be combined to some degree when opposing a patent - but the test for novelty remains remarkably lax in the US, I beleive. And I agree 100% with Alex Martelli - Europe and other countries must reject software, algorithmic and business method patents and thus create a powerhouse of innovation. let the US and fellow-travellers stew in their own juice - they will become powerhouses of litigation instead. Provided other countries don't recognise software and business method patents, the litigation will be confined within US borders, where resources can be productivelt spent making television dramas about attractive young patent attorneys and plodding, tram-riding patent clerks who are really brilliant physicists if only someone would recognise their potential. So yes, please write to your MP and MEP and protest against the prospect of software and business method patents in Europe. Hopefully one day within my lifetime we'll have a governemt here in Australia which will roll back the damage done to our patent system by trying to make just like the US system, just so we can conclude an unbelieveably inequitable free trade agreement with the US. But that's our problem. Tim C From mensanator at aol.com Mon Jan 10 12:52:03 2005 From: mensanator at aol.com (mensanator at aol.com) Date: 10 Jan 2005 09:52:03 -0800 Subject: Old Paranoia Game in Python In-Reply-To: References: <2005010903390916807%spk00@coxnet> <5JcEd.1988$KJ2.907@newsread3.news.atl.earthlink.net> <1105318366.966577.107460@c13g2000cwb.googlegroups.com> Message-ID: <1105379523.253933.278550@f14g2000cwb.googlegroups.com> Lucas Raab wrote: > mensanator at aol.com wrote: > > Aahz wrote: > > > >>Trust the computer, the computer is your friend. > > > > > > However, the computer isn't a fuckin' mind reader. > > > > If you're going to post source code on the usenet, don't > > have lines longer than 72 characters. Otherwise you'll > > find your code has wrapped lines. This not only causes > > syntax errors in your choose and print statements but > > also fucks up the formatting of of printed paragraphs. > > > > Stupid human. > > > > Temper, temper... But if I hadn't thrown a temper tantrum, I never would have learned about pyparsing (which I downloaded and installed). From chrisdewinN0SPAM at yahoo.com.au Tue Jan 18 17:42:44 2005 From: chrisdewinN0SPAM at yahoo.com.au (Dfenestr8) Date: Wed, 19 Jan 2005 08:42:44 +1000 Subject: python/cgi/html bug Message-ID: Hi. I've written a cgi messageboard script in python, for an irc chan I happen to frequent. Bear with me, it's hard for me to describe what the bug is. So I've divided this post into two sections: HOW MY SCRIPTS WORKS, and WHAT THE BUG IS. HOW MY SCRIPT WORKS Basically, it's divided into two executable scripts...... One is the thread viewer, ppthread.py, which views threads. When someone posts a new topic, for instance called "Generic new topic", it creates a file called "Generic new topic.thread". It stores the post, and any subsequent posts under in the thread in that file. Nice and simple I figured. The other executable script is the topic viewer, pptopic.py. All that does is display the topics, by doing a "tops = os.popen('ls -c *.thread')" The "ls -c" part reads the threads in the order in which they've been modified, so the first item in the list is always the thread most recently posted in. It then creates an html link to each of the threads ... on the page the html looks like.... foo
WHAT THE BUG IS .... The problem is when someone posts a new topic, and that topic happens to have "" double quotes, or any other strange character, some strange glitches occur. Best way to describe is to demonstrate it is go to the forum and try it yourself. Try entering a topic with straight, ordindary characters, not that you can re enter the thread any time you want and make new posts under it. Then try entering a thread with new or whacky characters and see how far you get. http://funkmunch.net/~pirch/cgi-bin/alphaforum/pptopic.py BTW, if you want to download the script, here it is in gzipped form http://funkmunch.net/~pirch/pepperpot.tgz From klachemin at comcast.net Fri Jan 28 11:08:12 2005 From: klachemin at comcast.net (Kamilche) Date: 28 Jan 2005 08:08:12 -0800 Subject: Dynamic class methods misunderstanding References: Message-ID: <1106928492.114459.191320@c13g2000cwb.googlegroups.com> I see what you're attempting to do. However, your code, if it DID run, would result in a method being added to the object, not the object's class! Modify the class itself, not the object, as follows: |class Test: | def __init__(self): | self.method() | |def m(self): | print self | |setattr(Test, 'method', m) |Test() From deetsNOSPAM at web.de Tue Jan 18 09:29:06 2005 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Tue, 18 Jan 2005 15:29:06 +0100 Subject: generator expressions: performance anomaly? References: <354esdF4fouh0U1@individual.net> Message-ID: <354kntF4g4crnU1@individual.net> > I don't see how generating byte code for a = 9; when seeing the > expression a = 3 + 6, would be a problem for non-functional > languages. Most probably. But I don't see much code of that type that it would be worth optimizing for, either. The cost for re-evaluation such an expression doesn't really account for any performance problems you hit - in python, of course. See this: deets at kumquat:/usr/lib/python2.3$ python timeit.py -c "[4*5 for i in xrange(10000)]" 100 loops, best of 3: 5.5e+03 usec per loop deets at kumquat:/usr/lib/python2.3$ python timeit.py -c "[20 for i in xrange(10000)]" 100 loops, best of 3: 4.3e+03 usec per loop Now of course the longer the expressions get, the more time it costs - but how many long arithmetical expression of constant evaluation value do you have? > > I agree that things like [time.time() for i in xrange(10)] shouldn't > be pregenerated and that the problem is more complicated as I thought. > > But during compilation the compilor could do an anlysis of the code > do determine whether there are side effects or not. If the compilor > then would store a code in the byte code for functions that are > guaranteed side-effect free and only pregenerated objects generated > by expressions with no side-effect, some common subexpression > elimination could be done even in a non-functional language. This analysis would only be possible for the most primitive of examples, the reason beeing that due to the dynamic features syntactically equivalent expressions can have totally different semantics. So its not really worth the effort. -- Regards, Diez B. Roggisch From jbperez808 at wahoo.com Wed Jan 12 20:26:29 2005 From: jbperez808 at wahoo.com (Jon Perez) Date: Thu, 13 Jan 2005 09:26:29 +0800 Subject: Another look at language comparisons In-Reply-To: References: <41dfb45d$0$19405$8fcfb975@news.wanadoo.fr> <34llf5F4apou6U2@individual.net> Message-ID: <34m12rF4cppjeU1@individual.net> Terry Reedy wrote: > It would hardly make more sense with the photos. The photos would be graphic evidence and would make it more entertaining to read through. > "Not the law is clear? There is a beard - there is a success. > There is no beard - you are guilty. " > > Terry J. Reedy And what about the moustache issue and Grace Hopper (COBOL is/was a very popular language but very much maligned and criticized like Perl and BASIC whose creators had moustaches instead of beards) ? Also, what about C#? AFAIK, Heljsberg has neither beard nor moustache, or is he sprouting one now (no pic to confirm...)? From eppstein at ics.uci.edu Wed Jan 19 13:19:55 2005 From: eppstein at ics.uci.edu (David Eppstein) Date: Wed, 19 Jan 2005 10:19:55 -0800 Subject: Dictionary keys (again) (was Re: lambda) References: <1105633239.316956.262140@f14g2000cwb.googlegroups.com> <41EBA021.5060903@holdenweb.com> Message-ID: In article , Nick Coghlan wrote: > For a 'mutable key' to make sense, the following: > > lst = [] > dct = {l: "Hi!"} > print dct[[]] > print dct[lst] > lst.append(1) > print dct[[1]] > print dct[lst] > > Should print: > Hi > Hi > Hi > Hi Yes, and what should the following do? lst1 = [1] lst2 = [2] dct = {lst1: "1", lst2: "2"} lst2[0]=1 lst1[0]=2 print dct[[1]] print dct[[2]] -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ From steve at holdenweb.com Mon Jan 31 13:03:54 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 31 Jan 2005 13:03:54 -0500 Subject: variable declaration In-Reply-To: <1gr9lyc.1rrm543162uefN%aleaxit@yahoo.com> References: <1gr98se.102e9b1qnsknwN%aleaxit@yahoo.com> <1107188359.375703.110590@f14g2000cwb.googlegroups.com> <1gr9lyc.1rrm543162uefN%aleaxit@yahoo.com> Message-ID: <41FE730A.4030201@holdenweb.com> Alex Martelli wrote: > Michael Tobis wrote: > [...] >>Let me add that I remain unconvinced that a language cannot combine the >>best features of Python with very high performance, which is ultimately > > > I'm also unconvinced. Fortunately, so is the EU, so they have approved > very substantial financing for the pypy project, which aims in good part > exactly at probing this issue. If any single individual can be called > the ideator of pypy, I think it's Armin Rigo, well-known for his > excellent psyco specializing-compiler for Python: the key research > thesis behind both projects is that a higher-level, dynamic language > need not have performance inferior to a lower-level one and indeed may > well beat it. > I should be failing in my duty as Chairman if I didn't remind readers at this point that they can hear Armin Rigo's talk "PyPy and Type Inference" at PyCon at 5:30 on Wednesday March 23. http://www.python.org/pycon/dc2005/register.html While Alex is not necessarily too modest to mention it he might forget that he is also giving three talks to PyCon. I believe this is the first year he has been able to attend PyCon, so delegates are definitely in for a treat this year. regards Steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 From ncoghlan at iinet.net.au Fri Jan 28 20:33:37 2005 From: ncoghlan at iinet.net.au (Nick Coghlan) Date: Sat, 29 Jan 2005 11:33:37 +1000 Subject: Who should security issues be reported to? In-Reply-To: References: <1106863164.745581.11920@f14g2000cwb.googlegroups.com> <1106911061.429966.303510@f14g2000cwb.googlegroups.com> <41FA22DA.2090402@iinet.net.au> Message-ID: <41FAE7F1.8060008@iinet.net.au> Fredrik Lundh wrote: > Nick Coghlan wrote: > > >>>I'm sorry, but this isn't really good enough. If Open Source wants to >>>say that they are better than these proprietary companies, they need >>>to deal with these sorts of things more professionally and establish >>>decent channels of communications for dealing with it. >> >>Is that the sound of a volunteer I hear? >> >>All you have to do is put your hand up, and the problem will be solved. If not you, who? > > > oh, please. this is a security issue. it needs a little more coordination > than an ordinary bug report. > > Well, a less facetious answer to the OP's question would be Anthony Baxter. As the current release manager, he's the best contact point I can think of. Cheers, Nick. -- Nick Coghlan | ncoghlan at email.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.skystorm.net From bokr at oz.net Sat Jan 22 23:28:27 2005 From: bokr at oz.net (Bengt Richter) Date: Sun, 23 Jan 2005 04:28:27 GMT Subject: specifying constants for a function (WAS: generator expressions: performance anomaly?) References: Message-ID: <41f325b5.1576259210@news.oz.net> On Sat, 22 Jan 2005 16:22:33 +1000, Nick Coghlan wrote: >Steven Bethard wrote: >> I wrote: >> > If you really want locals that don't contribute to arguments, I'd be >> > much happier with something like a decorator, e.g.[1]: >> > >> > @with_consts(i=1, deftime=time.ctime()) >> > def foo(x, y=123, *args, **kw): >> > return x*y, kw.get('which_time')=='now' and time.ctime() or deftime >> > >> > Then you don't have to mix parameter declarations with locals >> > definitions. >> > >> > Steve >> > >> > [1] I have no idea how implementable such a decorator would be. I'd >> > just like to see function constants declared separate from arguments >> > since they mean such different things. >> >> I played around with this, and I think it's basically implementable: > >Raymond's constant binding decorator is probably a good model for how to do it: >http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/277940 > I thought so too. I modified it to accept **presets as a keyword argument and generate constants and assignments from its values matching assignment names when the rhs was __frompresets__, e.g., >>> from makeconstpre import make_constants as pre >>> import time >>> @pre(verbose=True, deftime=time.ctime(), a=1, b=2, c=3, pi=__import__('math').pi) ... def foo(): ... deftime = __frompresets__ ... b, a = __frompresets__ ... c = __frompresets__ ... pi = __frompresets__ ... return locals() ... __frompresets__ : deftime --> Sat Jan 22 20:18:09 2005 __frompresets__ : ('b', 'a') --> (2, 1) __frompresets__ : c --> 3 __frompresets__ : pi --> 3.14159265359 locals --> >>> import dis >>> dis.dis(foo) 3 0 LOAD_CONST 1 ('Sat Jan 22 20:18:09 2005') 3 STORE_FAST 3 (deftime) 4 6 LOAD_CONST 2 ((2, 1)) 9 UNPACK_SEQUENCE 2 12 STORE_FAST 2 (b) 15 STORE_FAST 0 (a) 5 18 LOAD_CONST 3 (3) 21 STORE_FAST 1 (c) 6 24 LOAD_CONST 4 (3.1415926535897931) 27 STORE_FAST 4 (pi) 7 30 LOAD_CONST 5 () 33 CALL_FUNCTION 0 36 RETURN_VALUE >>> foo() {'a': 1, 'c': 3, 'pi': 3.1415926535897931, 'b': 2, 'deftime': 'Sat Jan 22 20:18:09 2005'} Not vary tested as yet, but seems to work. I want to eliminate redundant constants if the same name is assigned = __frompresets__ more than once. Right now I brute force generate another constant. Regards, Bengt Richter From rupole at hotmail.com Fri Jan 28 02:04:57 2005 From: rupole at hotmail.com (Roger Upole) Date: Fri, 28 Jan 2005 02:04:57 -0500 Subject: PythonWin (build 203) for Python 2.3 causes Windows 2000 to grind to a halt? References: <3f233389.0501271147.43572416@posting.google.com> Message-ID: <41f9e4a9$1_1@127.0.0.1> These look like symptoms of sf bug #1017504 http://sourceforge.net/tracker/index.php?func=detail&aid=1017504&group_id=78018&atid=551954 What version of Pywin32 are you running ? There's a (semi) fix for this in the latest build. hth Roger "Chris P." wrote in message news:3f233389.0501271147.43572416 at posting.google.com... > I've been having a problem with PythonWin that seemed to start > completely spontaneously and I don't even know where to START to find > the answer. The only thing I can think of that marks the point > between "PythonWin works fine" and "PythonWin hardly every works fine" > was that I changed the size of my Virtual Paging file, noticing that > it was too small (I currently have a P4 with 1G of RAM). I tried > returning it to its original (smaller) size, but it didn't fix the > problems. > > The first time I noticed it, I was using PythonWin and then > right-clicked on My Computer to use "Explore". Instead of the usual > full listing (approx 10 items), I got a mini-listing of 4 items. > Then, after clicking "Explore", I either don't get a new window at all > OR I get a strange file explorer that won't let me look at files, > won't let me copy files, etc. The "mini-lising" thing also happens if > I click the "Start" button while PythonWin is open. > > Another problem is trying to open another program while PythonWin is > running - generally, the program will not start, but I also don't get > any kind of error popping up on the screen. My request is just > ignored (although I sometimes get a "system beep".) If I already have > other programs open and then open PythonWin, my menu bar might refuse > to function. Is it significant that, when the menu bar IS working, > the drop-down menu fades in quite slowly, instead of popping up > immediately? > > At the end of this message, I've pasted a screen dump of a message I > get when I try to open a file and I've got other apps open (note that > I can have very few, non-memory intensive apps open and I still get > it). > > Thanks for any help you can give, > > - Chris > > [SCREEN DUMP AFTER I TRY TO OPEN A .PY FILE] > File "C:\Python23\Lib\site-packages\pythonwin\pywin\mfc\docview.py", > line 91, in CreateNewFrame > wnd.LoadFrame(self.GetResourceID(), -1, None, context) # triggers > OnCreateClient... > win32ui: LoadFrame failed > > win32ui: CreateNewFrame() virtual handler ( SyntEditTemplate.CreateNewFrame of > 0x01193F30>>) raised an exception > TypeError: PyCTemplate::CreateNewFrame must return a PyCFrameWnd > object. ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= East/West-Coast Server Farms - Total Privacy via Encryption =--- From mfranklin1 at gatwick.westerngeco.slb.com Tue Jan 25 08:44:32 2005 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Tue, 25 Jan 2005 13:44:32 +0000 Subject: tkinter socket client ? In-Reply-To: <1106659122.977876.234250@z14g2000cwz.googlegroups.com> References: <1106288752.561833.46510@z14g2000cwz.googlegroups.com> <11h1v0lnsoh9l46vmt26umn5kafdk5n7u8@4ax.com> <1106307973.536723.297940@z14g2000cwz.googlegroups.com> <35cae5F4jvrirU1@individual.net> <1106311130.446259.30710@f14g2000cwb.googlegroups.com> <1106318469.311179.126140@c13g2000cwb.googlegroups.com> <1106319270.932204.180590@c13g2000cwb.googlegroups.com> <1106659122.977876.234250@z14g2000cwz.googlegroups.com> Message-ID: Tonino wrote: > Hi, > > thanks for this info - I had to abandon the createfilehandler() method > as it is not supported in windows and the GUI "might" be used there at > some time ... > > So - I went the threading route - works well - for now - so I will > stick to it ... > > BUT - the next question: > In the Text() widget - why - when the text scrolls off the screen - > does the window not follow it ? > > I have added a scrollbar to it : > > self.center_frame = Frame(self.top_frame, background="tan", > relief=RIDGE) > > self.text=Text(self.center_frame,background='white') > scroll=Scrollbar(self.center_frame) > self.text.configure(yscrollcommand=scroll.set) > > self.text.pack(side=LEFT, fill=BOTH, expand=YES) > scroll.pack(side=RIGHT,fill=Y) > self.center_frame.pack(side=RIGHT, expand=YES, fill=BOTH) > > > but the window does not scroll to follow the text ? > Any ideas ? > This is the default behavior of the Text widget. You have two options (as I see it) one, put the new text at the top of the Text widget textwidget.insert(0, "your new text") or two, use the yview_pickplace method to move the view down every time you insert text textwidget.yview_pickplace('end') I wrote a sub-class of the ScrolledText widget to do just this I gave it a write method - so I could re-direct stdout to it - and also called yview_pickplace in that method. HTH Martin. From fccoelho at gmail.com Tue Jan 11 06:32:01 2005 From: fccoelho at gmail.com (Flavio codeco coelho) Date: 11 Jan 2005 03:32:01 -0800 Subject: Checking for X availability Message-ID: I have a program that uses pythondialog for its UI. Pythondialog is a wrapper of the shell dialog and xdialog libs. But I would like for it to switch between using Dialog ( when X is not available ) and xdialog (when X is available) So my question is: how can I check for the availability of X? i.e., How will my program know if its running in a text only console or in console window over X? thanks, Fl?vio From rkern at ucsd.edu Mon Jan 31 00:29:51 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sun, 30 Jan 2005 21:29:51 -0800 Subject: PyGame not working(?) In-Reply-To: <20050130152208505-0800@news.claremont.edu> References: <20050129232540162-0800@news.claremont.edu> <20050130152208505-0800@news.claremont.edu> Message-ID: Chris Weisiger wrote: > Thanks; I've now successfully installed Numeric, as well as all of the > other dependencies listed for PyGame. However, PyGame appears to still > not be working. When I try to run the program at the top of this page: > http://www.pygame.org/docs/tut/tom/games2.html > I get the following error: > > % python main.py > Fatal Python error: Interpreter not initialized (version mismatch?) > Abort A couple things: * Are you sure you are using the same python executable that you compiled the extension modules against? * If you aren't using the X11 versions of SDL et al., then you need to run your scripts with pythonw, which will run the framework's interpreter in such a way that it can communicate with the native window server. This shouldn't give you the error above, though. -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From andre.roberge at gmail.com Fri Jan 21 20:57:48 2005 From: andre.roberge at gmail.com (=?iso-8859-1?B?QW5kcuk=?=) Date: 21 Jan 2005 17:57:48 -0800 Subject: finding name of instances created References: <1106352799.481829.279900@c13g2000cwb.googlegroups.com> Message-ID: <1106359068.802501.35190@z14g2000cwz.googlegroups.com> Using the method suggested by Steven Bethard, I *almost* got it working the way I would like. Here's my program: === .class PrivateClass(object): . dict = {} . def not_so_simple_method(self): . for name in PrivateClass.dict.keys(): . if PrivateClass.dict[name] == self: . print "instance " + name + " called not so simple" . apparently_simple_method = not_so_simple_method . def __init__(self): . print "instance created" . for name, value in globals().iteritems(): . if isinstance(value, PrivateClass): . PrivateClass.dict[name] = value .def public_class(): . return PrivateClass() .print "=== start===" .alpha = public_class() .print "created alpha" .print PrivateClass.dict .print "### alpha is not there\n" .beta = public_class() .print "created beta" .print PrivateClass.dict .print "### we are always one behind in the dict content\n" .alpha.apparently_simple_method() .beta.apparently_simple_method() ================================= The output follows: === start=== instance created created alpha {} ### alpha is not there instance created created beta {'alpha': <__main__.PrivateClass object at 0x0117CDD0>} ### we are always one behind in the dict content instance alpha called not so simple ======= Note that instance beta was never recognized when it called "apparently simple method". I'm sure there must be a way to do this.... Andr? From jack at performancedrivers.com Wed Jan 26 12:03:01 2005 From: jack at performancedrivers.com (Jack Diederich) Date: Wed, 26 Jan 2005 12:03:01 -0500 Subject: limited python virtual machine (WAS: Another scripting language implemented into Python itself?) In-Reply-To: <1a72l6umj80r6.dlg@usenet.alexanderweb.de> References: <17fpi4ewvvz3h.dlg@usenet.alexanderweb.de> <1a72l6umj80r6.dlg@usenet.alexanderweb.de> Message-ID: <20050126170301.GJ1607@performancedrivers.com> On Wed, Jan 26, 2005 at 05:18:59PM +0100, Alexander Schremmer wrote: > On Tue, 25 Jan 2005 22:08:01 +0100, I wrote: > > >>>> sys.safecall(func, maxcycles=1000) > > could enter the safe mode and call the func. > > This might be even enhanced like this: > > >>> import sys > >>> sys.safecall(func, maxcycles=1000, > allowed_domains=['file-IO', 'net-IO', 'devices', 'gui'], > allowed_modules=['_sre']) > > Any comments about this from someone who already hacked CPython? Yes, this comes up every couple months and there is only one answer: This is the job of the OS. Java largely succeeds at doing sandboxy things because it was written that way from the ground up (to behave both like a program interpreter and an OS). Python the language was not, and the CPython interpreter definitely was not. Search groups.google.com for previous discussions of this on c.l.py -Jack From ialbert at mailblocks.com Wed Jan 12 09:16:08 2005 From: ialbert at mailblocks.com (Istvan Albert) Date: Wed, 12 Jan 2005 09:16:08 -0500 Subject: shutil.move has a mind of its own In-Reply-To: References: Message-ID: Daniel Bickett wrote: > In my script, rather than a file being moved to the desired location, > it is, rather, moved to the current working directory (in this case, > my desktop -- without any exceptions, mind you). As it happens, the what is the output generated by the lines: fdir, fname = randFileInfo.new() debugMess( "Generated file information: %s, %s" % ( fdir, fname ) ) Istvan. From bob.ducharme at gmail.com Fri Jan 21 13:37:18 2005 From: bob.ducharme at gmail.com (bobdc) Date: 21 Jan 2005 10:37:18 -0800 Subject: short programming projects for kids Message-ID: <1106332638.595750.150590@c13g2000cwb.googlegroups.com> I will be teaching an "Introduction to Programming" class to some middle school aged children and will be using Python, obviously. Does anyone have suggestions for simple little programs to create and analyze with them after I get past turtle graphics? Turtle graphics will be plenty for the first session, and I will leave time to ask them what they'd like to do in later sessions, but I was curious if anyone on the list has experience picking pedagogical programming examples appropriate for twelve-year-olds' attention spans. thanks, Bob From tjreedy at udel.edu Sun Jan 30 03:37:08 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 30 Jan 2005 03:37:08 -0500 Subject: Test of comp.lang.python to python-list to gmane pathway. References: <1107040729.535936.42230@c13g2000cwb.googlegroups.com> Message-ID: Feel free to ignore this. Some system falsely labeled this post (sent via gmane) as possible spam. I am sending it back in the opposite direction to see what transpires that way. Sorry for the disturbance. tjr "Terry Reedy" wrote in message news:cthdth$fp0$1 at sea.gmane.org... > > "Michael Tobis" wrote in message > news:1107040729.535936.42230 at c13g2000cwb.googlegroups.com... > >> I'd like to dynamically add a method to an instance at >> instantiation time. > > No can do. A method is function that is an attribute of a class, even if > accessed via an instance. A function added to an instance as an > attribute of the instance remains a function. It is instance-specific > data that methods and other code can use, just like other instance data, > for instance-specific effects. Two common examples: > > class composer: > # skip obvious init > def __call__(self, x): return self.outer(self.inner(x)) > > sincos = composer(math.sin, math.cos) > # yes, this can also be done with composer function with nested scope > > class memoizer: # posted several times > # skip init again > def __call__(self,x): > # return previously computed self.memodict[x] if it exists > # or calculate, store, and return self.func(x) > > \> PS - any idea how to get past google's stupid formatting these days? I >> thought they were supposed to like python, but they just ignore leading >> blanks. > > Don't use google to post on clp. Go to news.gmane.org instead. > > Terry J. Reedy > > > > -- > http://mail.python.org/mailman/listinfo/python-list > From g.horvath at mx.at Tue Jan 4 14:40:25 2005 From: g.horvath at mx.at (Gregor Horvath) Date: Tue, 04 Jan 2005 19:40:25 GMT Subject: HTML table input data grid Message-ID: Hi, I googled for a possibilty to create a html table where the user can input data. I just found this site: http://www.codeproject.com/aspnet/I3HTree2.asp That is what I am looking for. Is there an existing solution for python? -- Greg From steve at holdenweb.com Mon Jan 17 07:21:16 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 17 Jan 2005 07:21:16 -0500 Subject: lambda In-Reply-To: References: <1105633239.316956.262140@f14g2000cwb.googlegroups.com> <41EBA021.5060903@holdenweb.com> Message-ID: Antoon Pardon wrote: > Op 2005-01-17, Steve Holden schreef : > >>Antoon Pardon wrote: >>[...] >> >>>>"A foolish consistency is the hobgoblin of little minds". Rules are made >>>>to be broken. >>> >>> >>>Like only use immutables as dictionary keys. >>> >> >>Fair enough, but don;t go advising newbies to do this. > > > How about something like this. > > Because of the extra precautions one has to take when > using mutables as hash keys, we advise newbies > to stick with immutable keys until they have gathered > enough knowledge and experience to adequatly weight > the pro and cons of a mutable key solution against > an immutable key solution. > There you go with the minutiae again. How about: "Don't use mutables as hash keys"? regards Steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 From jcribbs at twmi.rr.com Sun Jan 30 18:06:49 2005 From: jcribbs at twmi.rr.com (Jamey Cribbs) Date: Sun, 30 Jan 2005 23:06:49 GMT Subject: ANNOUNCE: KirbyBase 1.7 In-Reply-To: <7xy8ea1qgt.fsf@ruckus.brouhaha.com> References: <7xy8ea1qgt.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > That's cute, especially the part about using Python expressions > instead of SQL to express queries. I don't see anything in the info > page about what happens when you have multiple clients updating the db > concurrently. Do you make any attempt to handle that? Yep. There are two server scripts included with the distribution. One (kbsimpleserver.py) does serial, blocking requests, so there are no concurrent-access issues. The second server script (kbthreadedserver.py) is threaded and non-blocking. I have code in the script that manages read and write locks for each table. I'm no rocket scientist, but I have been using kbthreadedserver.py at work for several months with no issues so far, so I am beginning to trust the code. :) Jamey From fredrik at pythonware.com Fri Jan 28 08:29:34 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 28 Jan 2005 14:29:34 +0100 Subject: Who should security issues be reported to? References: <1106863164.745581.11920@f14g2000cwb.googlegroups.com><1106911061.429966.303510@f14g2000cwb.googlegroups.com><7x3bwlsqnj.fsf@ruckus.brouhaha.com> Message-ID: Duncan Booth wrote: > I think its a bit borderline whether this really was a security bug in > Python rather than just a problem with the way some people used Python. It > was a standard library which if used in the wrong way opens a security hole > on your machine for SmartCookie, that should be "if used, opens a security hole" From mmokrejs at ribosome.natur.cuni.cz Mon Jan 10 14:32:59 2005 From: mmokrejs at ribosome.natur.cuni.cz (=?UTF-8?B?TWFydGluIE1PS1JFSsWg?=) Date: Mon, 10 Jan 2005 20:32:59 +0100 Subject: Writing huge Sets() to disk In-Reply-To: <1f7befae050110111239496b07@mail.gmail.com> References: <41E2A91D.7080006@ribosome.natur.cuni.cz> <1105381712.3588.15.camel@localhost.localdomain> <41E2CE0E.5000704@ribosome.natur.cuni.cz> <1f7befae050110111239496b07@mail.gmail.com> Message-ID: <41E2D86B.5080909@ribosome.natur.cuni.cz> Tim Peters wrote: > [Martin MOKREJ?] > >> just imagine, you want to compare how many words are in English, German, >>Czech, Polish disctionary. You collect words from every language and record >>them in dict or Set, as you wish. > > > Call the set of all English words E; G, C, and P similarly. > > >> Once you have those Set's or dict's for those 4 languages, you ask >>for common words > > > This Python expression then gives the set of words common to all 4: > > E & G & C & P > > >>and for those unique to Polish. > > > P - E - G - C > > is a reasonably efficient way to compute that. Nice, is it equivalent to common / unique methods of Sets? > > >>I have no estimates >>of real-world numbers, but we might be in range of 1E6 or 1E8? >>I believe in any case, huge. > > > No matter how large, it's utterly tiny compared to the number of > character strings that *aren't* words in any of these languages. > English has a lot of words, but nobody estimates it at over 2 million > (including scientific jargon, like names for chemical compounds): > > http://www.worldwidewords.org/articles/howmany.htm As I've said, I analyze in real something else then languages. However, it can be described with the example of words in different languages. But nevertheless, imagine 1E6 words of size 15. That's maybe 1.5GB of raw data. Will sets be appropriate you think? >>My concern is actually purely scientific, not really related to analysis >>of these 4 languages, but I believe it describes my intent quite well. >> >> I wanted to be able to get a list of words NOT found in say Polish, >>and therefore wanted to have a list of all, theoretically existing words. >>In principle, I can drop this idea of having ideal, theoretical lexicon. >>But have to store those real-world dictionaries anyway to hard drive. > > > Real-word dictionaries shouldn't be a problem. I recommend you store > each as a plain text file, one word per line. Then, e.g., to convert > that into a set of words, do > > f = open('EnglishWords.txt') > set_of_English_words = set(f) I'm aware I can't keep set_of_English_words in memory. > f.close() M. From jeff at ccvcorp.com Mon Jan 17 19:50:21 2005 From: jeff at ccvcorp.com (Jeff Shannon) Date: Mon, 17 Jan 2005 16:50:21 -0800 Subject: Fuzzy matching of postal addresses In-Reply-To: <96B2w2E$HF7BFwSq@at-andros.demon.co.uk> References: <96B2w2E$HF7BFwSq@at-andros.demon.co.uk> Message-ID: <10uon0ir3n6b7ac@corp.supernews.com> Andrew McLean wrote: > The problem is looking for good matches. I currently normalise the > addresses to ignore some irrelevant issues like case and punctuation, > but there are other issues. I'd do a bit more extensive normalization. First, strip off the city through postal code (e.g. 'Beaminster, Dorset, DT8 3SS' in your examples). In the remaining string, remove any punctuation and words like "the", "flat", etc. > Here are just some examples where the software didn't declare a match: And how they'd look after the transformation I suggest above: > 1 Brantwood, BEAMINSTER, DORSET, DT8 3SS > THE BEECHES 1, BRANTWOOD, BEAMINSTER, DORSET DT8 3SS 1 Brantwood BEECHES 1 BRANTWOOD > Flat 2, Bethany House, Broadwindsor Road, BEAMINSTER, DORSET, DT8 3PP > 2, BETHANY HOUSE, BEAMINSTER, DORSET DT8 3PP 2 Bethany House Broadwindsor Road 2 BETHANY HOUSE > Penthouse,Old Vicarage, 1 Clay Lane, BEAMINSTER, DORSET, DT8 3BU > PENTHOUSE FLAT THE OLD VICARAGE 1, CLAY LANE, BEAMINSTER, DORSET DT8 3BU Penthouse Old Vicarage 1 Clay Lane PENTHOUSE OLD VICARAGE 1 CLAY LANE > St John's Presbytery, Shortmoor, BEAMINSTER, DORSET, DT8 3EL > THE PRESBYTERY, SHORTMOOR, BEAMINSTER, DORSET DT8 3EL St Johns Presbytery Shortmoor PRESBYTERY SHORTMOOR > The Pinnacles, White Sheet Hill, BEAMINSTER, DORSET, DT8 3SF > PINNACLES, WHITESHEET HILL, BEAMINSTER, DORSET DT8 3SF Pinnacles White Sheet Hill PINNACLES WHITESHEET HILL Obviously, this is not perfect, but it's closer. At this point, you could perhaps say that if either string is a substring of the other, you have a match. That should work with all of these examples except the last one. You could either do this munging for all address lookups, or you could do it only for those that don't find a match in the simplistic way. Either way, you can store the Database B's pre-munged address so that you don't need to constantly recompute those. I can't say for certain how this will perform in the false positives department, but I'd expect that it wouldn't be too bad. For a more-detailed matching, you might look into finding an algorithm to determine the "distance" between two strings and using that to score possible matches. Jeff Shannon Technician/Programmer Credit International From claird at lairds.us Thu Jan 6 18:08:03 2005 From: claird at lairds.us (Cameron Laird) Date: Thu, 06 Jan 2005 23:08:03 GMT Subject: Excluded and other middles in licensing (was: The Industry choice) References: <1104425916.615972.97530@z14g2000cwz.googlegroups.com> <1gpz4ot.1hugdikn2ddctN%aleaxit@yahoo.com> <71dDd.21829$En7.1635461@phobos.telenet-ops.be> <1gpz9qx.vmv8hav17z8qN%aleaxit@yahoo.com> Message-ID: <75r0b2-ohg.ln1@lairds.us> In article <1gpz9qx.vmv8hav17z8qN%aleaxit at yahoo.com>, Alex Martelli wrote: . . . >One last reflection -- I believe there are or used to be some programs >written by people no doubt of very good will, distributed with all >sources and often with no profit motive at all, which are NOT open >source because they include in the license some restrictive clause, such >as "no military use", "no use by organizations which perform testing of >cosmetics on animals", or something of that kind. These would be >examples of closed-source software which DO allow ALMOST any kind of use >-- any EXCEPT the specific one the authors dislike so intensely. > >While most people may not think of such programs as "closed source", >they most definitely ARE: the definition of open source is very strict >about this aspect. > > >Alex With my mathematical background, I'm consistent about calling these "non-open" rather than "closed". I don't insist others adopt my nomenclature ... From ncoghlan at iinet.net.au Thu Jan 27 05:31:20 2005 From: ncoghlan at iinet.net.au (Nick Coghlan) Date: Thu, 27 Jan 2005 20:31:20 +1000 Subject: python without OO In-Reply-To: References: <1106689788.676121.48490@c13g2000cwb.googlegroups.com> Message-ID: <41F8C2F8.8060203@iinet.net.au> Davor wrote: > data structures > and > functions that operate on these data structures Eh? What do you think a class is? Py> data = range(10) Py> list.extend(data, range(5)) Py> list.sort(data) Py> print data [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6, 7, 8, 9] The fact that data.extend(range(5)) and data.sort() are alternative spellings for the second and third lines doesn't change the fact that a class is just a data structure grouped with a bunch of functions that operate on that data structure. Cheers, Nick. -- Nick Coghlan | ncoghlan at email.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.skystorm.net From grante at visi.com Mon Jan 17 14:50:13 2005 From: grante at visi.com (Grant Edwards) Date: 17 Jan 2005 19:50:13 GMT Subject: List problems in C code ported to Python References: <41ebed38$0$87063$a1866201@visi.com> <1105981814.317402.192940@f14g2000cwb.googlegroups.com> Message-ID: <41ec16f5$0$87076$a1866201@visi.com> On 2005-01-17, wittempj at hotmail.com wrote: >>>> l = [] >>>> for i in range(2): > for j in range(2): > l[i][j] = 'x' > > > > Traceback (most recent call last): > File "", line 3, in -toplevel- > l[i][j] = 'x' > IndexError: list index out of range > > So you still have to dimension the list before you can use it , eg like >>l = [] >>for i in range(2): >> l.append([]) >> for j in range(2): >> l[i].append(j) > > then you do not get the indexerror, but I feel a class is what you need > here to make life easier and the program more readable I'd probably numeric python (which I beleive is depricated, but it's what I have installed) or numarray. I think either would make it a lot easier. Using lists of lists when what you want is a matrix can be made to work, but there are a lot of non-obvious traps to fall into. -- Grant Edwards grante Yow! I always wanted a at NOSE JOB!! visi.com From aleaxit at yahoo.com Thu Jan 6 13:55:10 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 6 Jan 2005 19:55:10 +0100 Subject: OT: spacing of code in Google Groups References: <1104516184.077462.283350@c13g2000cwb.googlegroups.com> <1104528447.005870.6530@z14g2000cwz.googlegroups.com> <41d5c606$0$26890$a1866201@visi.com> <5amdnbMsyqlhx0DcRVn-vw@powergate.ca> Message-ID: <1gpzgcv.1a4vagsqm9b69N%aleaxit@yahoo.com> Peter Hansen wrote: > Jacek Generowicz wrote: > > Peter Hansen writes: > >>Why the heck would I ever have to do "rectangle operations" on a > >>regular basis? ;-) > > > > Well, given that all editors are cat equivalent[*], you don't _have_ > > to use any of their features :-) > > This "cat equivalent" thing is a red-herring. I can rarely type more I tried offering a red herring to my cat to check this out, and, sure enough, she indignantly refused it and miaowed loudly for less smelly food. So, you may have a point here. Alex From mwm at mired.org Mon Jan 3 17:38:42 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 03 Jan 2005 16:38:42 -0600 Subject: Continuations Based Web Framework - Seaside. References: <41d7dad7$0$9355$afc38c87@news.optusnet.com.au> <7aTBd.11928$H%6.521997@twister1.libero.it> Message-ID: <861xd2qgst.fsf@guru.mired.org> Steve Holden writes: > It's the *ideas* that are important, though, rather than the > implementation, and my initial hope was to publicise the weakness of > statelessness on the web as applications become more complex. This needed publicity? Isn't it obvious to anyone who has ever written a non-trival web application? Enough so that people started referring to non-web applications as "stately" rather than "stateful". http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From martyn_quick at yahoo.co.uk Fri Jan 21 10:39:12 2005 From: martyn_quick at yahoo.co.uk (Martyn Quick) Date: 21 Jan 2005 07:39:12 -0800 Subject: Configuring Python for Tk on Mac Message-ID: On my desk here at work I have a Mac G4 running Mac OS X v10.2.8. When I go into a terminal and type "python" up comes a nice python interface and all seems great. However when I type "import Tkinter" I'm greeted by the following error. >>> import Tkinter Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.2/lib-tk/Tkinter.py", line 35, in ? import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named _tkinter So I guess something about this implementation is not appropriately configured. I'm guessing this is the default behaviour since I don't think anyone did anything special about python when they set up my machine. What do I do to set it up so I can use Tkinter? Thanks... and sorry if this is an FAQ... but I couldn't find the info easily. Yours, Martyn From http Fri Jan 7 16:48:41 2005 From: http (Paul Rubin) Date: 07 Jan 2005 13:48:41 -0800 Subject: "A Fundamental Turn Toward Concurrency in Software" References: Message-ID: <7x4qhs52rq.fsf@ruckus.brouhaha.com> aurora writes: > Just gone though an article via Slashdot titled "The Free Lunch Is > Over: A Fundamental Turn Toward Concurrency in Software" > [http://www.gotw.ca/publications/concurrency-ddj.htm]. It argues that > the continous CPU performance gain we've seen is finally over. And > that future gain would primary be in the area of software concurrency > taking advantage hyperthreading and multicore architectures. Well, another gain could be had in making the software less wasteful of cpu cycles. I'm a pretty experienced programmer by most people's standards but I see a lot of systems where I can't for the life of me figure out how they manage to be so slow. It might be caused by environmental pollutants emanating from Redmond. From jtr at ofb.net Fri Jan 21 16:52:59 2005 From: jtr at ofb.net (John Reese) Date: Fri, 21 Jan 2005 21:52:59 +0000 (UTC) Subject: Is there a library to parse Mozilla "mork" documents? References: <1rb1v0566bmkesg9mclsk28idkjopgofuc@4ax.com> Message-ID: On Thu, 20 Jan 2005 23:48:34 -0800, Tim Roberts wrote: > John Reese wrote: >> >>Mozilla, Firefox, Thunderbird, and so forth use this awful format >>called MORK to store all kinds of things: which messages you've read >>in a newsgroup, headers and indexes into the mbox file of messages in >>a mail folder, and address books. > > Yes. What a crock that is. The MORK format is a great way to compress > tabular information, IF the information consists of the same pieces of data > over and over. E-mail boxes do not fit into that class, so I have no doubt > that the typical Thunderbird MORK file is singificantly LARGER than the > same file would be in, say, INI format. > > I wrote a Python script to parse it, but it isn't terribly robust. I was > able to produce a dictionary, but I didn't do anything with the results. > You're welcome to take a look: > http://www.probo.com/timr/parsemsf.py Thanks, I'll work with this. I have to say that this has all been worth it just to read about Jamie Zawinski railing against this file format. I think your comment at the top sums it up well: # Why am I doing this? From tjreedy at udel.edu Thu Jan 13 15:08:16 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 13 Jan 2005 15:08:16 -0500 Subject: lambda References: Message-ID: "Egor Bolonev" wrote in message news:opskje6vb7xejsk1 at theurs.octopusnet.lan... > why functions created with lambda forms cannot contain statements? Because lambda was only ever intended to be an inline abbreviation of simple one-use functions whose body consists of 'return '. It is clear to me that the word 'lambda' was a mistake since it engenders expectations of more than that from too many people, such as you. Terry J. Reedy From akineko at pacbell.net Fri Jan 14 01:00:10 2005 From: akineko at pacbell.net (Aki Niimura) Date: 13 Jan 2005 22:00:10 -0800 Subject: Pickled text file causing ValueError (dos/unix issue) Message-ID: <1105682410.406541.317590@c13g2000cwb.googlegroups.com> Hello everyone, I started to use pickle to store the latest user settings for the tool I wrote. It writes out a pickled text file when it terminates and it restores the settings when it starts. It worked very nicely. However, I got a ValueError when I started the tool from Unix when I previously used the tool from Windows. File "/usr/local/lib/python2.3/pickle.py", line 980, in load_string raise ValueError, "insecure string pickle" ValueError: insecure string pickle If I do 'dos2unix ' to convert the file, then everything becomes fine. I found in the Python release note saying ... "pickle: Now raises ValueError when an invalid pickle that contains a non-string repr where a string repr was expected. This behavior matches cPickle." I guess DOS text format is creating this problem. My question is "Is there any elegant way to deal with this?". I certainly can catch ValueError and run 'dos2unix' explicitly. But I don't like such crude solution. Any suggestions would be highly appreciated. Best regards, Aki Niimura From duncan.booth at invalid.invalid Thu Jan 6 11:30:20 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 6 Jan 2005 16:30:20 GMT Subject: Developing Commercial Applications in Python References: <1104750017.235937.181370@c13g2000cwb.googlegroups.com> <87pt0iegga.fsf@localhost.localdomain.i-did-not-set--mail-host-address--so-tickle-me> Message-ID: Nick Vargish wrote: > eeykay at gmail.com writes: > >> Can somebody there to point me any good commercial applications >> developed using python ? > > Python is used in several games, including Temple of Elemental Evil > and the forthcoming Civilization 4. Humungous Games, which makes > software for children, is also using Python. Sorry if games would give > your boss the wrong impression... Also "Startrek Bridge Commander", and "Uru: Ages beyond Myst". From amk at amk.ca Fri Jan 21 14:20:03 2005 From: amk at amk.ca (A.M. Kuchling) Date: Fri, 21 Jan 2005 13:20:03 -0600 Subject: What YAML engine do you use? References: <35a6tpF4gmat2U1@individual.net> <7x1xcfwbab.fsf@ruckus.brouhaha.com> <35csm7F4l57inU1@individual.net> Message-ID: On Fri, 21 Jan 2005 18:54:50 +0100, Fredrik Lundh wrote: > judging from http://yaml.org/spec/current.html (750k), the YAML designers are > clearly insane. that's the most absurd software specification I've ever seen. they > need help, not users. IMHO that's a bit extreme. Specifications are written to be detailed, so consequently they're torture to read. Seen the ReStructured Text spec lately? The basic idea -- a data dumping format that's human-readable -- isn't a bad one. OTOH, I can't recall wanting such a thing -- when I want readable output I'm happy using unreadable pickle files, unpickling the object and calling a .dump() or .as_text() method.) But YAML seems to have started out with the goal of being human-writable, something you would write in Emacs, and that seems to have gotten lost; the format is now just as complicated as Restructured Text, but more cryptic (the URI namespacing for tags, for example), not really simpler than XML and in some ways weaker (e.g. only two encodings supported, more complicated escaping rules). For a pure Python application, I can't see a need for YAML; use pickle/cPickle instead, because they're already there. Exchanging serialized objects between Python/Perl/Ruby scripts might be a good use case for YAML, but XML has wider software support and S-expressions are simpler, so my inclination would be to use them instead of YAML. --amk From elephantum at dezcom.mephi.ru Sat Jan 8 06:43:36 2005 From: elephantum at dezcom.mephi.ru (Andrey Tatarinov) Date: Sat, 08 Jan 2005 14:43:36 +0300 Subject: python3: 'where' keyword In-Reply-To: <41dfc018.305122743@news.oz.net> References: <3480qqF46jprlU1@individual.net> <41DF78EB.6040502@iinet.net.au> <41dfc018.305122743@news.oz.net> Message-ID: <349vb9F45c9crU1@individual.net> Bengt Richter wrote: >>>It also allows the necessary but uninteresting setup for an expression >>>to be moved "out of the way", bringing the expression that does the real >>>work to prominence. >>Killer app for this keyword: >> >>class C(object): >> >> x = property(get, set) where: >> def get(self): >> return "Silly property" >> def set(self, val): >> self.x = "Told you it was silly" > Yes, that is cool and it _is_ an interesting idea. Are suites nestable? E.g., is this legal? ... > And, is the whole thing after the '=' an expression? E.g., > > x = ( foo(x) where: > x = math.pi/4.0 > ) where: > def foo(x): print 'just for illustration', x > > or is this legal? > > for y in ([foo(x) for x in bar] where: > bar = xrange(5) > ): baz(y) where: > def baz(arg): return arg*2 > > Not trying to sabotage the idea, really, just looking for clarification ;-) yes, all your examples are correct. And that's the way I'd like to use this feature. From lard at tardis.ed.ac.molar.uk Wed Jan 26 10:35:59 2005 From: lard at tardis.ed.ac.molar.uk (Alex Hunsley) Date: Wed, 26 Jan 2005 15:35:59 GMT Subject: cookielib and urllib2: thread-safe? Message-ID: I'm writing a test script in python for pulling web pages from a web server using urllib2 and cookielib. Since the main thing I am testing is what happens when concurrent requests are made to the web server, I need to make several requests concurrently, which I'll do from different threads in my python script. So the important question is: are cookielib and urllib2 thread safe? Are there any precautions that apply to using these libs in a multi-threaded context? thanks! alex From lkirsh at cs.ubc.ca Thu Jan 20 04:28:34 2005 From: lkirsh at cs.ubc.ca (Lowell Kirsh) Date: Thu, 20 Jan 2005 01:28:34 -0800 Subject: why are these not the same? Message-ID: On a webpage (see link below) I read that the following 2 forms are not the same and that the second should be avoided. They look the same to me. What's the difference? Lowell ---- def functionF(argString="abc", argList = None): if argList is None: argList = [] ... def functionF(argString="abc", argList=None): argList = argList or [] ... http://www.ferg.org/projects/python_gotchas.html (number 5) From fperez.net at gmail.com Mon Jan 31 02:22:19 2005 From: fperez.net at gmail.com (Fernando Perez) Date: Mon, 31 Jan 2005 00:22:19 -0700 Subject: Image stats - going from Matlab to Python References: <1107153660.431217.145160@f14g2000cwb.googlegroups.com> Message-ID: tjv at hotmail.com wrote: > Hi all, > I am working with images in python using PIL. I come from a MATLAB > background so I am finding it to be sometimes frustrating to do things > correctly and quickly. All I need to do is load an image and store a > list of pixel coordinates at which the alpha channel is set to 1. > In Matlab this would be easy...Lets say we have a 2x2x4 array that > represents the image. I would just type something like: > > indices = find(im(:,:,3)==1); > > then work with indices to get xy coords. Is there a similar way to > accomplish the same thing in python and PIL without having a nested for > loop and checking every pixel? > I would appreciate advice. Thanks very much for your attention! The kind of array functionality which you have in mind is implemented in python by the Numeric/Numarray libraries. You can (and should) use the PIL for the more image-specific tasks, but basic array things are done via those others. You may also want to look at matplotlib, for a high level, matlab-compatible plotting library. Regards, f From http Tue Jan 11 13:49:43 2005 From: http (Paul Rubin) Date: 11 Jan 2005 10:49:43 -0800 Subject: OT: MoinMoin and Mediawiki? References: <7x6524d6pv.fsf@ruckus.brouhaha.com> <34h7m9F43vomsU1@individual.net> <7xsm58lcms.fsf@ruckus.brouhaha.com> Message-ID: <7xu0pn4x88.fsf@ruckus.brouhaha.com> Robin Becker writes: > A few months ago I tried and failed to get squirrelmail/php to run > with Apache2 and freeBSD 4.9. It seems that php prefers the old style > apache 1.3 work flow. I got some help from the php guys, but not > enough. I suppose I could have run a separate apache13 server, but > that seems like a cop out to me. We don't want to maintain an extra > set of configs etc etc. I think mod_php doesn't play nice with apache2 but am not aware of any cgi interoperability problems. I ran squirrelmail/php as an apache 1.3 cgi a while back (low enough traffic to not get killed by cgi overhead), if that helps. Note that squirrelmail itself has a bunch of security bugs that the maintainers refuse to acknowledge as bugs. Anyway, I'm still using apache 1.3 (haven't had a reason to modernize) so I can run mod_php if I need to. > Mailman, moinmoin and others work fine with apache2 maybe because they > use a cgi style interface. I would stick with a pythonic solution > unless there's a good reason not too. Yes, I certainly prefer Python to PHP. From jerf at jerf.org Fri Jan 21 18:07:24 2005 From: jerf at jerf.org (Jeremy Bowers) Date: Fri, 21 Jan 2005 18:07:24 -0500 Subject: finding name of instances created References: <1106352799.481829.279900@c13g2000cwb.googlegroups.com> <1106353764.19065.89.camel@bucket.localnet> Message-ID: On Fri, 21 Jan 2005 21:01:00 -0400, Andr? Roberge wrote: > etc. Since I want the user to learn Python's syntax, I don't want to > require him/her to write > alex = CreateRobot(name = 'alex') > to then be able to do > alex.move() This is just my opinion, but I've been involved with teaching new programmers before so I think it is an informed one. I don't think you teach a language by hiding how the language works, no matter what the intentions. You should be *minimizing* the magic. You're going to train your students that Python objects have names (they don't) and that's going to mess them up later. Actually, it's going to mess them up almost right away, because how can they have a list of robots like this: for robot in robots: robot.turn_left() That can't work, right, the command inside the loop can only affect the robot named "robot", right? You can't teach Python if what you're actually teaching them is a variant that you have created that is used nowhere else on Earth, and is internally inconsistent to boot (see loop above, the *real* Python variable semantics conflict with the semantics you are teaching). Considering that not a month goes by where someone doesn't post a question related to this, and it has been a FAQ entry for as long as I've used Python, I think you are doing a major disservice to your "users" by training them that objects magically gets the name when assigned. I strongly urge you to do absolutely no pre-processing of any kind to the programs they generate. (By which I mean changes to the code; running pychecker on it would be OK; and I'd urge you to resist the temptation to process its output, either. Provide a "translation table" if you need to, but they need to learn to read the real output, too.) Programming is hard enough with burdening people with "pleasant falsehoods". Trust your students to handle the truth (and of course rationally minimize the truth they have to handle, and by using Python you're off to a great start there). If they can't handle the truth, with time, effort, and support, they *sure* as hell can't handle lies! From roy at panix.com Fri Jan 7 23:59:07 2005 From: roy at panix.com (Roy Smith) Date: Fri, 07 Jan 2005 23:59:07 -0500 Subject: Getting rid of "self." References: Message-ID: Jeremy Bowers wrote: > were I programming in C++ routinely now I'd prefix "this" and > dispense with that ugly "m_" garbage. (One of the things I ***hate*** > about C++ culture is its acceptance of hideously ugly variable names, > but now I'm two parentheticals deep so I probably ought to stop.)) I'm currently working in a C++ system where they have a wrapper class that provides some transaction locking functionality for member access. The colloquial name for the wrapped "this" pointer is self, i.e. they do "self = wrapper (this)" at the beginning of functions that need it. You can then do "member" to get the bare access or "self.member" to get the locking functionality. It's actually kind of neat, but boy does it play headgames with me when I switch back and forth between that and Python. From jeff at ccvcorp.com Mon Jan 10 12:53:13 2005 From: jeff at ccvcorp.com (Jeff Shannon) Date: Mon, 10 Jan 2005 09:53:13 -0800 Subject: Securing a future for anonymous functions in Python In-Reply-To: References: <1105098890.358721.279550@f14g2000cwb.googlegroups.com> <1105289391.534192.74060@c13g2000cwb.googlegroups.com> <1105357625.835608.299560@c13g2000cwb.googlegroups.com> Message-ID: <10u5fu3o7v4h9e3@corp.supernews.com> Jacek Generowicz wrote: > "Anna" writes: > >>But first, wouldn't something like: >> >>[x+1 for x in seq] >> >>be even clearer? > > I'm glad you mentioned that. [...] > > As to whether it is clearer. That depends. I would venture to suggest > that, given a pool of laboratory rats with no previous exposure to > Python, more of them would understand the map-lambda than the list > comprehension. I would venture to suggest the exact opposite, that the syntax of a list comprehension is in itself suggestive of its meaning, while 'map' and 'lambda' are opaque until you've researched them. The verb 'to map', in this mathematical sense, is not part of standard usage among anyone that *I* know. Instead, they'd speak of doing something for (or to) each item in a group -- exactly what list comps express. Speaking for *this* laboratory rat, at least, map/lambda was always a nasty puzzle for me and difficult to sort out. But when list comps were introduced, after reading just a sentence or two on how they worked, they were completely clear and understandable -- much more so than map/lambda after many months of exposure. Jeff Shannon Technician/Programmer Credit International From vincent at visualtrans.de Tue Jan 25 14:32:11 2005 From: vincent at visualtrans.de (vincent wehren) Date: Tue, 25 Jan 2005 20:32:11 +0100 Subject: module for 'po' files In-Reply-To: References: Message-ID: Sara Fwd wrote: > Hi all > Is there a module for processing & handling '.po' > files in python? Don't know exactly what you mean by "processing & handling". What do you want to do? -- Vincent Wehren > > > > __________________________________ > Do you Yahoo!? > Read only the mail you want - Yahoo! Mail SpamGuard. > http://promotions.yahoo.com/new_mail From http Tue Jan 4 20:12:04 2005 From: http (Paul Rubin) Date: 04 Jan 2005 17:12:04 -0800 Subject: Python evolution: Unease References: <7xacrpdxy3.fsf@ruckus.brouhaha.com> Message-ID: <7x652che6z.fsf@ruckus.brouhaha.com> Skip Montanaro writes: > Start writing (or reorganizing). Folks, this is open source. I'm > sure by the traffic on the list most people here know how to write. Irrelevant, the issue isn't what docs can be written if someone wants to do it, it's what docs are actually already there. I mean every shortcoming anyone could raise about Python or anything else could have the same answer, "it's open source, go fix it". The question is what does the existing stuff do. > In the case of Tkinter, you should probably get the okay of the > authors of various external docs before incorporating them into the > Python docs, If such permission is available then the external docs should just be dropped into the distro. > but note that several Tkinter-related documents are referenced > directly from the Tkinter module docs: Irrelevant, the Python docs mean the ones that are included, not the ones that are merely referenced. > This being the Internet and all, it's not clear that referencing external > documentation is somehow worse than incorporating it directly into the > distribution. The same thing could be said for software. So why not eliminate the Python library and let everyone download each module separately? Because it's bogus is why. It really does matter whether something is included or just referenced. That's what "batteries included" is supposed to be about--you get ONE package and it's supposed to have everything you need without having to go forage for additional components. It matters because most users shouldn't need to care about the Python distro at all, since they got Python through its inclusion in some bigger distro. E.g., I'm now running the Python that was included in Fedora Core 3 GNU/Linux, a complete OS distro on a DVD-ROM, containing about 3 gigabytes not including sources. And when a user installs 3 gigabytes of software from a DVD, they can reasonably expect that they've installed a complete system and shouldn't need to download anything additional to use all the features of the programs on the DVD. Now the Fedora maintainers aren't Python gurus--people ask for Python so they did the obvious thing: downloaded it, ran its installer, put the output into their distro, and said "ok, Fedora has Python". That's all they should need to do to incorporate Python into Fedora. So it's up to the Python maintainers, not the Fedora maintainers or the user, to make sure that the Python distro has everything that users need, without further downloading. And that was just about Tkinter, for which good docs exist but just don't happen to be in the distro. How about something like SocketServer, for which no reasonable docs exist at all? There's no way to figure out how to use it without reading the source. Or the socket library, whose docs say to go buy a book by W. Richard Stevens. The book is very good, but having to go buy a proprietary book is the opposite of what self-contained free software documentation is supposed to mean. I'm not trying to bash Python, which is excellent in many ways, or I wouldn't be using it. I just see various other free software projects as trying to live up to higher standards and I think Python should aspire to the same thing. > As for stuff that exists in PEPs and release notes, they should > already all have the necessary copyright (either they were placed in > the public domain or they are already part of the Python > distribution) to allow you do just check out a CVS tree, make the > necessary edits and either check the files back in or submit a patch > to SourceForge. And about that full featured Python web browser and native-code Python compiler, all you have to do is go write it. Come on. Having to piece together info from a dozen obscure and inconsistent PEP's and stuff in the CVS tree and source comments is not what most people think of as "documentation". Documentation means I can look in the manual and the info is right there, properly referenced in the table of contents and in the proper section for that type of language feature, unified with the rest of the docs. > In the documentation arena, I think more thought should probably be > given to producing online docs that can be directly annotated, thus > further reducing the barrier to more complete documentation (and > more updates). Take a look at latex2html, propose or implement > changes, or just rewrite the damn thing in Python. I think > latex2html is probably a recurring nightmare for Fred Drake. I've personally been happy with Texinfo for other kinds of docs and would consider it easier to deal with than latex2html. It might even be feasible to edit it in a wiki, so anyone could improve it easily. Another idea is web-based doc comments like PHP and MySQL have, so the doc editors can incorporate the info from the comments in subsequent doc releases. From deetsNOSPAM at web.de Mon Jan 3 08:10:15 2005 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Mon, 03 Jan 2005 14:10:15 +0100 Subject: Async-signal safe functions in signal handlers (unix) References: <6942fc70.0501030347.29253110@posting.google.com> Message-ID: > So, is there a) any mechanism inside Python that can detect if the > current code is executed in a signal handler, or b) a list of > statements that must not be used in a Python signal handler in order > to avoid glibc function calls that are not async-signal safe? The execution of signal handlers in python is not done really asynchronous - instead, an incoming signal is noticed and flagged to the interpreters byte code loop - so the signal gets dealed with when the current bytecode instruction is termintated. Read section 7.1 in the docs about the signal module. In other words: Don't worry, be happy. -- Regards, Diez B. Roggisch From luismgz at gmail.com Mon Jan 10 10:49:53 2005 From: luismgz at gmail.com (Luis M. Gonzalez) Date: 10 Jan 2005 07:49:53 -0800 Subject: else condition in list comprehension In-Reply-To: References: <1105302040.286420.313240@c13g2000cwb.googlegroups.com> <1105305000.052714.188980@c13g2000cwb.googlegroups.com> Message-ID: <1105372193.185270.279290@c13g2000cwb.googlegroups.com> It's me wrote: > > z = [i + (2, -2)[i % 2] for i in range(10)] > > But then why would you want to use such feature? Wouldn't that make the > code much harder to understand then simply: > > z=[] > for i in range(10): > if i%2: > z.append(i-2) > else: > z.append(i+2) > > Or are we trying to write a book on "Puzzles in Python"? Once you get used to list comprehensions (and it doesn't take long), they are a more concise and compact way to express these operations. I think that writing 6 lines instead of 1 could be more readable of you are a beginner, but after playing a little bit with listcomps for the first time, you'll see they are very practical yet readable. From news at NOwillmcguganSPAM.com Wed Jan 26 11:25:43 2005 From: news at NOwillmcguganSPAM.com (Will McGugan) Date: Wed, 26 Jan 2005 16:25:43 +0000 Subject: Help With Python In-Reply-To: <41f7c3a7$0$7777$db0fefd9@news.zen.co.uk> References: <41f7c3a7$0$7777$db0fefd9@news.zen.co.uk> Message-ID: <41f7c487$0$7777$db0fefd9@news.zen.co.uk> > > >>> print "Spam, " * 510 + "Spam" Or if you have 2.4.. >>> print ", ".join( "Spam" for _ in xrange( 511 ) ) Although, the replys with links will ultimately be more helpful! Will McGugan From deetsNOSPAM at web.de Mon Jan 24 16:33:27 2005 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Mon, 24 Jan 2005 22:33:27 +0100 Subject: add indexes on the fly to lists References: Message-ID: The data structure you want to use is a dictionary - known as hashmap or hash or map in other languages. Lets say you have a few objects of type town that you want to access using their zip, then things could look like this: ------------ class Town(object): def __init__(self, zip, cool_clubs): self.zip = zip self.colo_clubs = cool_clubs towns = [Berlin(10439, ["Marietta", "ICON", "Bastart"]), Cologne(50000, ["Subway", "Stadtgarten", "Geb?ude 9"])] index = {} for town in towns: index[town.zip] = town ---------------- Hope that makes it clear to you - look into the tutorial for a chapter about python data structures. -- Regards, Diez B. Roggisch From ncoghlan at iinet.net.au Sat Jan 8 00:10:06 2005 From: ncoghlan at iinet.net.au (Nick Coghlan) Date: Sat, 08 Jan 2005 15:10:06 +1000 Subject: sorting on keys in a list of dicts In-Reply-To: <10ttukogfl43p62@corp.supernews.com> References: <10tr9ejf05pv660@corp.supernews.com> <10ttukogfl43p62@corp.supernews.com> Message-ID: <41DF6B2E.3030700@iinet.net.au> Jeff Shannon wrote: > Agreed. I'd started typing before I realized that it'd provide a stable > sort, which pretty much answered my own question, but decided to send it > anyhow in case I'd missed anything else... :) And it turns out we both missed the fact that it avoids comparing the dictionaries which could save a *lot* of number crunching (as well as making otherwise unsortable lists sortable). So it's a good thing you did decide to send it :) Cheers, Nick. -- Nick Coghlan | ncoghlan at email.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.skystorm.net From fuzzyman at gmail.com Tue Jan 25 11:02:47 2005 From: fuzzyman at gmail.com (Fuzzyman) Date: 25 Jan 2005 08:02:47 -0800 Subject: Another scripting language implemented into Python itself? In-Reply-To: References: <1106643765.733317.27440@f14g2000cwb.googlegroups.com> Message-ID: <1106668967.677864.36690@f14g2000cwb.googlegroups.com> Nick Coghlan wrote: > Fuzzyman wrote: > > An implementation of the core language semantics - without any modules > > or file operations would be dead useful. > > > > It could replace some of the function of the long dead rexec modules as > > well as support projects like this. > > Securing a custom build of the CPython interpreter would probably be > significantly easier than designing a 'secure mode' that ran on top of the > standard version. The former might even be a stepping stone towards the latter. > > Still not easy though (the main task would be to prevent Python code from > accessing the OS, while still allowing module imports to work). Pure python imports only... no C extensions. Regards, Fuzzy http://www.voidspace.org.uk/python/index.shtml > > Cheers, > Nick. > > -- > Nick Coghlan | ncoghlan at email.com | Brisbane, Australia > --------------------------------------------------------------- > http://boredomandlaziness.skystorm.net From sjmachin at lexicon.net Tue Jan 11 15:26:48 2005 From: sjmachin at lexicon.net (John Machin) Date: 11 Jan 2005 12:26:48 -0800 Subject: unicode mystery In-Reply-To: References: Message-ID: <1105475208.187957.282650@c13g2000cwb.googlegroups.com> Sean McIlroy wrote: > I recently found out that unicode("\347", "iso-8859-1") is the > lowercase c-with-cedilla, so I set out to round up the unicode numbers > of the extra characters you need for French, and I found them all just > fine EXCEPT for the o-e ligature (oeuvre, etc). I examined the unicode > characters from 0 to 900 without finding it; then I looked at > www.unicode.org but the numbers I got there (0152 and 0153) didn't > work. Can anybody put a help on me wrt this? (Do I need to give a > different value for the second parameter, maybe?) Characters that are in iso-8859-1 are mapped directly into Unicode. That is, the first 256 characters of Unicode are identical to iso-8859-1. Consider this: >>> c_cedilla = unicode("\347", "iso-8859-1") >>> c_cedilla u'\xe7' >>> ord(c_cedilla) 231 >>> ord("\347") 231 What you did with c_cedilla "worked" because it was effectively doing nothing. However if you do unicode(char, encoding) where char is not in encoding, it won't "work". As John Lenton has pointed out, if you find a character in the Unicode tables, you can just use it directly. There is no need in this circumstance to use unicode(). HTH, John From john at grulic.org.ar Sat Jan 15 00:11:58 2005 From: john at grulic.org.ar (John Lenton) Date: Sat, 15 Jan 2005 02:11:58 -0300 Subject: finding/replacing a long binary pattern in a .bin file In-Reply-To: <1105598214.921103.287010@f14g2000cwb.googlegroups.com> References: <1105598214.921103.287010@f14g2000cwb.googlegroups.com> Message-ID: <20050115051158.GA12018@grulic.org.ar> On Wed, Jan 12, 2005 at 10:36:54PM -0800, yaipa wrote: > What would be the common sense way of finding a binary pattern in a > .bin file, say some 200 bytes, and replacing it with an updated pattern > of the same length at the same offset? > > Also, the pattern can occur on any byte boundary in the file, so > chunking through the code at 16 bytes a frame maybe a problem. The > file itself isn't so large, maybe 32 kbytes is all and the need for > speed is not so great, but the need for accuracy in the > search/replacement is very important. ok, after having read the answers, I feel I must, once again, bring mmap into the discussion. It's not that I'm any kind of mmap expert, that I twirl mmaps for a living; in fact I barely have cause to use it in my work, but give me a break! this is the kind of thing mmap *shines* at! Let's say m is your mmap handle, a is the pattern you want to find, b is the pattern you want to replace, and n is the size of both a and b. You do this: p = m.find(a) m[p:p+n] = b and that is *it*. Ok, so getting m to be a mmap handle takes more work than open() (*) A *lot* more work, in fact, so maybe you're justified in not using it; some people can't afford the extra s = os.stat(fn).st_size m = mmap.mmap(f.fileno(), s) and now I'm all out of single-letter variables. *) why isn't mmap easier to use? I've never used it with something other than the file size as its second argument, and with its access argument in sync with open()'s second arg. -- John Lenton (john at grulic.org.ar) -- Random fortune: If the aborigine drafted an IQ test, all of Western civilization would presumably flunk it. -- Stanley Garn -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From peter at engcorp.com Sat Jan 29 23:12:05 2005 From: peter at engcorp.com (Peter Hansen) Date: Sat, 29 Jan 2005 23:12:05 -0500 Subject: cx_freeze error In-Reply-To: <1107057808.297752.168780@z14g2000cwz.googlegroups.com> References: <1107048210.548048.152870@z14g2000cwz.googlegroups.com> <1107054796.999110.18380@c13g2000cwb.googlegroups.com> <1107057808.297752.168780@z14g2000cwz.googlegroups.com> Message-ID: <1Lqdnd44o_AOw2HcRVn-og@powergate.ca> zyqnews at 163.net wrote: > Thanks for your answer. > I tried it and the result is: > [cxfreeze]$ python > Python 2.2.3 (#1, Oct 15 2003, 23:33:35) > [GCC 3.3.1 20030930 (Red Hat Linux 3.3.1-6)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>>>import re >>>>re.compile > > > >>>>re.__file__ > > '/usr/lib/python2.2/re.pyc' > > Is there any hint? "Hint", maybe. Clear answer, not for me. What it means is that your re module definitely has a "compile" function, as it is supposed to. What that suggests is that when the textwrap.py module is being imported by cx_freeze, it is not finding the correct "re" module when it imports it. I don't know anything about cx_freeze, and I don't have an appropriately configured Linux box to help troubleshoot, so I can't help further, but maybe somebody else could try compiling a simple "hello.py" like you did and offer some suggestions. -Peter From steven.bethard at gmail.com Fri Jan 21 19:30:08 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Fri, 21 Jan 2005 17:30:08 -0700 Subject: default value in a list In-Reply-To: References: <1106349263.943972.72710@f14g2000cwb.googlegroups.com> Message-ID: Paul McGuire wrote: > expand = lambda lst,default,minlen : (lst + [default]*minlen)[0:minlen] Or if you're afraid of lambda like me: def expand(lst,default,minlen):return (lst + [default]*minlen)[0:minlen] or perhaps more readably: def expand(lst, default, minlen): return (lst + [default]*minlen)[0:minlen] No need for an anonymous function when you're naming it. ;) Steve From rschroev_nospam_ml at fastmail.fm Fri Jan 14 11:27:44 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Fri, 14 Jan 2005 16:27:44 GMT Subject: python and macros (again) [Was: python3: 'where' keyword] In-Reply-To: References: <1105437966.129342.304400@f14g2000cwb.googlegroups.com> <7xmzvfn096.fsf@ruckus.brouhaha.com> <7xsm559heo.fsf@ruckus.brouhaha.com> <7xacrcdhzh.fsf@ruckus.brouhaha.com> Message-ID: <4qSFd.30758$Qv5.2842746@phobos.telenet-ops.be> Skip Montanaro wrote: > Fredrik> no, expressions CAN BE USED as statements. that doesn't mean > Fredrik> that they ARE statements, unless you're applying belgian logic. > > Hmmm... I'd never heard the term "belgian logic" before. Googling provided > a few uses, but no formal definition (maybe it's a European phrase so > searching for it in English is futile). I'm from Belgium, and I've never heard it before either. Probably a public secret, very carefully being kept hidden from us Belgians ;) -- "Codito ergo sum" Roel Schroeven From adonisv at DELETETHISTEXTearthlink.net Tue Jan 11 19:57:41 2005 From: adonisv at DELETETHISTEXTearthlink.net (Adonis) Date: Wed, 12 Jan 2005 00:57:41 GMT Subject: Newbie: Pythonwin In-Reply-To: References: Message-ID: <9C_Ed.4799$C52.960@newsread2.news.atl.earthlink.net> Brent W. Hughes wrote: > 1) I'm running a program within Pythonwin. It's taking too long and I want > to stop/kill it. What do I do (other than ctrl-alt-del)? > > 2) I'm running a long program and I want to minimize it to let it continue > to run in the background while I do something else in the foreground. I try > clicking on Pythonwin's minimize box but it doesn't respond until the Python > program finally quits Then it minimizes! Any way I can do what I want > here? > > Brent > > Try running your script using (from command prompt): \path\python.exe \path\script.py Alternatively go to its folder in explorer and double click it to run. pythonwin is just a developing enviroment, and the execution of scripts within it is just for debugging use. Hope this helps. Adonis From __peter__ at web.de Thu Jan 13 07:42:42 2005 From: __peter__ at web.de (Peter Otten) Date: Thu, 13 Jan 2005 13:42:42 +0100 Subject: from __future__ import decorators References: Message-ID: Jacek Generowicz wrote: > I have some code, which makes copious use of the @decorator syntax > which was introduced in Python2.4. Now I find myself in a situation > where I have to run the code under Python 2.3. However, I would like > to keep developing the code with the new syntax. > > How could I best automate the process of making the syntax digestible > by Python2.3 ? Have a look at Bill Mill's redecorate utility: http://llimllib.f2o.org/files/redecorate.py Peter From itsme at yahoo.com Fri Jan 7 11:26:55 2005 From: itsme at yahoo.com (It's me) Date: Fri, 07 Jan 2005 16:26:55 GMT Subject: sorting on keys in a list of dicts References: <10tr9ejf05pv660@corp.supernews.com> Message-ID: What does it mean by "stability in sorting"? Can somebody please give a sample for using the code posted? I am a little lost here and I like to know more about the use of keys.... Thanks, "Nick Coghlan" wrote in message news:mailman.298.1105112062.22381.python-list at python.org... > Jeff Shannon wrote: > > I suppose that your version has the virtue that, if the sortkey value is > > equal, items retain the order that they were in the original list, > > whereas my version will sort them into an essentially arbitrary order. > > Is there anything else that I'm missing here? > > Stability in sorting is a property not to be sneezed at - it means switching to > sorting by a second key gives the effect of "sort by key 1, then by key 2", > whereas that doesn't hold with an unstable sort algorithm. If you've ever used > an application with an unstable sorting process and that only allows sorting a > table on one column at a time, you'll appreciate the frustration that can cause :) > > Also, it's required to match the behaviour of the Python 2.4 version (which gets > to take advantage of the stability of the builtin sort). > > Cheers, > Nick. > > -- > Nick Coghlan | ncoghlan at email.com | Brisbane, Australia > --------------------------------------------------------------- > http://boredomandlaziness.skystorm.net From steven.bethard at gmail.com Mon Jan 24 02:31:17 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Mon, 24 Jan 2005 00:31:17 -0700 Subject: specifying constants for a function (WAS: generator expressions: performance anomaly?) In-Reply-To: <41f490e8.1669238027@news.oz.net> References: <41f325b5.1576259210@news.oz.net> <6I2dnYLoXdcTmGncRVn-vw@comcast.com> <41f490e8.1669238027@news.oz.net> Message-ID: Bengt Richter wrote: > So, e.g., for > > >>> presets = dict(a=1, b=2, deftime=__import__('time').ctime()) > > in the decorator args, the next version will act as if the decorated > function had the source code > > >>> print '%s = __frompresets__' % ', '.join(sorted(presets)) > a, b, deftime = __frompresets__ > > for the current version, except that it will be hidden. Cool! Keep us posted. I assume you'll put this into the Cookbook? Steve From uche at ogbuji.net Thu Jan 27 22:40:43 2005 From: uche at ogbuji.net (Uche Ogbuji) Date: 27 Jan 2005 19:40:43 -0800 Subject: 4suite XSLT thread safe ? In-Reply-To: <35praqF4p8vohU2@individual.net> References: <6lkkc2-fbd.ln1@pluto.i.infosense.no> <35pntaF4os76kU1@individual.net> <35ppqeF4nu516U1@individual.net> <35praqF4p8vohU2@individual.net> Message-ID: <1106883643.169034.74750@c13g2000cwb.googlegroups.com> Sorry I'm late to the whole thread. Diez B. Roggisch is pretty much right on the money in all his comments. 4XSLT *is* thread safe, but each individual processor instance is not thread safe. Yes, this is typical OO style: you encapsulate state in an instance so that as long as each thread has its own instance, there are no state clashes. Therefore, you should be creating at least one processor object per thread. Note: the 4Suite server is a multi-threaded architecture that uses 4XSLT heavily using processor-per-thread. -- Uche Ogbuji Fourthought, Inc. http://uche.ogbuji.net http://4Suite.org http://fourthought.com Use CSS to display XML - http://www.ibm.com/developerworks/edu/x-dw-x-xmlcss-i.html Introducing the Amara XML Toolkit - http://www.xml.com/pub/a/2005/01/19/amara.html Be humble, not imperial (in design) - http://www.adtmag.com/article.asp?id=10286UBL 1.0 - http://www-106.ibm.com/developerworks/xml/library/x-think28.html Manage XML collections with XAPI - http://www-106.ibm.com/developerworks/xml/library/x-xapi.html Default and error handling in XSLT lookup tables - http://www.ibm.com/developerworks/xml/library/x-tiplook.html Packaging XSLT lookup tables as EXSLT functions - http://www.ibm.com/developerworks/xml/library/x-tiplook2.html From harold.fellermann at upf.edu Thu Jan 13 11:26:11 2005 From: harold.fellermann at upf.edu (harold fellermann) Date: Thu, 13 Jan 2005 17:26:11 +0100 Subject: Using Tix and Tkinter In-Reply-To: References: Message-ID: On 31.12.2004, at 16:50, Harlin Seritt wrote: > import Tix > from Tkconstants import * > from Tkinter import * > > root = Tix.Tk() > > Label(root, text="Hello!").pack() > Tix.tixControl().pack() > > root.mainloop() > When I run this, I get the following error: > > Traceback (most recent call last): > File "TixTest.py", line 8, in ? > Tix.tixControl().pack() > AttributeError: 'module' object has no attribute 'tixControl' in the Tix module this widget is called Control. writing Tix.Control().pack() should work. - harold - -- Man will occasionally stumble over the truth, but most of the time he will pick himself up and continue on. -- Winston Churchill From steven.bethard at gmail.com Tue Jan 4 04:45:49 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Tue, 04 Jan 2005 09:45:49 GMT Subject: Hlelp clean up clumpsy code In-Reply-To: References: Message-ID: <7BtCd.276928$5K2.111655@attbi_s03> It's me wrote: > Another newbie question. > > There must be a cleaner way to do this in Python: > > #### section of C looking Python code #### > a = [[1,5,2], 8, 4] > a_list = {} > i = 0 > for x in a: > if isinstance(x, (int, long)): > x = [x,] > for w in [y for y in x]: > i = i + 1 > a_list[w] = i > print a_list > ##### > > The code prints what I want but it looks so "C-like". How can I make it > more Python like? Don't know what version of Python you're using, but if you're using 2.4 (or with a few slight modifications, with 2.3), you can write: py> dict((item, i+1) ... for i, item in enumerate( ... a_sub_item ... for a_item in a ... for a_sub_item ... in isinstance(a_item, (int, long)) and [a_item] or a_item)) {8: 4, 1: 1, 2: 3, 4: 5, 5: 2} Basically, I use a generator expression to flatten your list, and then use enumerate to count the indices instead of keeping the i variable. Steve From jan.dries at dcube-resource.be Sat Jan 1 01:46:12 2005 From: jan.dries at dcube-resource.be (Jan Dries) Date: Sat, 01 Jan 2005 07:46:12 +0100 Subject: Any Python XML Data Binding Utilities Avaiable? In-Reply-To: <41D61BB9.5030701@263.net> References: <41D61BB9.5030701@263.net> Message-ID: <41D64734.6090709@dcube-resource.be> SeSe wrote: > Hi, every one, happy new year! > > I am working on XML with Python. I wonder if there is any XML Schema<-> > Python Object mapping tools so that we can convert one to another. > Thanks. You may want to look at generateDS. It can generate Python data structures from an XML Schema document. It supports only a subset of the schema spec, but is nonetheless quite useful. See http://www.rexx.com/~dkuhlman/generateDS.html There's also minixsv, which does something similar. I've never used it myself though. See http://www.leuthe.homepage.t-online.de/minixsv/minixsv_overview.html The most complete Schema validator in Python is probably XSV. It doesn't have the ability to generate Python object mappings though. See http://www.ltg.ed.ac.uk/~ht/xsv-status.html Another extensive schema parser is part of (and well hidden in) the wsdl toolset from the pywebsvcs project. It does support Python object mapping generation, but the usefulness of the result is limited outside the context of web services. See http://pywebsvcs.sourceforge.net/ Regards, Jan From peter at engcorp.com Sat Jan 8 13:14:17 2005 From: peter at engcorp.com (Peter Hansen) Date: Sat, 08 Jan 2005 13:14:17 -0500 Subject: Recent infoworld column In-Reply-To: <41DEEF0F.5000300@nospamyahoo.com> References: <41DEEF0F.5000300@nospamyahoo.com> Message-ID: Dwarf Electrician wrote: > from a long time listener... > > http://www.infoworld.com/article/04/12/30/01OPstrategic_1.html Kudos for Roger Binns! From aleaxit at yahoo.com Mon Jan 31 08:16:39 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 31 Jan 2005 14:16:39 +0100 Subject: implicit conversion References: Message-ID: <1gr9bia.1nrrc8q1ny2zngN%aleaxit@yahoo.com> Benjamin Schmeling wrote: ... > I don't know how to achieve implicit conversion at this point, turning an > long automatically into an bigint. The other way round, turning an bigint > into long can be realized by defining __long__. Perhaps adding to your bigint class a constructor (not declared as ``explicit'', if you're coding C++) which accepts as its argument a python long might help...? Alex From G.Franzkowiak at web.de Sat Jan 15 12:22:16 2005 From: G.Franzkowiak at web.de (franzkowiak) Date: Sat, 15 Jan 2005 18:22:16 +0100 Subject: interpret 4 byte as 32-bit float (IEEE-754) Message-ID: <34t1p2F4foiplU1@individual.net> Hello, I've read some bytes from a file and just now I can't interpret 4 bytes in this dates like a real value. An extract from my program def l32(c): return ord(c[0]) + (ord(c[1])<<8) + (ord(c[2])<<16) + (ord(c[3])<<24) ... value = l32(f.read(4)) <--- 3F 8C CC CD should be 1.11 Anybody an answer ? regards gf From aleaxit at yahoo.com Tue Jan 4 04:10:00 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Tue, 4 Jan 2005 10:10:00 +0100 Subject: Frameworks for "Non-Content Oriented Web Apps" References: <1104641466.776338.71700@z14g2000cwz.googlegroups.com> <1104672631.884144.294730@c13g2000cwb.googlegroups.com> <1104771690.845547.264630@z14g2000cwz.googlegroups.com> Message-ID: <1gpv02y.1bwcbv218q4i02N%aleaxit@yahoo.com> wrote: > Moreover, I recently saw Dabo(http://www.dabodev.com/about), a > framework for developing 3 tier apps with Python and wxPython(and other > supported GUI toolkits). I have not tried it but I think something > similar, but for web-apps, is a close definition of "A Framework for > Non-Content Oriented Web Apps". Once you're on a multilayer track, whether the presentation is on the web or on some other UI should just be an issue for the very last layer (closest to the user). That's definitely how we did things at AB Strakt (www.strakt.com). Of course, the web-based presentation layer will be generally simpler/poorer than ones based on richer GUI toolkits -- as a compensation, it may more easily be "skinnable" by using CSS and the like, and it's way more easily _testable_ thanks to many good packages for webpage-generators testing. Alex From jeffrey at cunningham.net Fri Jan 21 21:30:22 2005 From: jeffrey at cunningham.net (Jeffrey Cunningham) Date: Fri, 21 Jan 2005 18:30:22 -0800 Subject: how to write a tutorial References: <1106305730.361540.21010@f14g2000cwb.googlegroups.com> Message-ID: On Fri, 21 Jan 2005 03:08:50 -0800, Xah Lee wrote: > i've started to read python tutorial recently. > http://python.org/doc/2.3.4/tut/tut.html > (snip rest of misleading filler) > > http://xahlee.org/PageTwo_dir/more.html The first line is solipsistic (..like..'so what?'). But I think its all misleading. The real purpose of his cross-post is to get people to visit his website, ooh-and-ahh at his unique and daring Bush-bashing at the top, and finally admire (along with Xah himself) the pictures he takes of himself. Vanity, vanity, all is vanity... The only remaining question is 'why does he restrict his cross-posting to this particular collection of groups?' I don't have an answer to that one. [incidentally, I'm still cracking up over k.t. and the soldier...] --Jeff From tonino.greco at gmail.com Thu Jan 27 03:16:21 2005 From: tonino.greco at gmail.com (Tonino) Date: 27 Jan 2005 00:16:21 -0800 Subject: tkinter socket client ? In-Reply-To: References: <1106288752.561833.46510@z14g2000cwz.googlegroups.com> <11h1v0lnsoh9l46vmt26umn5kafdk5n7u8@4ax.com> <1106307973.536723.297940@z14g2000cwz.googlegroups.com> <35cae5F4jvrirU1@individual.net> <1106311130.446259.30710@f14g2000cwb.googlegroups.com> <1106318469.311179.126140@c13g2000cwb.googlegroups.com> <1106319270.932204.180590@c13g2000cwb.googlegroups.com> <1106659122.977876.234250@z14g2000cwz.googlegroups.com> Message-ID: <1106813781.056257.245180@f14g2000cwb.googlegroups.com> great - thanks ;) Tonino From lbates at syscononline.com Wed Jan 12 12:39:31 2005 From: lbates at syscononline.com (Larry Bates) Date: Wed, 12 Jan 2005 11:39:31 -0600 Subject: ConfigParser - add a stop sentinel? In-Reply-To: References: Message-ID: You should probably consider NOT doing what you suggest. You would need to do some rather extensive work so you can support the .write method of ConfigParser. With a little ingenuity I've been able to user ConfigParser to support some very different and complex syntaxes on different projects. If this won't work, just have two different (separate) files. If you are dead set on combining these two, put your foreign syntax lines into the file as comments. ConfigParser will not process them, and you can have some other class extract only the comments and parse them independently. Regards, Larry Bates rzed wrote: > I am working with PythonCard in one of my apps. For its purposes, it > uses an .ini file that is passed to ConfigParser. For my app, I also > need configuration information, but for various reasons, I'd rather > use a syntax that ConfigParser can't handle. > > I know I can maintain two separate configuration files, and if I have > to I will, but I'd rather avoid that, if possible, and a solution > that suits my purposes is quite straightforward. I insert a sentinel > in the ini file and modify my local ConfigParser's _read method to > stop accepting input when it encounters that value. I handle my app's > portion of the configuration myself. > > This all works fine, but I was wondering whether it might be > worthwhile to add a standard stop flag in ConfigParser itself. Am I > the only one with this sort of use case? If there were a standard way > of doing this, I'd much rather use that, particularly if I ever have > reason to distribute the app elsewhere. From craig at postnewspapers.com.au Mon Jan 3 15:45:36 2005 From: craig at postnewspapers.com.au (Craig Ringer) Date: Tue, 04 Jan 2005 04:45:36 +0800 Subject: Bad Interpreter In-Reply-To: <1104783849.754892.47560@c13g2000cwb.googlegroups.com> References: <1104783849.754892.47560@c13g2000cwb.googlegroups.com> Message-ID: <1104785136.4535.12.camel@albert.localnet> On Mon, 2005-01-03 at 12:24 -0800, RajaSrinivasan at hotmail.com wrote: > I have seen some previous messages about such a problem. I have this > problem but it is not clear what the solution really was. > > I am running FC2, python 2.3.3 > > the script i have sock.py runs if i say something like : > > python sock.py > > but ./sock.py results in a :bad interpreter error > how do i troubleshoot something like this? You probably have Windows-style line endings in the file. The kernel sees the ^M at the end of the line and gets all confused. -- Craig Ringer From google_groups_001 at yahoo.com Tue Jan 25 10:03:33 2005 From: google_groups_001 at yahoo.com (google_groups_001 at yahoo.com) Date: 25 Jan 2005 07:03:33 -0800 Subject: *IMPORTANT* Message for Google Group users! Message-ID: <1106665413.546265.22710@z14g2000cwz.googlegroups.com> Good News! Do you know how simple it is to go to Heaven after this life has ended? Some people believe that belonging to a local church, temple, mosque or synagogue will get them to Heaven. Others believe that water baptism, obeying the ten commandments or just being a good person will get them to Heaven. There are many other beliefs as well, but the good news about God's way to Heaven is found in the Holy Bible. The good news is that God came from Heaven to earth in the person of Jesus Christ over 2000 years ago and died for our sins(misdeeds). He was born in the land of Israel supernaturally to a virgin Jewish woman named Mary. He lived a sinless life for thirty-three years and then sacrificed His sinless blood and died on a cross to pay the death penalty for our sins. After Jesus was placed in a tomb He rose from the dead three days later as He said He would. The Holy Bible also tells us that Jesus Christ ascended into Heaven and that all who accept Him as their Lord and Saviour will live forever with Him in Heaven where there is no more death, sorrow, sickness and pain. The Bible says, "For the wages of sin is death, but the gift of God is eternal life through Christ Jesus our Lord." (Romans 6:23) This verse in the Bible says, "For ALL HAVE SINNED, and come short of the glory of God." (Romans 3:23) This verse says, "But God demonstrates his own love for us in this: While we were still sinners, Christ died for us." (Romans 5:8) In this passage the Bible clearly explains how simple it is to be saved and on your way to Heaven, "For if you confess with your mouth, "Jesus is Lord," and believe in your heart that God raised him from the dead, you WILL BE SAVED." (Romans 10:9) You can be saved right now and on your way to Heaven if you will open your heart to Jesus and pray the following prayer out loud: Dear Jesus Christ, I want to be saved so that I can have a home in Heaven when this life is over. I agree with You that I am a sinner. I believe You love me and want to save me. I believe that You bled and died on the cross to pay the penalty for my sins. I believe that You rose from the dead. Please forgive my sins and come into my heart and be my Lord and Saviour. Thank You Lord Jesus Christ for forgiving me and saving me through Your merciful grace. Amen. You are now a Christian if you said the prayer and allowed God to save you. Welcome to the family of God. Salvation is not a reward but a gift. The Bible says it this way, "For it is by GRACE you have been SAVED, through FAITH and this not from yourselves, it is the GIFT of God." (Ephesians 2:8) Nothing in the world is more important than your eternal destiny. The Bible says, "In Him(Jesus) we have redemption through His blood, the forgiveness of sins..." (Ephesians 1:7) If you have not yet made a decision to be saved, please do so now before it is too late. The reason why it is so important to be saved now is because you do not know exactly when you will die. You may die prematurely in a traffic accident, terrorist attack or some other way before you get another chance to be saved. The Bible tells us that we will spend eternity in Heaven or a place of eternal torment called Hell. It would be terrible to die and go to Hell when all you have to do is accept Jesus Christ as your personal Lord and Saviour. Some people that have already made Jesus Christ their Lord and Saviour worry about losing their salvation. The Bible teaches Christians that we can never lose our salvation no matter what happens. The Bible says it this way, "My dear children, I write this to you so that you will not sin. But if anybody does sin, we have one who speaks to the Father in our defense Jesus Christ, the Righteous One." Yes my friend, Jesus Christ is able to save you and keep you saved. Please tell your family and friends, thanks! Have a great day! Internet Evangelist R.L. Grossi 1. http://www.biblegateway.com << Free Online Bible 2. http://www.free-hoster.com/goodnews << Passion of the Christ 3. http://www.carm.org/cults/cultlist.htm << Beware Of Cults 4. http://www.equip.org/free/DH198.htm << About Hell 5. http://www.powertochange.com/questions/qna2.html << Is Jesus God? From __peter__ at web.de Wed Jan 26 04:06:50 2005 From: __peter__ at web.de (Peter Otten) Date: Wed, 26 Jan 2005 10:06:50 +0100 Subject: need help on generator... (re) References: <63b5e209.0501241406.4fb5980b@posting.google.com> Message-ID: Joh wrote: >> def gen(iterable, start, end): >>it?=?iter(iterable) >>while?True: >>it,?a?=?tee(it) >>a?=?tuple(islice(a,?end-1)) >>for?sz?in?xrange(start,?len(a)+1): >>yield?a[:sz] >>it.next() >> >> if __name__ == "__main__": >>print?list(gen(range(1,?5),?2,?4)) > > please, this one looks interesting, could you explain a bit how it > works and why it "remain memory-efficient" ? If you have a generator of the form def gen1(iterable): for i in iterable: yield f(i) for i in iterable: yield g(i) and then use it for item in gen1(range(huge_number)): do_something_useful_with(item) it will only work when you feed it with something you can iterate over multiple times, e. g. a list, not a generator that reads data on every call of the next() method. That means you must store the data for (to keep it simple) the lifetime of gen1(). If you can modify the generator to def gen2(iterable): for i in iterable: yield f(i) yield g(i) for item in gen2(xrange(huge_number)): # switched from range() to xrange() do_something_useful_with(item) there is no such restriction to the iterable. All data can be read, processed and garbage-collected immediately. The gen() generator is a bit more complex in that it has to store a few adjacent items instead of only one and allows for an arbitrary number of functions (inlined as yield of an n-tuple) instead of always two functions, but the idea is the same. Peter From lbolognini at gmail.com Thu Jan 6 06:27:56 2005 From: lbolognini at gmail.com (lbolognini at gmail.com) Date: 6 Jan 2005 03:27:56 -0800 Subject: wxPython clipboard Message-ID: <1105010876.075011.261070@z14g2000cwz.googlegroups.com> Hi all, I'm thinking about coding a free version of this software: http://www.pitrinec.com/pkindex.htm I would use wxPython and wx.Clipboard class (hoping to be able to make it cross-platform) The software above detects macros you code in any Windows active window and replaces them with a text: something like you write "/ff" and he pastes "Feel free to call us back for whatever questions you might have". This kind of softwares are very usefull in a call-centre environment (where I'm currently working). The thing is I'm thinking about the best approach (in terms of CPU resources) to detect the macro. Not sure how keyloggers work but I suspect I could run a service that compares everything beign written in the active window with the macros I saved in the software configuration. Could you please give me some advice on the best approach to solve this problem? Thanks a lot, Lorenzo -- http://www.bolognini.net From usenet_spam at janc.invalid Fri Jan 7 19:26:33 2005 From: usenet_spam at janc.invalid (JanC) Date: Sat, 08 Jan 2005 00:26:33 GMT Subject: OT: spacing of code in Google Groups References: <1104516184.077462.283350@c13g2000cwb.googlegroups.com> <1104528447.005870.6530@z14g2000cwz.googlegroups.com> <41d5c606$0$26890$a1866201@visi.com> <5amdnbMsyqlhx0DcRVn-vw@powergate.ca> <41DD5C6B.2070708@holdenweb.com> Message-ID: Peter Hansen schreef: > Steve Holden wrote: > >> Or even used cut(1) from the command line. > > Or myybe not :-) > > Microsoft Windows XP [Version 5.1.2600] > (C) Copyright 1985-2001 Microsoft Corp. > > c:\>cut > 'cut' is not recognized as an internal or external command, > operable program or batch file. Microsoft Windows 2000 [versie 5.00.2195] (C) Copyright 1985-2000 Microsoft Corp. C:\>cut cut: u moet een lijst van bytes, tekens, of velden geven Probeer `cut --help' voor meer informatie. Seems to work just fine... :-P Have a look at: They have native win32 builds of many of the GNU commandline utilities... -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From bo at systemhouse.dk Tue Jan 25 22:01:27 2005 From: bo at systemhouse.dk (Bo Jacobsen) Date: Wed, 26 Jan 2005 04:01:27 +0100 Subject: Can't load bytecode with execfile ? Message-ID: I have a number of files compiled to bytecode using py_compile.compile(). The .pyc files can be invoked by python directly ($python file.pyc), but "loading" them by execfile just throws an exception ? Any suggestions Bo. From aut_gbarros at uolinc.com Wed Jan 5 11:37:36 2005 From: aut_gbarros at uolinc.com (Gabriel Cosentino de Barros) Date: Wed, 5 Jan 2005 14:37:36 -0200 Subject: How to make executable file ? Message-ID: <2814F26DA6908F41927A81C410C4991A02079C33@siamun.server.bl.corp.intranet> > Also, you can try with py2exe. It's very easy. > Catalin. > > You may want to try cx_freeze. I brief experience with both. may be helpful 1. I did a little program on python/TK. Some 100 lines or less 2. executed cx_freeze 3. executed py2exe In the end, i had a dir with the name of the script: 03/12/04 18:08 . 03/12/04 18:08 .. 03/12/04 18:07 28.672 bugger.12.exe 25/05/04 21:19 45.117 datetime.pyd 03/12/04 18:07 563.528 library.zip 09/11/04 15:41 964 palavras.txt (this is data, i put here) 25/05/04 21:17 974.909 python23.dll 03/12/04 18:07 tcl 31/03/04 21:34 569.344 tcl84.dll 31/03/04 21:41 1.011.200 tk84.dll 25/05/04 21:18 16.384 w9xpopen.exe 25/05/04 21:18 57.401 _sre.pyd 25/05/04 21:19 36.925 _tkinter.pyd 10 File(s) 3.304.444 bytes 3 Dir(s) 2.143.559.680 bytes free Despite the fact that it got extremely big (but i wasn't expecting less when i started) it got pretty clumsy for what i had in mind. I was hoping for something like a 10Mb-single-exe-file kinda of result :) I belive cx_freeze didn't did much because i had no small includes. just the huge ones like Tk. Gabriel -------------- next part -------------- An HTML attachment was scrubbed... URL: From cabrera at wrc.xerox.com Mon Jan 31 20:47:41 2005 From: cabrera at wrc.xerox.com (jose isaias cabrera) Date: Mon, 31 Jan 2005 20:47:41 -0500 Subject: Java Integer.ParseInt translation to python References: <008d01c507f4$451d9b30$2820790d@stso.xcdg.xerox.com> <797fe3d405013116284ecfab68@mail.gmail.com> Message-ID: <003801c50800$04dea710$d6b8850d@jicman> Yes, that's my problem. I don't want to go through the java stuff. :-) Thanks. ----- Original Message ----- From: "Bill Mill" To: "jose isaias cabrera" Cc: Sent: Monday, January 31, 2005 7:28 PM Subject: Re: Java Integer.ParseInt translation to python > Jose, > > On Mon, 31 Jan 2005 19:23:35 -0500, jose isaias cabrera > wrote: >> >> Greetings! >> >> I've looked through the internet (not long, though) but I have not been >> able >> to find a python translation to >> >> buffer[0] = (byte)Integer.parseInt(string,16); > > Tell me what this does, give me an example or two, and I'll translate > it for you. I don't feel like going to read the java docs to figure it > out. > > You probably want to look at the built-in int() function though. Type > help(int) at the python prompt. > > Peace > Bill Mill > bill.mill at gmail.com > -- > http://mail.python.org/mailman/listinfo/python-list > From stephen.thorne at gmail.com Wed Jan 5 18:52:15 2005 From: stephen.thorne at gmail.com (Stephen Thorne) Date: Thu, 6 Jan 2005 09:52:15 +1000 Subject: Decorators and static typing. In-Reply-To: <41DC7893.2090707@oz.net> References: <41DC7893.2090707@oz.net> Message-ID: <3e8ca5c805010515525cddb69e@mail.gmail.com> On Wed, 05 Jan 2005 15:30:27 -0800, whisper at oz.net wrote: > Well, the decorator war is over (Python lost IMO!) and now we've got the > static typing war to fight! > > Both of these seem like syntax sugar to avoid writing good code! One has > already introduced ugly coding and the 2nd is likely to do the same! IMHO, the syntax is irrelevent. The goal of making it a core language feature is to remove the necessity of people writing their own type checkers and interface implementations. Essentially at the moment we have a situation with zope.interfaces that is causing many python projects that are completely unrelated to Zope (for instance, twisted) to depend on zope.interfaces, because its the most standard way of doing interfaces in Python. No one is going to like the syntax, and if anyone actually does, they're not going to speak up. Guido knows this. Thats why he's the BDFL, he can just dictate what the syntax SHALL be, and avoid 150 post threads over if '@' is better than 'dec' for decorators. Sure, we can implement type checking without language changes, but in doing so, we kill the entire point. Something standard is desired. Why don't we make it a language feature so that we don't have to waste even more lines of code and brain-cycles with obscure things like: def f(n): assert type(n) in (int, float) or subscribesToDuckType("number") using handwritten APIs that differ between every project. Regards Stephen Thorne From ariza at flexatone.com Thu Jan 13 04:43:19 2005 From: ariza at flexatone.com (ariza) Date: 13 Jan 2005 01:43:19 -0800 Subject: site.here on python 2.4 Message-ID: <1105609399.915874.71150@z14g2000cwz.googlegroups.com> greetings. it seems that the attribute site.here, of the site module, has vanished in python 2.4. up until python 2.3, site.here seemed (to me at least) a convenient way to get the complete path to the python library on any platform: >>> import site >>> site.here '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3' i do not see any information about this change save that in the new documentation it says: """ This module is automatically imported during initialization. The automatic import can be suppressed using the interpreter's -S option. Importing this module will append site-specific paths to the module search path. """ can anyone propose a similarly effective and cross-platform solution for easily discovering the the library path on any python installation? From bjourne at gmail.com Fri Jan 7 20:23:32 2005 From: bjourne at gmail.com (=?ISO-8859-1?Q?BJ=F6rn_Lindqvist?=) Date: Sat, 8 Jan 2005 02:23:32 +0100 Subject: Securing a future for anonymous functions in Python In-Reply-To: <10tu91mhv8mn89d@corp.supernews.com> References: <1105098890.358721.279550@f14g2000cwb.googlegroups.com> <7xis6930ah.fsf@ruckus.brouhaha.com> <7xvfa90w6g.fsf@ruckus.brouhaha.com> <10tu91mhv8mn89d@corp.supernews.com> Message-ID: <740c3aec05010717232a784961@mail.gmail.com> The more features a language has, the harder it becomes to learn. An example of that is C++ which has almost everything. Classes, structs, templates, strange keywords that noone uses like auto, inline const, passing by reference/value, enum, union, lots of macros, multiple inheritance, namespaces etc. I'll bet that you could shave off 50% of C++'s features and it would still be 95% as usable[*]. Judging by the number of PEP proposals and syntax additions that appear on the mailing list every day Python could some day become as bloated. We don't want that, do we? So how do we avoid feature bloat?: 1. We stop adding features, either now or at some point in the future. 2. We remove some features. Either way we have to put a limit on the number of features we want Python to have. Let's call that number X where X is a number much smaller than infinity. With a set limit, the discussion becomes "which features should be selected for use in Python?" instead of "should this feature be added/removed?" Personally, I don't care either way if lambda is removed or retained, but I would much rather have the "with" keyword someone proposed, do-while loops or whatever. I think there are way too many good features out there just waiting to take lambdas place. * - Please don't ask me to make that bet. -- mvh Bj?rn From moma at example.net Fri Jan 28 15:41:05 2005 From: moma at example.net (moma) Date: Fri, 28 Jan 2005 21:41:05 +0100 Subject: Where can I find sample "beginner" programs to study? In-Reply-To: <_6CdnWIOB8AaA2fcRVn-rg@speakeasy.net> References: <_6CdnWIOB8AaA2fcRVn-rg@speakeasy.net> Message-ID: Todd_Calhoun wrote: > I'm trying to learn Python (and programming), and I'm wondering if there are > any places where I can find small, simple programs to study. > > Thanks. > Hello, http://www.python.org (docs -> tutorial) http://www.python.org/doc/ ! http://www.diveintopython.org http://www.byteofpython.info Eggs are here. Bring some bacon. http://www.python-eggs.org/links.html -------- Cross platform GUI-programs: http://www.wxPython.org Widgets documentation: http://www.wxPython.org -------- IDEs (programmers Python editors, if you want one): Eric http://www.die-offenbachs.de/detlev/eric3.html Dr.Python http://drpython.sourceforge.net/ ? // moma http://www.futuredesktop.org/OpenOffice.html http://www.futuredesktop.org/hpc_linux.html From pierre.barbier at cirad.fr Tue Jan 18 02:30:33 2005 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Tue, 18 Jan 2005 08:30:33 +0100 Subject: extension module, thread safety? In-Reply-To: References: Message-ID: <41ecbaae$0$1046$626a14ce@news.free.fr> David Bolen a ?crit : > > If the threads under discussion are all Python threads, then by > default yes, the extension module C functions will appear to be atomic > from the perspective of the Python code. When the Python code calls > into the extension module, the GIL (global interpreter lock) is still > being held. Unless the extension module code explicitly releases the > GIL, no other Python threads can execute (even though those threads > are in fact implemented as native platform threads). Indeed, there is this (so annoying) GIL ... is there any project about extracting the (few ?) critical points of the python interpreter to put locks around them instead of choosing the opposite strategy (ie. locking anythime but when we know the section is not critical) ? Because it would made embedding a python interpreter in another language much more easy ! With the current CPython, it's very hard to mix Python and C in a multithreading application (with C-threads, not Python-threads). In fact I never really succeeded in that task because of that GIL ! I have a multi-thread application but every bit of Python code must be run into a Python thread. To be more precise, I wanted to be able to call Python code in response to some GUI events, and I didn't want to instanciate a new interpreter for I wanted to be able to access the environment of my main Python interpreter. By the way, if someone succeeded in a similar task, I'll be happy to hear about it :) Pierre PS: if the main code is in C (in fact C++ ...) and not Python it's for historical reasons of course ;) From peter at engcorp.com Thu Jan 6 10:59:07 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 06 Jan 2005 10:59:07 -0500 Subject: OT: spacing of code in Google Groups In-Reply-To: <41DD5C6B.2070708@holdenweb.com> References: <1104516184.077462.283350@c13g2000cwb.googlegroups.com> <1104528447.005870.6530@z14g2000cwz.googlegroups.com> <41d5c606$0$26890$a1866201@visi.com> <5amdnbMsyqlhx0DcRVn-vw@powergate.ca> <41DD5C6B.2070708@holdenweb.com> Message-ID: Steve Holden wrote: > Peter Hansen wrote: >> But the whole argument is fairly moot... I've needed a rectangle >> operation only once in the last ten years, and if I hadn't known at >> the time that my editor could do it (and spent about half an hour >> figuring out how it worked), I could have written a utility to >> do the job faster if I'd been using Python at the time... > > Or even used cut(1) from the command line. Or myybe not :-) Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. c:\>cut 'cut' is not recognized as an internal or external command, operable program or batch file. -Peter From hcslmf at texlife.com Mon Jan 10 14:56:44 2005 From: hcslmf at texlife.com (brolewis) Date: 10 Jan 2005 11:56:44 -0800 Subject: Importing Problem on Windows In-Reply-To: <1105382542.552797.125200@c13g2000cwb.googlegroups.com> References: <1105379352.302141.264580@f14g2000cwb.googlegroups.com> <1105382542.552797.125200@c13g2000cwb.googlegroups.com> Message-ID: <1105387004.434581.194560@c13g2000cwb.googlegroups.com> Sorry. 2.4 in both locations From steve at holdenweb.com Fri Jan 14 16:51:44 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 14 Jan 2005 16:51:44 -0500 Subject: why are people still using classic classes? In-Reply-To: References: <7x6522gegg.fsf@ruckus.brouhaha.com> Message-ID: <41E83EF0.2020402@holdenweb.com> Peter Hansen wrote: > Paul Rubin wrote: > >> Simon Wittber writes: >> >>>> Is there a reason NOT to use them? If a classic class works fine, what >>>> incentive is there to switch to new style classes? >>> >>> >>> Perhaps classic classes will eventually disappear? >> >> >> It just means that the formerly "classic" syntax will define a >> new-style class. Try to write code that works either way. > > > Unfortunately, if we should follow the recent advice about > always using "super()" in the __init__ method, it's hard > to do what you suggest (though it sounds like good advice) > without resorting to extreme ugliness: > > >>> class Classic: > .... def __init__(self): > .... super(Classic, self).__init__() > .... > >>> c = Classic() > Traceback (most recent call last): > File "", line 1, in ? > File "", line 3, in __init__ > TypeError: super() argument 1 must be type, not classobj > > Could classic classes ever be removed without us having manually > to fix all __init__ calls to the superclass? > That's not really an issue unless there's a diamond-shaped inheritance graph and linearisation of the the super classes is required to ensure that things stay sane. Remembering that the MO for classic classes and types are rather different, how many cases do you think it will matter? regards Steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 From peter at engcorp.com Thu Jan 13 13:30:00 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 13 Jan 2005 13:30:00 -0500 Subject: [perl-python] 20050112 while statement In-Reply-To: References: <1105611506.106440.135670@f14g2000cwb.googlegroups.com> Message-ID: <-oSdnYnagrc_I3vcRVn-3Q@powergate.ca> Steven Bethard wrote: > Xah Lee wrote: [some Python code] > Because you're posting this to newsgroups, it would be advisable to use > only spaces for indentation -- tabs are removed by a lot of newsreaders, > which means your Python readers are going to complain about > IndentationErrors. Unfortunately, there are now two ways to post screwed up Python code, and using tabs is only one of them. The other is to post from Google Groups, and that's what Xah Lee is doing. (The rest of your advice, about going away, is pretty good though. ;-) -Peter From fredrik at pythonware.com Fri Jan 28 04:32:57 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 28 Jan 2005 10:32:57 +0100 Subject: unicode and data strings References: <41FA03C1.50404@geochemsource.com> Message-ID: Laszlo Zsolt Nagy wrote: > Now I installed Python 2.3.4 and wxPython 2.5.3 (with unicode support). I'm getting this > exception: > > exceptions.UnicodeDecodeError:'ascii' codec can't decode byte 0x91 in position 0: ordinal not in > range(128) >From where? Can you include a "print repr()" of the string you're trying to convert, and enough code from your script to be able to reproduce the problem? > The I tried this: > > >>>'\x91'.decode('utf8') > UnicodeDecodeError: 'utf8' codec can't decode byte 0x91 in position 0: unexpected code byte > >>>'\x91'.encode('utf8') > > Here is the question: I would like to use simple binary data strings (like an array of bytes). > I do not care about encodings. How do I do that? Unicode errors only appear if you're converting between "raw 8-bit data" and Unicode strings (which contain Unicode characters, not bytes or integers). You cannot do that without caring about encodings... From paolo_veronelli at yahoo.it Tue Jan 4 04:07:32 2005 From: paolo_veronelli at yahoo.it (paolo_veronelli) Date: Tue, 04 Jan 2005 09:07:32 +0000 Subject: Frameworks for "Non-Content Oriented Web Apps" In-Reply-To: <1104641466.776338.71700@z14g2000cwz.googlegroups.com> References: <1104641466.776338.71700@z14g2000cwz.googlegroups.com> Message-ID: <41DA5CD4.8060900@yahoo.it> mirnazim at gmail.com wrote: >Hi, > >There are great Python Web Application Framework. But most of them are >meant for content oriented web apps. > >Is there something that can ease the development of application that >are not content oriented(I call them "NON CONTENT-ORIENTED WEB >APPLICATIONS" because I don't know what else to call them). I mean the >applications like, accounting, high volume data entry apps, where >normally GUI clients have ruled. I know very high quality ERP and >similar packages have been implemented in a web based environment. But >problem is that they have been developed with the tools that were >actually meant for content oriented apps like Zope, PHP, etc. > >But is there some sort of framework or something that is actually meant >for such web apps,application that make heavy use of forms, have very >high amount of user interaction etc. > >What I am asking here may sound off beat, but I think, in todays world >where web based solutions offers such a flexibility, we really need it. > >I also know that I am to ambiguous, but as is the characteristic of >this wonderful community, talks that start as most abigous, transform >in crystal clear. > >PS: I am a web developer, using PHP for living. I have been playing >with python for a while. I found python is really a cool language(do I >need to say that ;-)) with a really, really impressive collection of >modules and frameworks. While developing a school information system, I >felt the need of such a framework that makes developing of "Non-Content >Oriented Web-Apps" easy. > >I know I posted a similar message earlier, but this time I a bit more >general. > > > In pytypus everything is not content is metadata( a part from some of the code ,which part is useful for accessing informations) ,so my definition will simply be metadata oriented. From snail at objmedia.demon.co.uk Tue Jan 25 10:46:30 2005 From: snail at objmedia.demon.co.uk (Stephen Kellett) Date: Tue, 25 Jan 2005 15:46:30 +0000 Subject: is there better 32 clock() timing? References: <41f61372.1768192005@news.oz.net> <41f63d79.1778950866@news.oz.net> Message-ID: In message <41f63d79.1778950866 at news.oz.net>, Bengt Richter writes >I believe that is quite wrong as a general statement. Actually my initial statement should have been written "accessing a resource, the accuracy of which is no better than 10ms.". I was thinking of the 1ms multimedia timer but wrote about clock() instead. 10ms, coincidentally is the approx minimum scheduling granularity for threads unless you are in a multimedia thread (or real time thread - not sure about real time threads in NT). >If the "resource" only had ~1ms granularity, >the minimum would be zero, as it is if you call time.time() in a tight loop, Correct. Write your app in C and call clock(). Thats what you get. You can call clock 20000 times and still get a delta of zero. The next delta (on my system) is 10ms at about 22000 calls. >>There are various timers available, documented and undocumented, all of >>which end up at 1ms or 1.1ms, give or take. For anything shorter you Whoops here we go, same typo - should have been 10ms or 11ms. There is a 1ms timer in the multimedia timing group. >>need QueryPerformanceCounter() (but that *is* a slow call), or use the >Have you timed it, to make that claim? Yes. >What do you mean by "slow"? Slower than any other Win32, CRT or Undocumented NT function you can use to get timer information. Yes, I have timed them all, a few years ago. QueryPerformanceCounter is 47 times slower to call than clock() on my 1Ghz Athlon. QueryPerformanceCounter may have finer granularity, but called in a tight loop it'll crush your program. >>RDTSC instruction which is fast but gives a count of instruction cycles >>executed and is thus not totally accurate (multiple execution pipelines, >>plus multithreading considerations). >Accurate for what. See below - you haven't taken things into account, despite my comment in brackets above which gives a big hint. >A single clock AFAIK drives RDTSC Correct. >The main problem with a CPU clock based reading is that it's very stable unless >there's variable clock rate due to power management. Try running multiple apps at the same time you are doing your measurement, each of which has a variable loading. Each of these apps is contributing to the count returned by RDTSC. That is what I was referring to. Stephen -- Stephen Kellett Object Media Limited http://www.objmedia.demon.co.uk RSI Information: http://www.objmedia.demon.co.uk/rsi.html From http Fri Jan 7 16:49:44 2005 From: http (Paul Rubin) Date: 07 Jan 2005 13:49:44 -0800 Subject: how to extract columns like awk $1 $5 References: Message-ID: <7xzmzk3o5j.fsf@ruckus.brouhaha.com> roy at panix.com (Roy Smith) writes: > Something along the lines of: > > words = input.split() > print words[4], words[5] That throws an exception if there are fewer than 6 fields, which might or might not be what you want. From rschroev_nospam_ml at fastmail.fm Fri Jan 14 11:40:29 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Fri, 14 Jan 2005 16:40:29 GMT Subject: python and macros (again) [Was: python3: 'where' keyword] In-Reply-To: References: <1105437966.129342.304400@f14g2000cwb.googlegroups.com> <7xmzvfn096.fsf@ruckus.brouhaha.com> Message-ID: <1CSFd.30772$Qv5.2842746@phobos.telenet-ops.be> Antoon Pardon wrote: > IMO we have a: dogs are mamals kind of relationship in Python. I see what you mean, but I don't think it's true. > Every expression can be used where a statement is expected. > (And this can be worded as: every expression is a statement.) Not really. An expression statement is a statement that looks like an expression, but actually it's more than that: not only does it calculate the value of the expression, it also prints the value. Note that it would be perfectly possible to modify the syntax into expression_stmt ::= "exprstmt" expression_list so that you would have to write exprstmt 6*9 instead of just 6*9 That makes it clearer to see the distinction: 6*9 is an expression, exprstmt 6*9 is a statement. An expression statement, more precisely. > Not every statement can be used where an expression is expected. AFAIK *no* statement can be used where an expression is expected. -- "Codito ergo sum" Roel Schroeven From air_jlin at yahoo.com Thu Jan 20 22:24:43 2005 From: air_jlin at yahoo.com (Johnny Lin) Date: 20 Jan 2005 19:24:43 -0800 Subject: Unbinding multiple variables Message-ID: <1106277883.620769.255830@z14g2000cwz.googlegroups.com> Hi! Is there a way to automate the unbinding of multiple variables? Say I have a list of the names of all variables in the current scope via dir(). Is there a command using del or something like that that will iterate the list and unbind each of the variables? Thanks much! (If anyone posts an answer, if you could also cc your reply to my email air_jlin at yahoo.com, would be much obliged. Thanks again!) Best, -Johnny www.johnny-lin.com From grante at visi.com Mon Jan 31 23:29:13 2005 From: grante at visi.com (Grant Edwards) Date: 01 Feb 2005 04:29:13 GMT Subject: need for binary floats (except performance)? References: <81300027.0501312006.72454fd6@posting.google.com> Message-ID: <41ff0599$0$10746$a1866201@visi.com> On 2005-02-01, kartik wrote: > Since the Decimal type can represent any given fractional number > exactly, including all IEEE binary floating-point numbers, wouldn't it > be advisable to use Decimals for all floating point numbers (except > possibly for performance)? That's a pretty huge "except" for some applications. -- Grant Edwards grante Yow! HUGH BEAUMONT died at in 1982!! visi.com From rnd at onego.ru Wed Jan 19 15:45:15 2005 From: rnd at onego.ru (Roman Suzi) Date: Wed, 19 Jan 2005 23:45:15 +0300 (MSK) Subject: RuntimeError: dictionary changed size during iteration Message-ID: I think, the behaviour below is misfeature: >>> [e for e in vars()] Traceback (most recent call last): File "", line 1, in ? RuntimeError: dictionary changed size during iteration >>> e = None >>> [e for e in vars()] ['e', '__builtins__', 'rlcompleter', '__file__', '_[1]', 'atexit', '__name__', 'readline', '__doc__'] Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3 From peter at engcorp.com Thu Jan 13 10:28:05 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 13 Jan 2005 10:28:05 -0500 Subject: How to install pyparallel In-Reply-To: <41e689fc$0$15700$626a14ce@news.free.fr> References: <41e689fc$0$15700$626a14ce@news.free.fr> Message-ID: Michel LE VAN KIEM wrote: > > I'm trying to install the pyparallel module for my Python 2.3.4 (runs on > a FC3) but I do have some troubles. > > >>> p=parallel.Parallel() > ppdev0: failed to register device ! > ... > IOError: [No such device or address] > > Some help would be appreciated. Did you read the notes in the parallelppydev.py file's Parallel class? I suspect they may be of some help... (I don't see any other significant documentation of pyParallel, so I'm not sure where else one would look for assistance.) Also, perhaps one of these threads would be of help: http://groups.google.ca/groups?q=parallel+ppdev0+failed+to+register+device -Peter From unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom Sun Jan 16 13:19:39 2005 From: unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom (Do Re Mi chel La Si Do) Date: Sun, 16 Jan 2005 19:19:39 +0100 Subject: Scriptomatic 2.0 Message-ID: <41eab05f$0$25799$8fcfb975@news.wanadoo.fr> Hi ! Scriptomatic 2.0 can, now, to generate scripts in Python. Download : http://www.microsoft.com/downloads/thankyou.aspx?FamilyID=09dfc342-648b-4119-b7eb-783b0f7d1178&displaylang=en Note : scriptomatic is a generator of WMI's scripts, for Windows, (and compatibles WBEM). Good night -- Michel Claveau From craig at postnewspapers.com.au Sat Jan 15 18:51:02 2005 From: craig at postnewspapers.com.au (Craig Ringer) Date: Sun, 16 Jan 2005 07:51:02 +0800 Subject: [Fwd: Re: Embedding Multiplr Python interpreter in C++] In-Reply-To: <41E7DA3B.9000005@holdenweb.com> References: <41E7DA3B.9000005@holdenweb.com> Message-ID: <1105833061.2858.1.camel@rasputin.localnet> On Fri, 2005-01-14 at 22:42, Steve Holden wrote: > Take a look at mod_python's code: that allows several independent > interpreters in the same Apache process using Py_NewInterpreter() I've never been entirely clear on whether mod_python does its magic by relying on having one thread per sub-interpreter, or if it can support multiple sub interpreters in a single thread. Any ideas? I'm pretty sure it's the former, but it'd be nice to be sure. -- Craig Ringer From robin at SPAMREMOVEjessikat.fsnet.co.uk Thu Jan 20 03:59:10 2005 From: robin at SPAMREMOVEjessikat.fsnet.co.uk (Robin Becker) Date: Thu, 20 Jan 2005 08:59:10 +0000 Subject: rotor replacement In-Reply-To: References: <7x1xcidnp1.fsf@ruckus.brouhaha.com> <41EE24F7.7030303@jessikat.fsnet.co.uk> <41EEF691.20706@jessikat.fsnet.co.uk> <7xacr4ewjk.fsf@ruckus.brouhaha.com> <41ef4a7a.1323588509@news.oz.net> <7xwtu8vb17.fsf@ruckus.brouhaha.com> Message-ID: <41EF72DE.5030305@jessikat.fsnet.co.uk> Peter Maas wrote: > Paul Rubin schrieb: > >>> Wasn't there a default 40-bit version that was ok (weak), but you had >>> to declare yourself US resident to download 128-bit support? >> >> >> >> That was years ago. The regulations changed since then, so they all >> have 128 bits now. > > > Perhaps the NSA has found a way to handle 128bit in the meantime. > But this is unlikely because there is no export regulation to ban > 512bit as far as I know :) > Apparently factorization based crypto is on the way out anyhow (as an article in Scientific American is reported to claim). http://www.sciam.com/article.cfm?chanID=sa006&articleID=000479CD-F58C-11BE-AD0683414B7F0000&ref=rdf -can't wait to get my quantum computer-ly yrs- Robin Becker From macrocosm at fastmail.fm Wed Jan 5 08:54:23 2005 From: macrocosm at fastmail.fm (Arich Chanachai) Date: Wed, 05 Jan 2005 08:54:23 -0500 Subject: project In-Reply-To: <20050104201100.73284.qmail@web80902.mail.scd.yahoo.com> References: <20050104201100.73284.qmail@web80902.mail.scd.yahoo.com> Message-ID: <41DBF18F.6040703@fastmail.fm> jerry wise wrote: >Please help me out! Your solution seems doable pretty easily, but I have very little experience in this so I need some help. At the very least respond, because I'm getting kind of desperate. Thank you so much. > > > "I'm getting kind of desperate", no kidding. Firstly, did you ask Jeff to help you understand the algorithm? Secondly, did you read up on the PyMedia docs? Thirdly, what do you have very little experience in exactly and why are you so desperate? Is this some sort of school project? You need to be able to answer yes to the first two questions if you want my and/or likely anyone else's help. I am very busy, but if you take the necessary preliminary steps, and do the work, there are many /very/ friendly and knowledgeable people here who would likely be willing to help you, given that you are willing to do some work/research yourself and ask good questions. Best regards, Arich From Rolf.Wester at t-online.de Sun Jan 2 11:52:52 2005 From: Rolf.Wester at t-online.de (Rolf Wester) Date: Sun, 02 Jan 2005 17:52:52 +0100 Subject: run region in IDLE Message-ID: <41D826E4.3020500@t-online.de> Hi, I would like to send a marked region of an IDLE editing window to the IDLE shell for evaluating, so that I can develop software incrementally. I know that I could type directly into the shell window (or copy and paste between an editing window and the shellwindow) but I'm looking for a way of doing it like it's possible with Emacs and Python. Is there any way of doing this? Regards Rolf Wester From tim at zeos.net Mon Jan 17 03:21:23 2005 From: tim at zeos.net (Timothy Babytch) Date: Mon, 17 Jan 2005 10:21:23 +0200 Subject: how to print unicode structures? Message-ID: Imagine you have some list that looks like ('unicode', 'not-acii', 'russian') and contains characters not from acsii. or list of dicts, or dict of dicts. how can I print it? not on by one, with "for" - but with just a simple print? My debugging would be MUCH simpler. Now when I try print or pprint that variable I get a page full of '\xe4\xeb\xa2\xa0\xe6\xe3\xaa\xe6\xe3\xaa' and so on. I use Python 2.4, Fedora Linux, UTF-8 locale From jgrahn-nntq at algonet.se Wed Jan 12 16:41:07 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 12 Jan 2005 21:41:07 GMT Subject: pulling info from website References: <41e2a556$0$14576$ed2619ec@ptn-nntp-reader01.plus.net> Message-ID: On 10 Jan 2005 16:06:33 GMT, Duncan Booth wrote: > bob wrote: > >> i am trying to write a script for Xbox media center that will pull >> information from the bbc news website and display the headlines , how >> do i pull this info into a list??? > > Google for "Python RSS reader" and read some of the results. And for the general (and fundamentally broken) approach, google for "web scraping". /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From sjmachin at lexicon.net Fri Jan 21 15:40:47 2005 From: sjmachin at lexicon.net (John Machin) Date: 21 Jan 2005 12:40:47 -0800 Subject: Simple (newbie) regular expression question References: <972ec5bd050119111359e358f5@mail.gmail.com> <797fe3d405011911465ab59acd@mail.gmail.com> <1106177050.630141.33090@c13g2000cwb.googlegroups.com> <972ec5bd0501191641166972b0@mail.gmail.com> <7xis5szpdj.fsf@ruckus.brouhaha.com> <7xekggbrns.fsf@ruckus.brouhaha.com> <7x651rwbib.fsf@ruckus.brouhaha.com> Message-ID: <1106340047.788392.74130@f14g2000cwb.googlegroups.com> Andr? Roberge wrote: > Sorry for the simple question, but I find regular > expressions rather intimidating. And I've never > needed them before ... > > How would I go about to 'define' a regular expression that > would identify strings like > __alphanumerical__ as in __init__ > (Just to spell things out, as I have seen underscores disappear > from messages before, that's 2 underscores immediately > followed by an alphanumerical string immediately followed > by 2 underscore; in other words, a python 'private' method). > > Simple one-liner would be good. > One-liner with explanation would be better. > > One-liner with explanation, and pointer to 'great tutorial' > (for future reference) would probably be ideal. > (I know, google is my friend for that last part. :-) > > Andre Firstly, some corrections: (1) google is your friend for _all_ parts of your question (2) Python has an initial P and doesn't have private methods. Read this: >>> pat1 = r'__[A-Za-z0-9_]*__' >>> pat2 = r'__\w*__' >>> import re >>> tests = ['x', '__', '____', '_____', '__!__', '__a__', '__Z__', '__8__', '__xyzzy__', '__plugh'] >>> [x for x in tests if re.search(pat1, x)] ['____', '_____', '__a__', '__Z__', '__8__', '__xyzzy__'] >>> [x for x in tests if re.search(pat2, x)] ['____', '_____', '__a__', '__Z__', '__8__', '__xyzzy__'] >>> I've interpreted your question as meaning "valid Python identifier that starts and ends with two [implicitly, or more] underscores". In the two alternative patterns, the part in the middle says "zero or more instances of a character that can appear in the middle of a Python identifier". The first pattern spells this out as "capital letters, small letters, digits, and underscore". The second pattern uses the \w shorthand to give the same effect. You should be able to follow that from the Python documentation. Now, read this: http://www.amk.ca/python/howto/regex/ HTH, John From invalidemail at aerojockey.com Wed Jan 12 13:53:29 2005 From: invalidemail at aerojockey.com (Carl Banks) Date: 12 Jan 2005 10:53:29 -0800 Subject: complex numbers In-Reply-To: References: <1105259798.863970.314750@c13g2000cwb.googlegroups.com> Message-ID: <1105556009.063965.145210@z14g2000cwz.googlegroups.com> It's me wrote: > The world would come to a halt if all of a sudden nobody understands complex > numbers anymore. :-) Actually, it would oscillate out of control. -- CARL BANKS From hans at zephyrfalcon.org Fri Jan 21 14:21:20 2005 From: hans at zephyrfalcon.org (Hans Nowak) Date: Fri, 21 Jan 2005 14:21:20 -0500 Subject: Funny Python error messages In-Reply-To: <1106315907.551660.276380@c13g2000cwb.googlegroups.com> References: <1106315907.551660.276380@c13g2000cwb.googlegroups.com> Message-ID: Will Stuyvesant wrote: > Add your funny or surprising Python error messages to this > thread. A requirement is that you should also show > (minimal) code that produces the message. Put the code > below, so people can think about how to generate the message > first, a little puzzle if you like. > > Perhaps this will even be a useful thread, to brighten the > life of the brave people doing the hard work of providing us > with error messages. I always liked: ValueError: insecure string pickle This error message is not strange if you think of "insecure", "string" and "pickle" as programming terms, but it's hugely mystifying to someone who isn't a programmer, since all of these words have different meanings in real life. Some code to produce it: >>> import cPickle >>> x = cPickle.dumps([1,2,3,"ratsj"]) >>> y = x[:18] + "?" + x[18:] >>> cPickle.loads(y) Traceback (most recent call last): File "", line 1, in ? ValueError: insecure string pickle -- Hans Nowak http://zephyrfalcon.org/ From steve at holdenweb.com Fri Jan 21 01:43:13 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 21 Jan 2005 01:43:13 -0500 Subject: Does anyone want one? In-Reply-To: <20050120232749.14147.00000205@mb-m10.aol.com> References: <20050120232749.14147.00000205@mb-m10.aol.com> Message-ID: Drummmachine wrote: > http://www.freeiPods.com/?r=14249501 > > just go here to get started. It's very easy and very real. This is no scam. > Complete an offer, get 5 others to do the same and you'll receive a free Ipod > of your choice. > thanks for your time. Free ipods are real. > > As are pyramid scams. -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 From maxm at mxm.dk Tue Jan 4 13:43:53 2005 From: maxm at mxm.dk (Max M) Date: Tue, 04 Jan 2005 19:43:53 +0100 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 30) In-Reply-To: References: <1gpoaq3.1trkc8e1bxl9h4N%aleaxit@yahoo.com> <1104846212.355098.186400@c13g2000cwb.googlegroups.com> <1104849206.111461.70500@c13g2000cwb.googlegroups.com> Message-ID: <41dae3c3$0$228$edfadb0f@dread12.news.tele.dk> Thomas Heller wrote: > It seems also the error messages aren't too helpful: > >>>>"?".encode("latin-1") > > Traceback (most recent call last): > File "", line 1, in ? > UnicodeDecodeError: 'ascii' codec can't decode byte 0x84 in position 0: ordinal not in range(128) > > Hm, why does the 'encode' call complain about decoding? Because it tries to print it out to your console and fail. While writing to the console it tries to convert to ascii. Beside, you should write: u"?".encode("latin-1") to get a latin-1 encoded string. -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science From usenet at horvath.com Tue Jan 4 01:42:46 2005 From: usenet at horvath.com (Bob Horvath) Date: Tue, 04 Jan 2005 00:42:46 -0600 Subject: Zope newsgroups? Need help with POSKeyError In-Reply-To: References: <41d5e51d$0$4095$afc38c87@news.optusnet.com.au> Message-ID: Dan Stromberg wrote: > On Sat, 01 Jan 2005 10:47:41 +1100, richard wrote: > > >>Bob Horvath wrote: >> >>>I have a Zope/Plone combination that I have been having POSKeyErrors >>>with for a while now. Are there any newsgroups that deal with Zope? >> >>No, but there is a mailing list - see zope.org >> >>Also, try google searching for POSKeyError. >> >> >> Richard > > > You could also see if the zeop mailing list is gatewayed to nntp on gmane. > They have a huge number of FLOSS development mailing lists on that nntp > server. Google should be able to find it easily. Hey thanks. That gmane tip will come in handy for many things! From anand at esi-india.com Thu Jan 6 05:34:16 2005 From: anand at esi-india.com (Anand K Rayudu) Date: Thu, 06 Jan 2005 16:04:16 +0530 Subject: Python C Object Comparison Message-ID: <41DD1428.1030503@esi-india.com> Dear All, I have some question regarding embedding and exposing of C pointers. We have embedded python and extended to expose our APIs and c objects to python. Every thing is working fine as far as customizing our application through python. How ever i am expecting following behavior but it failed. Can some oe suggest a work around!! Here is my python code import myModule a=myModule.myAPI1("1") b=myModule.myAPI2("name") # basically both above functions return same C pointer. # so i want to compare if(a==b): print "They are same" else : print "They are different" python always prints they are different, I guess this is because in python layer we create PythonCObject for every C pointer, and that is how it is exposed to python. Though both the APIs are returning the same C pointer, they are different instances of PythonCObject. So i guess that is the reason comparison is failing. How ever is it possible to make python to compare actual C pointer, rather than the PythonCObject Pointer. Can some one please suggest Regards, Anand From skip at pobox.com Mon Jan 17 12:10:35 2005 From: skip at pobox.com (Skip Montanaro) Date: Mon, 17 Jan 2005 11:10:35 -0600 Subject: strange note in fcntl docs In-Reply-To: <16875.54085.712019.524951@montanaro.dyndns.org> References: <20050117053949.GA28456@grulic.org.ar> <16875.54085.712019.524951@montanaro.dyndns.org> Message-ID: <16875.61835.168746.328412@montanaro.dyndns.org> Skip> I could have sworn that os.open supported the O_SHLOCK and Skip> O_EXLOCK flags. I submitted a patch to posixmodule.c for these: http://python.org/sf/1103951 Skip From peter at somewhere.com Thu Jan 27 04:16:43 2005 From: peter at somewhere.com (Peter Maas) Date: Thu, 27 Jan 2005 10:16:43 +0100 Subject: python without OO In-Reply-To: References: <1106689788.676121.48490@c13g2000cwb.googlegroups.com> Message-ID: Terry Reedy schrieb: > But if the class method syntax were > manditory, there would be class and/or class hierarchy bloat due to the > unlimited number of possible functions-of-a-float and large number of > actual such functions that have been written. You are right. I'm not an OO purist, I just wanted to convince Davor, that anti-OO purism can be harmful too. It's good for programmers to have a choice. > Your Four Steps to Python Object Oriented Programming - vars, lists, dicts, > and finally classes is great. I'm glad you like it :) -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- From http Wed Jan 12 23:06:39 2005 From: http (Paul Rubin) Date: 12 Jan 2005 20:06:39 -0800 Subject: why are people still using classic classes? References: Message-ID: <7x6522gegg.fsf@ruckus.brouhaha.com> Simon Wittber writes: > > Is there a reason NOT to use them? If a classic class works fine, what > > incentive is there to switch to new style classes? > > Perhaps classic classes will eventually disappear? It just means that the formerly "classic" syntax will define a new-style class. Try to write code that works either way. It would be nice if a __future__ directive were added right now (if it's not there already) that processes all class definitions as new-style. Otherwise there's no easy way to test for compatibility. From wittempj at hotmail.com Tue Jan 25 15:51:38 2005 From: wittempj at hotmail.com (wittempj at hotmail.com) Date: 25 Jan 2005 12:51:38 -0800 Subject: __deepcopy__ without recursive copies? In-Reply-To: <1106677008.086803.76270@c13g2000cwb.googlegroups.com> References: <1106677008.086803.76270@c13g2000cwb.googlegroups.com> Message-ID: <1106686298.584607.116100@c13g2000cwb.googlegroups.com> In this thread a solution is given on how to work with __deepcopy__: http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/c34431c5fd3c223b/427866340239edd7?q=__deepcopy__+example&_done=%2Fgroups%3Fq%3D__deepcopy__+example+%26hl%3Den%26lr%3D%26safe%3Doff%26sa%3DN%26tab%3Dwg%26&_doneTitle=Back+to+Search&&d#427866340239edd7 For you this would give something like: -import copy -class DeviceManager(object): - def __init__(self,devFile): - DevFile = open(devFile) - devList = [Device(line) for line in DevFile] - #etc, etc... - - def __deepcopy__(self, memo): - x = DeviceManager.__new__(DeviceManager) - memo[id(self)] = x - for n, v in self.__dict__.iteritems(): - setattr(x, n, copy.deepcopy(v, memo)) - return x - -class Device(object): - def __init__(self,line): - self.copies = [] - #do something with line here - - def __deepcopy__(self, memo): - x = Device.__new__(Device) - memo[id(self)] = x - for n, v in self.__dict__.iteritems(): - setattr(x, n, copy.deepcopy(v, memo)) - return x - -DevMan1 = DeviceManager(r'c:\autoexec.bat') -DevMan2 = copy.deepcopy(DevMan1) - -print DevMan1 is DevMan2 From phr at localhost.localdomain Tue Jan 25 17:56:47 2005 From: phr at localhost.localdomain (phr at localhost.localdomain) Date: Tue, 25 Jan 2005 22:56:47 GMT Subject: What's so funny? WAS Re: rotor replacement References: <41EE24F7.7030303@jessikat.fsnet.co.uk> <7x1xchlpqv.fsf@ruckus.brouhaha.com> <41efeb82$0$27807$9b622d9e@news.freenet.de> <41f1a70b$0$25959$9b622d9e@news.freenet.de> <7xllalljah.fsf@ruckus.brouhaha.com> <7xekgdmpll.fsf@ruckus.brouhaha.com> <7xpszxcnfa.fsf@ruckus.brouhaha.com> <7xllalcmqc.fsf@ruckus.brouhaha.com> <7xbrbhosh7.fsf@ruckus.brouhaha.com> <7xzmz0lw6h.fsf@ruckus.brouhaha.com> <41f4324a$0$1547$9b622d9e@news.freenet.de> <41f589f9$0$3357$9b622d9e@news.freenet.de> <41f6a8ef$0$27790$9b622d9e@news.freenet.de> Message-ID: "Martin v. L?wis" writes: > There isn't. The interface might be beautifully designed, and you might > claim it is, and I would *still* require that the module gets field > testing before being incorporated into Python. Yes, of course, that's completely reasonable. > If other people start attesting that the module is beatifully > designed, and should be included in the Python core - *then* it is > worth looking into inclusion. You said something more than that. You said it's not worth even thinking about inclusion until the finished module is actually in distribution outside the core. That it's not appropriate for the distro maintainers to look at the spec and the reference (pure Python) implementatation and say "yes, we want this, go write the C version and we'll include it after it's had some testing". I think that's silly. (Anyway I don't think "beautifully designed" needs to be a requirement, and I don't claim to have done a beautiful design. "Gets the job done straightforwardly" is all that's needed and is all that I've aimed for). When the inestimable Alexbot went to O'Reilly to pitch "Python in a Nutshell", I'm sure they didn't tell him "go write the whole book from cover to cover, circulate it for at least a year and get it thoroughly reviewed, and if enough people recommend it, then and only then will we begin to think about distributing it ourselves". More normally, he'd have given them a proposal with an outline and maybe a sample chapter and they used that to decide to give him a go-ahead. Usually at that point, they'd even also pay him some money in advance to do the rest of the work with, and promise to pay him a cancellation fee if they changed their mind about the book. I certainly never asked for anything like that from the Python guys about the crypto module. I did ask for, and receive, a "this looks good, we want it". I later heard that they backed off because of legal concerns, so I put the task aside. Similarly, look at how the whole PEP process works. There are lots of times when a PEP has been accepted before any working code is distributed. To take your view to an extreme, no project should even have a task list of desired features that people are invited to implement. There's been numerous times when I've written something for the GNU project because it's been on a list like that, and it's been accepted after checking that it does what it's supposed to. > > I'm happy to have that kind of testing (and I requested it), given > > that the goal is inclusion in the core, and the core developers have > > told me (as they did) that the proposal looks good and they'd like to > > have the module, so I can reasonably expect it to go into the core if > > it meets its technical expectations. > > Not if I have a say in it. *Any* new module should see out-of-the-core > distribution first (unless there is BDFL pronouncement to include it, > of course). > > This really is a matter of development process, not of technical > quality. That's bizarre and abnormal as a development process. What kind of development process in industry doesn't decide whether to include a feature, until after the feature is completely implemented at a production scale? They figure out what the features should be, and write them into a specification. The specification defines what features will be included. Then they implement the features. (I'm talking specificially about straightforward, well-defined features, not blue-sky or experimental concepts). You see, they decide in advance what features they're going to include, because development consumes resources and they don't want to burn resources to develop something unless they're pretty sure they're going to use the result once it's done. (Of course it doesn't always work out that way. Everyone has worked on projects that have gotten cancelled before delivery. However that by definition means that something has gone wrong. No engineer likes it when that happens.) You seem to have the attitude that since volunteer development effort doesn't consume actual PSF funds, the volunteer effort is worth nothing and can be expended arbitrarily. The volunteers may not feel that way. > > If the developers instead say (as they seemed to somewhat later) that > > because of legal/political concerns, there's no way the module can > > possibly go into the core no matter how good it is technically, then > > my motivation for writing the module dries up quite a bit. > > I personally would not say that, although I can imagine that some people > do say that, and I would also defend an inclusion, and push compliance > the BXA requirements so we can legally export Python out of the U.S.A. The BXA notification on the US side is pretty easy to handle, as you know. If you look at those Python-dev messages, the concern was about importing Python-with-crypto into countries like Holland, not about exporting it from the USA. Those concerns are not necessarily something to sneeze at. Salman Rushdie had to go into hiding for years, after publishing a book in England whose contents were illegal in Iran. So, I can't get too upset with the Python maintainers for deciding to stay away from such political messes, even though I don't feel such strong concern myself. > In either case, the user would best use the pre-compiled binary that > somebody else provided for the platform. Who's the "somebody else"? The module author might also not have had a compiler for that platform. Are you suggesting that he maintain his own distribution of multiple binaries, duplicating the machinery of the Python distro for managing multi-platform builds? Do you do that with your own modules, and still say that it's easy? If you don't, then how does the end user know where to get the module for his platform? > No, I'm merely repeating myself, and rephrasing each time. > I have to, because apparently you don't see what my requirement is. Unless your requirement is different than what you say it is, I do see what it is, and I'm saying it's better to do what normal projects do and what Python has done in the past. That is, it's perfectly ok to decide to do something and then do it, rather than insisting, bizarrely, that it always be the other way around. > The original source code of the SHA-1 implementation is the NIST code > (Gutmann, then Hollerbach), so I guess that had hundreds of users before > the module was contributed to Python. Not terribly relevant, the NIST code was not a Python module. > The module itself (including the API) was written by Greg Stein and > Andrew Kuchling. I believe (without being able to verify) that they > distributed this module for quite some time, before contributing it > to Python. We would have to ask them how many users they had until > they felt confident to contribute the code. I think that question isn't the right one. We need to ask how many users the sha module was required to have, before Greg and Andrew could have reasonable confidence that the sha module would go into the core once it was tested enough and shown to be reliable. I suspect they were able to have that confidence long before testing was complete, and maybe before implementation even started. That is, they were likely able to decide that the core obviously needed a sha module, before setting off to write and test one for that purpose. If Andrew is reading this, maybe he can comment. From craig at postnewspapers.com.au Tue Jan 11 06:10:34 2005 From: craig at postnewspapers.com.au (Craig Ringer) Date: Tue, 11 Jan 2005 19:10:34 +0800 Subject: here document In-Reply-To: <1166F26E-63BE-11D9-B3E0-003065FB7B26@upf.edu> References: <1166F26E-63BE-11D9-B3E0-003065FB7B26@upf.edu> Message-ID: <1105441834.3448.2.camel@rasputin.localnet> On Tue, 2005-01-11 at 18:46, harold fellermann wrote: > On 11.01.2005, at 11:34, Nader Emami wrote: > > Would somebody help me how i can write the 'here document' in > > Python script please? I have a csh script in which a program > > is invoked with some argument in the form of here document: > > > > /bin/exe.x << End_Here > > CategorY = GRIB > > etc. > > End_Here > > > > I translate this script to Python and i don't know how can I > > do this! > > f = open("/bin/exe.x","w") > print >>f , """CategoryY = GRIB > etc. > """ You mean "os.popen" not "open" I assume? The former opens a pipe to a command, the latter overwrites the file. I'd use: os.popen("/bin/exe.x", "w").write("""\ CategorY = GRIB etc. """) myself, but that's just taste (well, and performance I suspect). -- Craig Ringer From michele.simionato at gmail.com Tue Jan 4 03:26:54 2005 From: michele.simionato at gmail.com (michele.simionato at gmail.com) Date: 4 Jan 2005 00:26:54 -0800 Subject: Frameworks for "Non-Content Oriented Web Apps" In-Reply-To: <1104641466.776338.71700@z14g2000cwz.googlegroups.com> References: <1104641466.776338.71700@z14g2000cwz.googlegroups.com> Message-ID: <1104827214.733305.273410@z14g2000cwz.googlegroups.com> Well, with your first post you managed to get a very unclear picture of what you mean by "non-content oriented Web Application" ;-) Judging from your following posts, you want an easy way to construct Web interfaces, i.e. forms. This can be done with any Web framework, but a typical Web framework provides a lots of content-related functionality you don't want. For instance you could use Plone for your task, but you would waste 99% of its functionality and it would be absolutely overkill. If I had to write a Web application such as Webmin, for instance, i.e. one that use a Web interface to manage other applications, I would use Quixote as my Web framework of choice. Its key points are simplicity and the fact that it provides *very little*. Just the form library would be enough for you. Since the different part of Quixote are well separated, the learning curve is really really small. It also takes a little time to evaluate it. I suggest you to give a look at it. Michele Simionato From sean at buildingonline.com Wed Jan 19 22:38:22 2005 From: sean at buildingonline.com (Sean) Date: Wed, 19 Jan 2005 19:38:22 -0800 Subject: list item's position References: Message-ID: Not sure if this is what you are looking for but... >>> li = ['this','is','a','list','of','strings'] >>> li = [l for l in li if li.index(l) >= li.index('a')] >>> li ['a', 'list', 'of', 'strings'] >>> -- Sean Berry ~ Internet Systems Programmer BuildingOnline Inc. The Building Industry's Web Design and Marketing Agency Celebrating our 9th year in business, founded Aug. 1995 Ph: 888-496-6648 ~ Fax: 949-496-0036 --> Web Design Agency site: http://www.BuildingOnline.net --> Building Industry Portal: http://www.BuildingOnline.com --> Building Industry News: http://www.BuildingOnline.com/news/ --> Home Plans: http://www.eHomePlans.com "Bob Smith" wrote in message news:csn747$3fq$1 at solaris.cc.vt.edu... > Hi, > > I have a Python list. I can't figure out how to find an element's numeric > value (0,1,2,3...) in the list. Here's an example of what I'm doing: > > for bar in bars: > if 'str_1' in bar and 'str_2' in bar: > print bar > > This finds the right bar, but not its list position. The reason I need to > find its value is so I can remove every element in the list before it so > that the bar I found somewhere in the list becomes element 0... does that > make sense? > > Thanks, > > Bob From steven.bethard at gmail.com Thu Jan 27 16:07:40 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 27 Jan 2005 14:07:40 -0700 Subject: Question about 'None' In-Reply-To: References: <1106852591.770254.203560@z14g2000cwz.googlegroups.com> Message-ID: Francis Girard wrote: > Le jeudi 27 Janvier 2005 21:29, Steven Bethard a ?crit : >> >>So None being smaller than anything (except itself) is hard-coded into >>Python's compare routine. My suspicion is that even if/when objects of >>different types are no longer comparable by default (as has been >>suggested for Python 3.0), None will still compare as smaller than >>anything... > > Well, here's python doesn't seem to confirm what you're saying : > > >>>>a = "10" >>>>b = 10 >>>>a > b > > True > >>>>b > a > > False > >>>>id(a) > > 1077467584 > >>>>id(b) > > 134536516 Actually, this code doesn't contradict what I said at all. I said that None (and only None) was special-cased. > It really looks like the addresses are compared when objects are of different > types if there is no __cmp__ or __lt__ user made specification to compare > objects of different types. Use the source Luke! ;) Download it from CVS and take a look. The end of default_3way_compare: static int default_3way_compare(PyObject *v, PyObject *w) { ... /* None is smaller than anything */ if (v == Py_None) return -1; if (w == Py_None) return 1; /* different type: compare type names; numbers are smaller */ if (PyNumber_Check(v)) vname = ""; else vname = v->ob_type->tp_name; if (PyNumber_Check(w)) wname = ""; else wname = w->ob_type->tp_name; c = strcmp(vname, wname); if (c < 0) return -1; if (c > 0) return 1; /* Same type name, or (more likely) incomparable numeric types */ return ((Py_uintptr_t)(v->ob_type) < ( Py_uintptr_t)(w->ob_type)) ? -1 : 1; } So it looks like Python uses the type name. Testing this: py> A = type('A', (object,), {}) py> Z = type('Z', (object,), {}) py> lst = [str('a'), dict(b=2), tuple(), Z(), A()] py> [type(o).__name__ for o in lst] ['str', 'dict', 'tuple', 'Z', 'A'] py> sorted(type(o).__name__ for o in lst) ['A', 'Z', 'dict', 'str', 'tuple'] py> sorted(lst) [<__main__.A object at 0x011E29D0>, <__main__.Z object at 0x011E29F0>, {'b': 2}, 'a', ()] Yup. Looks about right. (Note that the source code also special-cases numbers...) So, the order is consistent, but arbitrary, just as Fredrik Lundh pointed out in the documentation. Steve From francis.girard at free.fr Thu Jan 27 16:30:57 2005 From: francis.girard at free.fr (Francis Girard) Date: Thu, 27 Jan 2005 22:30:57 +0100 Subject: Question about 'None' In-Reply-To: References: <1106852591.770254.203560@z14g2000cwz.googlegroups.com> Message-ID: <200501272230.57840.francis.girard@free.fr> Very complete explanation. Thank you Francis Girard Le jeudi 27 Janvier 2005 22:15, Steven Bethard a ?crit?: > Francis Girard wrote: > > I see. There is some rule stating that all the strings are greater than > > ints and smaller than lists, etc. > > Yes, that rule being to compare objects of different types by their type > names (falling back to the address of the type object if the type names > are the same, I believe). Of course, this is arbitrary, and Python does > not guarantee you this ordering -- it would not raise backwards > compatibility concerns to, say, change the ordering in Python 2.5. > > > What was the goal behind this rule ? > > I believe at the time, people thought that comparison should be defined > for all Python objects. Guido has since said that he wishes the > decision hadn't been made this way, and has suggested that in Python > 3.0, objects of unequal types will not have a default comparison. > > Probably this means ripping the end off of default_3way_compare and > raising an exception. As Fredrik Lundh pointed out, they could, if they > wanted to, also rip out the code that special-cases None too. > > Steve From steve at holdenweb.com Fri Jan 21 12:13:40 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 21 Jan 2005 12:13:40 -0500 Subject: Zen of Python In-Reply-To: References: <972ec5bd050119111359e358f5@mail.gmail.com> <797fe3d405011911465ab59acd@mail.gmail.com> <1106177050.630141.33090@c13g2000cwb.googlegroups.com> <972ec5bd0501191641166972b0@mail.gmail.com> <7xis5szpdj.fsf@ruckus.brouhaha.com> <7xekggbrns.fsf@ruckus.brouhaha.com> <7x651rwbib.fsf@ruckus.brouhaha.com> Message-ID: Skip Montanaro wrote: > Steve> The fact that a bright bunch like the Python developers didn't > Steve> realize that it would be sensible to have a local scope for the > Steve> list comprehension variable is a perfect demonstration of that > Steve> point. > > Actually, I seem to recall that the topic came up, but at the time the goal > was that list comprehensions be semantically the same as for loops, so the > fact that the loop variable survived to pollute the namespace was deemed > okay. > > Skip > Thanks, Skip. I remember the discussions on python-dev, but I don't think that invalidates my point. I wasn't suggesting nobody realized there would be name-droppings, simply that nobody realized that a later goal of namespace purity would take priority over the initial one of for-loop compatibility. Similar issues surrounded nested scopes, if I remember, and even there the jury's still out. Which is why I "accused" Paul Rubin of requiring psychic powers from language developers when he said "So once we can see where it's going, why not proceed to the finish line immediately instead of bothering with the intermediate steps?" we-can't-always-see-where-we're-going-ly y'rs - steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 From mcfletch at rogers.com Fri Jan 21 20:23:58 2005 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Fri, 21 Jan 2005 20:23:58 -0500 Subject: Class introspection and dynamically determining function arguments In-Reply-To: <41f18d10.1471646806@news.oz.net> References: <41f18d10.1471646806@news.oz.net> Message-ID: <41F1AB2E.7080902@rogers.com> >On Thu, 20 Jan 2005 11:24:12 -0000, "Mark English" wrote: > > > >>I'd like to write a Tkinter app which, given a class, pops up a >>window(s) with fields for each "attribute" of that class. The user could >>enter values for the attributes and on closing the window would be >>returned an instance of the class. The actual application I'm interested >>in writing would either have simple type attributes (int, string, etc.), >>or attributes using types already defined in a c-extension, although I'd >>prefer not to restrict the functionality to these requirements. >> >> Hmm, I missed the original post, but I'll jump in anyway: This sounds a heck of a lot like a property-editing system. When creating a property-modeled system, the best approach is normally to use something that actually models the properties, rather than trying to guess at the metadata involved by poking around in an arbitrarily structured object. My BasicProperty system allows for this kind of interaction (property-sheets) using wxPython (rather than Tkinter) when using wxoo. You declare classes as having a set of data-properties (which can have defaults or not, constraints or not, restricted data-types or not, friendly names or not, documentation or not). Normally you create these classes as subclasses of a class that knows how to automatically assign __init__ parameters to properties, and knows how to tell (e.g.) wxoo about the properties of the class. Those same property classes also allow for editing properties of database rows in PyTable, but that isn't likely relevant to your case. We've also used them internally to create a rather large web-based property-editing mechanism (applied to such databases), but again, not really relevant to the case at hand. Anyway, if you aren't interested in BasicProperty for this task; another project on which I work, PyDispatcher provides fairly robust mechanism (called robustApply) for providing a set of possible arguments and using inspect to pick out which names match the parameters for a function in order to pass them in to the function/method/callable object. That said, doing this for __init__'s with attribute values from an object's dictionary doesn't really seem like the proper way to approach the problem. Good luck, Mike ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From macrocosm at fastmail.fm Sun Jan 9 23:13:04 2005 From: macrocosm at fastmail.fm (Arich Chanachai) Date: Sun, 09 Jan 2005 23:13:04 -0500 Subject: Python Operating System??? In-Reply-To: <7x6526otw3.fsf@ruckus.brouhaha.com> References: <10trb0mgiflcj4f@corp.supernews.com> <10tteh884ivk6c9@corp.supernews.com> <7xr7kx0w4m.fsf@ruckus.brouhaha.com> <7xhdlss0tl.fsf@ruckus.brouhaha.com> <7x8y734jlq.fsf@ruckus.brouhaha.com> <7xr7kv8bmt.fsf@ruckus.brouhaha.com> <7xr7kvm72c.fsf@ruckus.brouhaha.com> <7x6526otw3.fsf@ruckus.brouhaha.com> Message-ID: <41E200D0.6010402@fastmail.fm> Paul Rubin wrote: >"Roose" writes: > > > ... > >>Upon reading back in the thread I see that you mean compiled Lisp, >>no? I was thinking that there would be a Lisp interpreter in a >>kernel, which afaik doesn't exist. >> >> > >Yes, compiled Lisp. There are Python compilers too.\ > > ??? You mean like Pyrex or some such? I wouldn't exactly call these "Python" compilers, as that kind of obscures some underlying (critical) facts. >>In any case, as I said before I don't think it is impossible, just a >>poor engineering decision and I don't see the rationale behind it. >> >> > >I don't see a convincing case against writing an OS even in >interpreted Python, though of course I'd want it to be compiled if >possible. > >What do you think OS's do, that Python wouldn't be suitable for? Your >examples of task switching and virtual memory are unconvincing. Those >just require setting up some suitable tables and then calling a >low-level routine to poke some CPU registers. File systems can be >more performance intensive, but again, in those, much of the cpu drain >can be relegated to low-level routines and the complexity can be >handled in Python. > > Correct. From rmemmons at member.fsf.org Sat Jan 8 11:31:05 2005 From: rmemmons at member.fsf.org (Rob Emmons) Date: Sat, 08 Jan 2005 10:31:05 -0600 Subject: The best way to do web apps with Python? References: <41dfdc15$0$29387$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: > > > > > > > >
What is Just FYI -- the post you posted was in HTML -- you might want to avoid this in the future. 99% of all posts to news groups are in text, not html. Html is hard for everyone to read with normal news readers and not usually of any extra value. It's also more of a security risk to read it -- because there is more potential for exploitation. Anyway, just thought I'd mention it if you didn't know. Take care, Rob From aorfanakos at gmail.com Sun Jan 30 21:58:10 2005 From: aorfanakos at gmail.com (Aggelos I. Orfanakos) Date: 30 Jan 2005 18:58:10 -0800 Subject: Regarding exception handling In-Reply-To: References: <1107114438.710147.218010@z14g2000cwz.googlegroups.com> <1107114866.965331.158950@f14g2000cwb.googlegroups.com> <1107119504.793109.184450@c13g2000cwb.googlegroups.com> <1107127179.863445.55310@c13g2000cwb.googlegroups.com> Message-ID: <1107140290.363099.273690@c13g2000cwb.googlegroups.com> Good point, but with your way, if "s = ... # socket opens" fails, then nothing will catch it. What I usually do is what I wrote above (place it below the 2nd try), and when attempting to close it, first use an if like: "if locals().has_key('s'):". From kartic.krishnamurthy at gmail.com Tue Jan 25 15:05:54 2005 From: kartic.krishnamurthy at gmail.com (Kartic) Date: 25 Jan 2005 12:05:54 -0800 Subject: Import from database In-Reply-To: References: <1106587145.067483.14710@z14g2000cwz.googlegroups.com> Message-ID: <1106681053.863328.261670@f14g2000cwb.googlegroups.com> Steve, Hmmm... Yes, I see what you are saying. Could you post your create table statement so that I can create a db and play around with dbimport? Thanks, --Kartic From foo at bar.com Sun Jan 23 20:29:23 2005 From: foo at bar.com (Steve Menard) Date: Sun, 23 Jan 2005 20:29:23 -0500 Subject: Help on project, anyone? In-Reply-To: <35ienhF4lu88lU1@individual.net> References: <35ienhF4lu88lU1@individual.net> Message-ID: <5cYId.2514$zV3.523375@wagner.videotron.net> Georg Brandl wrote: > Hello, > > to train my Python skills I am looking for some project I can contribute > to. I learned Python about one year ago, and had already some > programming background behind (I contributed to SharpDevelop for > instance), so I'm not the complete newbie. > > About myself: I'm a 20 year old German with strong interests in > programming and, of course, especially in Python (I love it...). > > Does anyone run, or participate in, a project looking for fellow > programmers? I don't have a special area of interest, well, perhaps web > programming... > > Thanks, > Georg You know what I would do? I would go on Sourceforge. Try to find a project that seems interestingto you. and then contact the Maintainer see if you can help. Many project also advertise the kind of help they need. -- Steve Menard -------------------- Maintainer of http://jpype.sourceforge.net From bokr at oz.net Sat Jan 8 06:31:08 2005 From: bokr at oz.net (Bengt Richter) Date: Sat, 08 Jan 2005 11:31:08 GMT Subject: python3: 'where' keyword References: <3480qqF46jprlU1@individual.net> <41DF78EB.6040502@iinet.net.au> Message-ID: <41dfc018.305122743@news.oz.net> On Sat, 08 Jan 2005 16:42:16 +1000, Nick Coghlan wrote: >Nick Coghlan wrote: >> It also allows the necessary but uninteresting setup for an expression >> to be moved "out of the way", bringing the expression that does the real >> work to prominence. > >Killer app for this keyword: > >class C(object): > > x = property(get, set) where: > def get(self): > return "Silly property" > def set(self, val): > self.x = "Told you it was silly" > Yes, that is cool and it _is_ an interesting idea. Are suites nestable? E.g., is this legal? x = term1 + term2 where: term1 = a*b where: a = 123 b = 456 term2 = math.pi Reminds me of some kind of weird let ;-) And, is the whole thing after the '=' an expression? E.g., x = ( foo(x) where: x = math.pi/4.0 ) where: def foo(x): print 'just for illustration', x or is this legal? for y in ([foo(x) for x in bar] where: bar = xrange(5) ): baz(y) where: def baz(arg): return arg*2 Not trying to sabotage the idea, really, just looking for clarification ;-) Regards, Bengt Richter From http Sun Jan 9 01:48:27 2005 From: http (Paul Rubin) Date: 08 Jan 2005 22:48:27 -0800 Subject: Python Operating System??? References: <10trb0mgiflcj4f@corp.supernews.com> <10tteh884ivk6c9@corp.supernews.com> <7xr7kx0w4m.fsf@ruckus.brouhaha.com> <7xhdlss0tl.fsf@ruckus.brouhaha.com> <7x8y734jlq.fsf@ruckus.brouhaha.com> <7xr7kv8bmt.fsf@ruckus.brouhaha.com> Message-ID: <7xr7kvm72c.fsf@ruckus.brouhaha.com> "Roose" writes: > But are you really going to write a virtual memory system in Python? Are > you going to write a file system, and a task scheduler in Python? Are you > going to have people write device drivers in Python? Do you know how virtual memory systems, file systems, task schedulers, and device drivers actually work? Have you ever written any of them? What exactly do you think the obstacles are to writing them in Python? I've written file systems in Python, and task schedulers in Javascript, and they were fine for their purposes. Virtual memory and device drivers are just more of the same. > > It doesn't prove anything of the sort. The Lisp hardware was needed > > for performance reasons, back in the day. > > OK, then give me an example of Lisp OS that runs on a PC. I would like to > install it on my PC tomorrow. Or maybe my Mac. That was your whole point, > originally, that since it could be done in Lisp, why not Python? Huh? That's a non-sequitur, nothing prevents you from running Lisp on your PC or Mac. The same issues issues that apply to OS code, also apply to user code. The Lisp machine hardware wasn't needed only to make the OS run fast. The Lisp machine was developed so that people could deploy large user-level applications written in Lisp, and the hardware was there to support those applications. And given such a good Lisp environment, there was no reason to think of writing the OS in anything other than Lisp. In fact, the reason the Lisp machine died off was because general purpose workstation hardware (and later, PC-class hardware) became fast enough to run Lisp applications without needing special purpose CPU's. That same PC hardware speed is what makes it possible to run user applications in Python. From cam.ac.uk at mh391.invalid Sun Jan 23 09:57:42 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Sun, 23 Jan 2005 14:57:42 +0000 Subject: is there better 32 clock() timing? In-Reply-To: References: Message-ID: Ray Schumacher wrote: > I have a need for a time.clock() with >0.000016 second (16us) accuracy. > The sleep() (on Python 2.3, Win32, at least) has a .001s limit. > > Are they lower/better on other's platforms? The meaning of time.clock() is entirely different on other platforms. See the documentation. You could probably get a slight speedup by using "from time import clock" and then just clock(). -- Michael Hoffman From http Mon Jan 10 20:13:17 2005 From: http (Paul Rubin) Date: 10 Jan 2005 17:13:17 -0800 Subject: Writing huge Sets() to disk References: <41E2A91D.7080006@ribosome.natur.cuni.cz> <1105381712.3588.15.camel@localhost.localdomain> <7xmzvgren6.fsf@ruckus.brouhaha.com> <7xis64ree5.fsf@ruckus.brouhaha.com> Message-ID: <7xr7ks3h02.fsf@ruckus.brouhaha.com> =?windows-1252?Q?Martin_MOKREJ=8A?= writes: > Yes, I'm. I still don't get what that acronym CLRS stands for ... :( CLRS = the names of the authors, Cormen, Leiserson, Rivest, and Stein, if I spelled those correctly. :) From golux at comcast.net Sat Jan 22 16:40:16 2005 From: golux at comcast.net (Stephen Waterbury) Date: Sat, 22 Jan 2005 16:40:16 -0500 Subject: What YAML engine do you use? In-Reply-To: References: <35a6tpF4gmat2U1@individual.net> <7x1xcfwbab.fsf@ruckus.brouhaha.com> <35csm7F4l57inU1@individual.net> <41f1a3e6.1477492061@news.oz.net> Message-ID: <41F2C840.2050304@comcast.net> Steve Holden wrote: > It seems to me the misunderstanding here is that XML was ever intended > to be generated directly by typing in a text editor. It was rather > intended (unless I'm mistaken) as a process-to-process data interchange > metalanguage that would be *human_readable*. The premise that XML had a coherent design intent stetches my credulity beyond its elastic limit. From aaronwmail-usenet at yahoo.com Sat Jan 8 06:53:26 2005 From: aaronwmail-usenet at yahoo.com (aaronwmail-usenet at yahoo.com) Date: 8 Jan 2005 03:53:26 -0800 Subject: OT: google groups bug, or worse? In-Reply-To: <41df13b7.260993058@news.oz.net> References: <1105127965.616198.302710@z14g2000cwz.googlegroups.com> <41df13b7.260993058@news.oz.net> Message-ID: <1105185206.674806.155330@c13g2000cwb.googlegroups.com> Bengt Richter wrote: > What did you google with? Is this it? > http://groups-beta.google.com/groups?hl=en&ie=UTF-8&q=%22The+xsdbXML+framework+provides+a+flexible+and+well+defined+infrastructure%22&qt_s=Search+Groups That was my *reply* to one of the original posts using Google, which I faked up when I couldn't find it (posted using google). The two originals aren't there. hmmm. -- Aaron Watters === You'd be paranoid too, if everyone was out to get you! From steve at holdenweb.com Mon Jan 31 17:49:53 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 31 Jan 2005 17:49:53 -0500 Subject: Want to meet any of these people? They are registered for PyCon In-Reply-To: References: Message-ID: Aahz wrote: > In article , > Steve Holden wrote: > >>Note that the sort order isn't perfect - I just sorted on the second >>"word" in each name. PyCon is a *great* place to meet people and discuss >>ideas. Hope to see you there. > > > Good thing I'm not coming this year, eh? ;-) If you mean specifically for sorting purposes, it would have put the null second name at the beginning just like you'd expect. regards Steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 From bearophileHUGS at lycos.com Wed Jan 5 19:40:47 2005 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 5 Jan 2005 16:40:47 -0800 Subject: Other notes References: <86r7l7sczp.fsf@guru.mired.org> Message-ID: <1104972047.050366.211670@f14g2000cwb.googlegroups.com> Thank you to all the gentle people that has given me some comments, and sorry for bothering you... Doug Holton: >This will also likely never appear in Python. I know, that's why I've defined it "wild". >Also, you might request the NetLogo and StarLogo developers to support Jython (in addition to Logo) scripting in their next version< I was suggesting the idea of adding the complex data structures of NetLogo (patches, etc) to the normal Python. ------------- Andrew Dalke: >(BTW, it needs to be 1 .. 12 not 1..12 because 1. will be interpreted as the floating point value "1.0".)< Uhm, I have to fix my ignorance about parsers. Cannot a second "." after the first tell that the first "." isn't in the middle of a floating point number? >In Pascal it works because you also specify the type and Pascal has an incr while Python doesn't.< The Pascal succ function (that works on chars and all integer types) is often useful (it's easy to define it in Python too). >>This may allow: assert 5 interval 9 == interval(5,9) >Maybe you could give an example of when you need this in real life?< Every time you have a function with 2 parameters, you can choose to use it infix. >Does this only work for binary or is there a way to allow unary or other n-ary (including 0-ary?) functions?< It's for binary functions only. For unary the normal fun(x) syntax is good enough, and for n-ary the sintax becomes unnecessary complex, and you can use the normal function syntax again. >But to someone with C experience or any language which derives its formatting string from C, Python's is easier to understand than your Pascal one.< You can be right, but "understanding" and "being already used to something" are still two different things :-) >A Python view is that there should be only one obvious way to do a task. Supporting both C and Pascal style format strings breaks that.< Okay. >I don't think Pascal is IEEE enough.< Well, if you assign that FP number inside the program (and not as a constant) Delphi 4 too gives a more "correct" answer ^_^ (I don't know/remember why there are such differences inside Delphi between constants and variables). >note also that the Pascal-style formatting strings are less capable than Python's,< I know... >though few people use features like< Right. >A real-life example would also be helpful here.< (I was parsing trees for Genetic Programming). People here can probably suggest me 10 alternative ways to do what I was trying to do :-) As list comprehensions, that suggestion of mine cannot solve new kinds of problems, it's just another way of doing things. >What does map(len, "Blah", level = 200) return?< Well: "c" == "c"[0][0][0][0][0][0] map(len, "blah") == [1, 1, 1, 1] So I think that answer is still [1, 1, 1, 1]. >You need to learn more about the Pythonic way of thinking of things. The usual solution for this is to have "level = None".< To Steven Bethard I've suggested an alternative syntax (using a level-ed flatten with a standard map command). >There's also tmPython.< Thank you, the screenshoots are quite nice :-) http://dkbza.org/11.0.html -------------- Steven Bethard: >Since I can't figure it out intuitively (even with examples), I don't think this syntax is any less inscrutable than '%.f'.< Well, I haven't given a textual explanation, but just few examples. >My suspicion is that you're just biased by your previous use of Pascal.< This is possible. >This packs two things into map -- the true mapping behaviour (applying a function to a list) and the flattening of a list.< Okay, then this is my suggestion for the syntax of an iterable xflatten: xflatten(sequence, level=-1, monadtuple=False, monadstr=True, safe=False]) - level allows to specify the mapping level: level=0 no flattening. level=1 the flattening is applied to the first and second level. Etc. And like in the indexing of lists: level=-1 (default) means the flattening is applied up to the leaves. level=-2 flattens up to pre-leaves. Etc. - monadtuple (default False) if True tuples are monads. - monadstr (default True) if False then strings with len>1 are sequences too. - safe (default False) if True it cheeks (with something like an iterative isrecursive) for recursive references inside the sequence. >(Also, Google for flatten in the python-list -- you should find a recent thread about it.)< I've discussed it too in the past :-) http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/d0ba195d98f35f66/ >and that your second example gains nothing over< Right, but maybe with that you can unify the def and lambda into just one thing ^_^ >def foo(x): > globals()['y'] = globals()['y'] + 2 >Not exactly the same syntax, but pretty close. Thank you for this idea. >I'll second that. Please, "Bearophile", do us the courtesy of checking [...] before posting another such set of questions. While most of the people on this list are nice enough to answer your questions anyway, the answers are already out there for at least half of your questions, if you would do us the courtesy of checking first.< I've read many documents, articles and PEPs and, but I'm still new, so I've missed many things. I'm sorry... I'm doing my best. ----------- Terry J. Reedy >I also suggest perusing the archived PyDev (Python Development mailing list) summaries for the last couple of years (see python.org). Every two weeks, Brett Cannon has condensed everything down to a few pages.< Okay, thank you. Bear hugs, Bearophile From steve at holdenweb.com Sat Jan 22 10:34:08 2005 From: steve at holdenweb.com (Steve Holden) Date: Sat, 22 Jan 2005 10:34:08 -0500 Subject: What YAML engine do you use? In-Reply-To: <41f1a3e6.1477492061@news.oz.net> References: <35a6tpF4gmat2U1@individual.net> <7x1xcfwbab.fsf@ruckus.brouhaha.com> <35csm7F4l57inU1@individual.net> <41f1a3e6.1477492061@news.oz.net> Message-ID: Bengt Richter wrote: > On Fri, 21 Jan 2005 12:04:10 -0600, "A.M. Kuchling" wrote: > > >>On Fri, 21 Jan 2005 18:30:47 +0100, >> rm wrote: >> >>>Nowadays, people are trying to create binary XML, XML databases, >>>graphics in XML (btw, I'm quite impressed by SVG), you have XSLT, you >>>have XSL-FO, ... . >> >>Which is an argument in favor of XML -- it's where the activity is, so it's >>quite likely you'll encounter the need to know XML. Few projects use YAML, >>so the chance of having to know its syntactic details is small. >> > > > I thought XML was a good idea, but IMO requiring quotes around > even integer attribute values was an unfortunate decision. I don't buy > their rationale of keeping parsing simple -- as if extracting a string > with no embedded space from between an equal sign and terminating white > space were that much harder than extracting the same delimited by double quotes. It isn't that much harder, but if there are two ways to do the same thing then effectively one of them has to become a special case, thereby complicating the code that has to handle it (in this case the parser). "There should be one (and preferably only one) ..." should be a familiar mantra around here :-) > The result is cluttering SVG with needless cruft around numerical graphics parameters. > > It seems to me the misunderstanding here is that XML was ever intended to be generated directly by typing in a text editor. It was rather intended (unless I'm mistaken) as a process-to-process data interchange metalanguage that would be *human_readable*. Tools that *create* XML are perfectly at liberty not to require quotes around integer values. > OTOH, I think the HTML XML spec is very readable, and nicely designed. > At least the version 1.0 spec I snagged from W3C a long time ago. > .... I see the third edition at http://www.w3.org/TR/REC-xml/ is differently styled, > (I guess new style sheets) but still pretty readable (glancing at it now). > > Regards, > Bengt Richter regards Steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 From max at alcyone.com Fri Jan 7 16:43:14 2005 From: max at alcyone.com (Erik Max Francis) Date: Fri, 07 Jan 2005 13:43:14 -0800 Subject: Notification of PEP Updates In-Reply-To: References: Message-ID: Nick Coghlan wrote: > I can't recall which thread this came up in, so I'm starting a new one. . . > > Barry Warsaw has kindly added a "peps" topic to the python-checkins mailing > list. If you want to be notified only when PEP's get updated, then subscribe to > python-checkins and edit your settings to select just the 'peps' topic. Maybe someone could roll this into an RSS feed? -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis There's a reason why we / Keep chasing morning -- Sandra St. Victor From jepler at unpythonic.net Thu Jan 27 22:29:59 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Thu, 27 Jan 2005 21:29:59 -0600 Subject: tkinter: Can You Underline More Than 1 Char In A Menu Title In-Reply-To: References: Message-ID: <20050128032958.GA17445@unpythonic.net> On Thu, Jan 27, 2005 at 06:38:22AM -0500, Tim Daneliuk wrote: > Is it possible to underline more than a single character as I am doing > with the 'underline=0' above. I tried 'underline=(0,2)' but that didn't > work. No. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From gandalf at geochemsource.com Mon Jan 24 07:45:15 2005 From: gandalf at geochemsource.com (Laszlo Zsolt Nagy) Date: Mon, 24 Jan 2005 13:45:15 +0100 Subject: wx.BoxSizer problem In-Reply-To: <48F31575-6BD2-11D9-9482-003065B11E84@leafe.com> References: <41F11AC1.6040108@geochemsource.com> <48F31575-6BD2-11D9-9482-003065B11E84@leafe.com> Message-ID: <41F4EDDB.3080807@geochemsource.com> >> My problem is that only one of the buttons is visible and that one is >> not expanded. (System: Windows, Python 2.3.4, wxPython 2.5.3) > > > Works as expected on Mac OS X 10.3.7, python 2.3.4, wxPython 2.5.2.8. Thanks. Probably the problem is with my bitmap (I used a bitmap instead of a button). Please do not spend more time on it - I'll handle. Best, Laci 2.0 From claird at lairds.us Mon Jan 17 15:08:04 2005 From: claird at lairds.us (Cameron Laird) Date: Mon, 17 Jan 2005 20:08:04 GMT Subject: PyChecker messages References: <1105983271.574296.37740@c13g2000cwb.googlegroups.com> Message-ID: In article <1105983271.574296.37740 at c13g2000cwb.googlegroups.com>, Ben Sizer wrote: >But you could use a dict of return values, or even just assigning a >different return value in each if clause. The end result is that you >have a single well-defined exit point from the function, which is >generally considered to be preferable. > Well, no; I'm trying to say exactly that there are times when "a dict of return values" only adds complexity. Or perhaps I'm missing a bet- way to code: def condition_label(): if x13.fluid_level() > lower_threshhold: return "OK" if user in restricted_list: return "Ask for help" if not current_time.in_range(beginning, end): return "Uncorrectable exception reported" ... When conditions live in a space with higher dimensionality than any handy immutable range, no dict-ification is a benefit. From mcfletch at rogers.com Mon Jan 24 10:35:58 2005 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Mon, 24 Jan 2005 10:35:58 -0500 Subject: Weakref.ref callbacks and eliminating __del__ methods In-Reply-To: <1f7befae0501231720428ca3c@mail.gmail.com> References: <41F427EB.3000200@rogers.com> <1f7befae0501231720428ca3c@mail.gmail.com> Message-ID: <41F515DE.8000600@rogers.com> Tim Peters wrote: >[Mike C. Fletcher] > > >>I'm looking at rewriting parts of Twisted and TwistedSNMP to eliminate >>__del__ methods (and the memory leaks they create). >> >> >A worthy goal! > > Well, as of now it seems to have eliminated the last leaks in TwistedSNMP, and that's likely going to eliminate the last of our leaks in our products, so yes, I suppose it was :) . >A callback is strongly referenced from the weakref(s) containing it. > > Thanks. >It would really help to give a minimal example of self-contained >executable code. I'm not sure how you're using this code, and >guessing takes too long. > > Sorry about that. I was expecting a theoretical problem, not a practical one, so didn't think to provide a practical example. >The "2" there is important, just because this is an interactive >session. The point of it was to stop `_` from holding a reference to >the created weakref. In your code > > weakref.ref( self, self.close ) > >the weakref itself becomes trash immediately after it's created, so >the weakref is thrown away entirely (including its strong reference to >self.close, and its weak reference to self) right after that line >ends. Of course callbacks aren't *supposed* to be called when the >weakref itself goes away, they're supposed to be called when the thing >being weakly referenced goes away. So this all looks vanilla and >inevitable to me -- the callback is never invoked because the weakref >itself goes away long before self goes away. > > Alex already scooped you on this "smack yourself on the head, Mikey". I was assuming the weakref object was a proxy for a reference in an internal structure; I was expecting a list of weak references that was nothing but a series of functions to call after finalising the object. My bad. >I'm pretty sure it's just because there's nothing here to keep the >weakref itself alive after it's created. You could try, e.g., > > self.wr = weakref.ref( self, self.close ) > >to keep it alive, but things get fuzzy then if self becomes part of >cyclic trash. > > Yes, so it requires an external storage mechanism and code to clean that up... ick. __del__ looks cleaner and cleaner by comparison. You'd think I would have noticed the huge tables of weakref objects in PyDispatcher as I was working in there... >>I can work around it in this particular case by defining a __del__ on >>the Closer, but that just fixes this particular instance (and leaves >>just as many __del__'s hanging around). I'm wondering if there's a >>ready recipe that can *always* replace a __del__'s operation? >> >> > >In the presence of cycles it gets tricky; there's a lot of >more-or-less recent words (less than a year old ) about that on >python-dev. It gets complicated quickly, and it seems nobody can make >more time to think about it. > > Sigh, guess I should stop listening to rumours just because they are saying something about that for which I yearn. >>I know I heard a rumour somewhere about Uncle Timmy wanting to eliminate >>__del__ in 2.5 or thereabouts, >> >> > >Python 3 at the earliest. That's the earliest everything nobody can >make time for lands <0.5 wink>. > > Well, we darn well better solve it by then! Don't want memory leaks when we're hard-wired into someone's brain. >There are unresolved issues about how to get all this stuff to work >sanely. The driving principle behind cyclic-trash weakref endcases >right now is "do anything defensible that won't segfault". > >I'll note that one fairly obvious pattern works very well for weakrefs >and __del__ methods (mutatis mutandis): don't put the __del__ method >in self, put it in a dead-simple object hanging *off* of self. Like >the simple: > >class BTreeCloser: > def __init__(self, btree): > self.btree = btree > > def __del__(self): > if self.btree: > self.btree.close() > self.btree = None > > Yes, this was the "work around" I'd implemented (well, with __call__ instead and del just calling it). Of course, that didn't actually eliminate any __del__ methods, but oh well, if we're not losing those until 3.x it doesn't really matter :) . The fix for the Deferred in Twisted got a little hideous (there the __del__ is poking around into lots of different attributes of the Deferred. To hack that I created a descriptor class that forwards a variable to the held object and wrapped each of the needed variables in one of those... I'm going to have to find something a little less baroque if I'm going to get it into Twisted... really, it doesn't look like any of it's necessary, it's just logging an error if the Deferred ended on a Failure. Something should be done though, leaking memory from a core object in the framework is just a PITA. >When a weakref and its weak referent are both in cyclic trash, Python >currently says "the order in which they die is undefined, so we'll >pretend the weakref dies first", and then, as at the start of this >msg, the callback is never invoked. > So external storage of a weakref is basically a requirement to make it useful. Hmm. >The problem this avoids is that >the callback may itself be part of cyclic trash too, in which case >it's possible for the callback to resurrect anything else in cyclic >trash, including the weakly-referenced object associated with the >callback. But by hypothesis in this case, that object is also in >cyclic trash, and horrible things can happen if a partially destructed >object gets resurrected. > > Reasonable I suppose. >So the real rule right now is that, if you want a guarantee that a >callback on a weakly referenced object gets invoked, you have to write >your code to guarantee that the referent becomes trash before its >weakref becomes trash. (And note that if you do, the callback >necessarily will be alive too, because a weakref does in fact hold a >strong reference to its callback.) > > Guess I'll go back to the sub-object approach for all things and merely dream of a far off weakref utopia free of all __del__ methods. Thanks, Tim, Mike ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From fredrik at pythonware.com Sat Jan 22 05:25:08 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 22 Jan 2005 11:25:08 +0100 Subject: list unpack trick? References: <1gqsalx.4ip95k18168r0N%aleaxit@yahoo.com> Message-ID: Alex Martelli wrote: >> or (readable): >> >> if len(list) < n: >> list.extend((n - len(list)) * [item]) > > I find it just as readable without the redundant if guard -- just: > > alist.extend((n - len(alist)) * [item]) the guard makes it obvious what's going on, also for a reader that doesn't know exactly how "*" behaves for negative counts. once you've seen the "compare length to limit" and "extend", you don't have to parse the rest of the statement. From a at b.c Tue Jan 4 15:19:44 2005 From: a at b.c (Doug Holton) Date: Tue, 04 Jan 2005 14:19:44 -0600 Subject: Python evolution: Unease In-Reply-To: <98WdnVGqi-yaUkfcRVn-tw@giganews.com> References: <41da4a3f$0$17626$e4fe514c@dreader13.news.xs4all.nl> <1gpv286.1kccndo1l4coseN%aleaxit@yahoo.com> <41DA79DB.7020507@none.net> <9vqdncpnrbRTNEfcRVn-ug@giganews.com> <98WdnVGqi-yaUkfcRVn-tw@giganews.com> Message-ID: Istvan Albert wrote: > Doug Holton wrote: > >> application is so important that I expect Python 3000 will have >> optional type declarations integrated into the argument list." > > > I think that *optional* part of the "optional type declaration" > is a myth. > > It may be optional in the sense that the language will > accept missing declarations but as soon as the feature > is available it will become "mandatory" to use it > (peer pressure, workplace practices). I didn't write that, Guido did. I agree with you, and others who have made the same point you made. I would have to think Guido is already aware of this issue (keep python simple). I'm not sure what his motivations are for wanting to add static typing to python, not that I'm against it. It doesn't matter a whole lot either way since Python 3000 is still years away and you can already do static typing now with Pyrex or boo, as well as many other things that people have requested for python from little things like ++i to bigger features like multi-line anonymous methods/closures. From roy at panix.com Sat Jan 1 09:27:30 2005 From: roy at panix.com (Roy Smith) Date: Sat, 01 Jan 2005 09:27:30 -0500 Subject: what is lambda used for in real code? References: Message-ID: In article , Adam DePrince wrote: > We can operate on every other class without having to involve the > namespace, why should functions be any different? def is a weird beast. It does more than just bind a lambda to a name, it also alters the function so it knows its own name. For example, the following: -------------- def foo (): print "I am foo" bar = foo def foo (): print "I am foo's evil twin" foo() print foo bar() print bar baz = lambda : "I am lambda" print baz print baz() -------------- will print: I am foo's evil twin I am foo at 0x363770> I am lambda From Jared.Cohen at noaa.gov Wed Jan 5 17:22:21 2005 From: Jared.Cohen at noaa.gov (Jared Cohen) Date: Wed, 05 Jan 2005 17:22:21 -0500 Subject: Please help -- Pmw PanedWidget inside ScrolledFrame Message-ID: <41DC689D.5010305@noaa.gov> I'm trying to use a Pmw.ScrolledFrame which contains a PanedWidget. But I can't get the PanedWidget to expand to fill the interior frame. It expands fine if I just grid it into the toplevel window; and when I tried gridding DIFFERENT widgets into the ScrolledFrame, they expanded just fine. So both the ScrolledFrame and PanedWidget seem to work OK on their own, but when I try to put one inside the other, something goes haywire. Can anyone help please? -------------- next part -------------- An HTML attachment was scrubbed... URL: From daranrife at yahoo.com Fri Jan 28 19:13:18 2005 From: daranrife at yahoo.com (drife) Date: 28 Jan 2005 16:13:18 -0800 Subject: LinearAlgebra incredibly slow for eigenvalue problems In-Reply-To: References: <1106887513.865901.154760@z14g2000cwz.googlegroups.com> <1106952951.834888.65430@f14g2000cwb.googlegroups.com> Message-ID: <1106957598.136667.45430@z14g2000cwz.googlegroups.com> Hi David, Yes, when Numeric compiles it does look like the linking is being done properly. I captured the build to a file and see a few lines similar to: gcc -pthread -shared build/temp.linux-i686-2.4/Src/lapack_litemodule.o -L/d2/lib/atlas -llapack -lptcblas -lptf77blas -latlas -lg2c -o build/lib.linux-i686-2.4/lapack_lite.so I checked the files in build/lib.linux-i686-2.4 and none have dependencies on ATLAS. When I run Python interpreter with: >>> import Numeric >>> Numeric.__file__ I get the answer I expect. I am totall baffled. Any other ideas? Thanks for your help, Daran From peter at engcorp.com Sun Jan 23 19:00:18 2005 From: peter at engcorp.com (Peter Hansen) Date: Sun, 23 Jan 2005 19:00:18 -0500 Subject: OT: problems mirroring python-list to c.l.py? In-Reply-To: References: <1d6cdae305012310535980e82d@mail.gmail.com> <20050123190637.GA4820@grulic.org.ar> Message-ID: Daniel Bickett wrote: > John Lenton wrote: >>>On Sun, Jan 23, 2005 at 01:53:52PM -0500, Daniel Bickett wrote: >>>>Is there a reason that Google Groups isn't mirroring python-list >>>>exactly like it used to, or is it simply a conspiracy I'm not in on? >>> >>>You should not ask this kind of question in a public forum, >> >>and *you* should know better than to go around flapping your mouth >>like that. > > Now I'm further confused, because I don't know what you quoted, but it > isn't on the mailing list and it isn't on c.l.py :) Maybe I should > give up trying to figure these things out. For what it's worth, I'm seeing the same behaviour as what you (Daniel) are seeing, and I read the group through comp.lang.python via NTTP, not via the mail-based python-list or Google Groups. > You didn't include a name at the beginning of your citation... Who had > the audacity to take my joke seriously? ;-) Apparently somebody who doesn't understand that unlike most other public fora, comp.lang.python is "special" in that it is mirrored to and from the mailing list, and that there is no other more appropriate place to ask such a question (at least until it's apparent that it is a problem with a specific part of this system, rather than being entirely unclear just _what_ the problem is). -Peter From iddwb at moroni.pp.asu.edu Thu Jan 13 20:26:09 2005 From: iddwb at moroni.pp.asu.edu (David Bear) Date: Fri, 14 Jan 2005 01:26:09 +0000 (UTC) Subject: query python env Message-ID: How does one query the python environment, ie pythonhome, pythonpath, etc. also, are there any HOWTO's on keeping multiple versions of python happy? From jdhunter at ace.bsd.uchicago.edu Mon Jan 31 11:01:15 2005 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Mon, 31 Jan 2005 10:01:15 -0600 Subject: barchart for webpage needed In-Reply-To: (dimitri pater's message of "Mon, 31 Jan 2005 16:54:52 +0100") References: Message-ID: >>>>> "dimitri" == dimitri pater writes: dimitri> Hello, I am looking for a Python tool to create graphs dimitri> and charts on a webpage. Chartdirector is too expensive dimitri> for me. A simple script for creating a barchart should be dimitri> sufficient as a starting point. matplotlib does barcharts, errorbars, stacked bars, and more (and its free). See the following links # matplotlib with web app servers: http://matplotlib.sourceforge.net/faq.html#APPSERVER # a barchart screenshot with example code http://matplotlib.sourceforge.net/screenshots.html#barchart_demo # the bar command for making bar charts http://matplotlib.sourceforge.net/matplotlib.pylab.html#-bar JDH From jzgoda at gazeta.usun.pl Tue Jan 25 16:06:21 2005 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Tue, 25 Jan 2005 22:06:21 +0100 Subject: snakespell and myspell In-Reply-To: <1106657932.301181.150050@z14g2000cwz.googlegroups.com> References: <1106657932.301181.150050@z14g2000cwz.googlegroups.com> Message-ID: Fuzzyman wrote: > I'm looking to implement a plugin spell checker. > > I'm probably going to go with PyEnchant, as it looks to be the most > promising currently maintained spell checker. > > I just wondered if anyone knew what happened to snakespell and myspell. > Both seem to have dissapeared from the net. People have reported good > results from both - and it seems a shame to lose them. Well, myspell-python is no longer maintained, original author resigned some time ago and I didn't found anybody who would like to take responsibility on this package. I provide myspell-1.0 download from my project page at BerliOS (http://developer.berlios.de/projects/jpa/), but I do not maintain this package. If you look for spell-checking library, I'd consider using python binding for aspell, available at http://www.republika.pl/wmula/proj/aspell-python/ (currently I'm rewriting my program to use python-aspell). This library is actively maintained and Wojtek Mula is active member of Polish Python community. -- Jarek Zgoda http://jpa.berlios.de/ | http://www.zgodowie.org/ From aut_gbarros at uolinc.com Thu Jan 27 09:04:41 2005 From: aut_gbarros at uolinc.com (Gabriel Cosentino de Barros) Date: Thu, 27 Jan 2005 12:04:41 -0200 Subject: Point of Sale Message-ID: <2814F26DA6908F41927A81C410C4991A02079C72@siamun.server.bl.corp.intranet> Hi, i'm curently doing a POS. But mine is a small scale and stand alone. Are you planing on developing in house and then opening? develop at open or simple use open source tools and keep it closed? I'm going to post my progress at source forge next week when i finish proof reading the design docs. i'm curently focused in the HCI layer (primarily using only plain tk) and haven't gave much tought to the 'external' stuff, like integrating wire money cards and such Gabriel -----Original Message----- From: Andreas Pauley [mailto:andreasp at qbcon.com] Sent: quinta-feira, 27 de janeiro de 2005 11:08 To: python-list at python.org Subject: Point of Sale Hi, My company has given me a rather cool project: I have to provide them with an open-source python-based point-of-sale / cash register system that can integrate with their existing ERP backend. The project will include development to ensure that the features they require are included in the open-source POS system. Can you recommend anything that I can use? Regards, Andreas -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From ola.natvig at infosense.no Wed Jan 26 11:06:27 2005 From: ola.natvig at infosense.no (Ola Natvig) Date: Wed, 26 Jan 2005 17:06:27 +0100 Subject: access private field in python 2.4 In-Reply-To: <1106754371.637295.82160@z14g2000cwz.googlegroups.com> References: <1106754371.637295.82160@z14g2000cwz.googlegroups.com> Message-ID: <4prkc2-ini.ln1@pluto.i.infosense.no> ajikoe at gmail.com wrote: > Hello, > I'm new to python, > How can I access private field in python. > > thanks > In python there realy are not private fields. There are those fields that you start with a double underline (__) theese are translated to ___ Withouth the < and > markers, but there are not good practice to access theese through that name. -- -------------------------------------- Ola Natvig infoSense AS / development From aurora00 at gmail.com Sat Jan 22 13:03:27 2005 From: aurora00 at gmail.com (aurora) Date: Sat, 22 Jan 2005 10:03:27 -0800 Subject: list unpack trick? References: Message-ID: Thanks. I'm just trying to see if there is some concise syntax available without getting into obscurity. As for my purpose Siegmund's suggestion works quite well. The few forms you have suggested works. But as they refer to list multiple times, it need a separate assignment statement like list = s.split('=',1) I am think more in the line of string.ljust(). So if we have a list.ljust(length, filler), we can do something like name, value = s.split('=',1).ljust(2,'') I can always break it down into multiple lines. The good thing about list unpacking is its a really compact and obvious syntax. On Sat, 22 Jan 2005 08:34:27 +0100, Fredrik Lundh wrote: ... >> So more generally, is there an easy way to pad a list into length of n >> with filler items appended >> at the end? > > some variants (with varying semantics): > > list = (list + n*[item])[:n] > > or > > list += (n - len(list)) * [item] > > or (readable): > > if len(list) < n: > list.extend((n - len(list)) * [item]) > > etc. > > From benn at cenix-bioscience.com Wed Jan 12 04:48:58 2005 From: benn at cenix-bioscience.com (Neil Benn) Date: Wed, 12 Jan 2005 10:48:58 +0100 Subject: Game programming in Python In-Reply-To: References: Message-ID: <41E4F28A.3000806@cenix-bioscience.com> Baza wrote: >I'm looking for any books or on-line resources on game programming using >Python. Does anyone have any advice? >-- >Computer says, 'no' > > > > Like the end quote : eh, eh, eeehhhhhh!! -- Neil Benn Senior Automation Engineer Cenix BioScience BioInnovations Zentrum Tatzberg 47 D-01307 Dresden Germany Tel : +49 (0)351 4173 154 e-mail : benn at cenix-bioscience.com Cenix Website : http://www.cenix-bioscience.com From steven.bethard at gmail.com Wed Jan 26 18:02:47 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Wed, 26 Jan 2005 16:02:47 -0700 Subject: inherit without calling parent class constructor? In-Reply-To: References: Message-ID: Christian Dieterich wrote: > On D? C?adaoin, Ean 26, 2005, at 13:45 America/Chicago, Steven Bethard > wrote: > >> Note that: >> @deco >> def func(...): >> ... >> is basically just syntactic sugar for: >> def func(...): >> ... >> func = deco(func) > > > Oh, I learned something new today :-) Nice thing to know, these > descriptors. Just a note of clarification: The @deco syntax is called *decorator* syntax. Classes with a __get__ method are called *descriptors*. But yes, they're both nice things to know. ;) Steve From mb at muenster.de Thu Jan 13 16:35:51 2005 From: mb at muenster.de (Martin Bless) Date: Thu, 13 Jan 2005 21:35:51 GMT Subject: Pyrex-0.9.3: definition mismatch with distutils of Python24 Message-ID: <41e6e1c5.8718906@news.muenster.de> Now that I've got my extension building machine using the VC++ Toolkit 2003 up and running I'm keen on using Pyrex (Pyrex-0.9.3, Python-2.4.0). But the definition of the swig_sources() method seems to have changed. When I try to build the examples from Pyrex I get a TypeError: c:\Pyrex-0.9.3\Demos> python Setup.py build_ext --inplace running build_ext building 'primes' extension [...] File "C:\Python24\lib\distutils\command\build_ext.py", line 442, in build_extension sources = self.swig_sources(sources, ext) TypeError: swig_sources() takes exactly 2 arguments (3 given) I can see that Pyrex.Distutils.build_ext.py subclasses distutils.command.build_ext.build_ext, and the number of arguments of the swig_sources method seems to have changed. Pyrex uses: def swig_sources (self, sources): whereas the distutils use: def swig_sources (self, sources, extension): If I just add the "extension" arg to the Pyrex definitions everything seems to work. But I have to admit that I don't really know what I'm doing here and I feel sorry I can't contribute more than just reporting the error. mb - Martin Bless From aleaxit at yahoo.com Sat Jan 22 08:10:36 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 22 Jan 2005 14:10:36 +0100 Subject: Zen of Python References: <972ec5bd050119111359e358f5@mail.gmail.com> <797fe3d405011911465ab59acd@mail.gmail.com> <1106177050.630141.33090@c13g2000cwb.googlegroups.com> <972ec5bd0501191641166972b0@mail.gmail.com> <7xis5szpdj.fsf@ruckus.brouhaha.com> <7xekggbrns.fsf@ruckus.brouhaha.com> <7x651rwbib.fsf@ruckus.brouhaha.com> <7xfz0uqe1d.fsf@ruckus.brouhaha.com> <7xu0p9lk4h.fsf@ruckus.brouhaha.com> Message-ID: <1gqsn7o.qyazai1nh7smmN%aleaxit@yahoo.com> Paul Rubin wrote: > Dave Benjamin writes: > > Can we get a show of hands for all of those who have written or are > > currently maintaining code that uses the leaky listcomp "feature"? > > It's really irrelevant whether anyone is using a feature or not. If > the feature is documented as being available, it means that removing > it is an incompatible change that can break existing code which > currently conforms to the spec. If the "feature" is described as the > bug that it is, anything that relies on it is nonconformant. > > I do remember seeing some cute tricks (i.e. capable of becoming > idioms) that depend on the leakage. Sure, ``if [mo for mo in [myre.search(line)] if mo]: use(mo)`` and the like, used to simulate assign-and-test. No doubt maintaining backwards compat with this kind of horrors means listcomps need to keep leaking until Python 3.0, alas. But hopefully no farther... Alex From daranrife at yahoo.com Fri Jan 28 14:31:44 2005 From: daranrife at yahoo.com (drife) Date: 28 Jan 2005 11:31:44 -0800 Subject: Installing Numeric with ATLAS and LAPACK In-Reply-To: References: <1106928716.562584.56270@z14g2000cwz.googlegroups.com> Message-ID: <1106940704.164253.134630@c13g2000cwb.googlegroups.com> Thanks John. Those are the steps I followed, and to no avail. Interestingly, I downloaded and installed SciPy, and ran the same eigenvector problem. SciPy greatly speeds up the calculation...was 1.5 hours using Numeric, now only 15 min with SciPy. Unfortunately, SciPy only solves ordinary and generalized eigenvalue problems of a square matrix. They do not test to see if the matrix is symmetric, then call the appropriate routine from LAPACK. Daran From littlejohn.75NOSPAM at news.free.fr.invalid Mon Jan 31 11:41:44 2005 From: littlejohn.75NOSPAM at news.free.fr.invalid (F. Petitjean) Date: 31 Jan 2005 16:41:44 GMT Subject: Crude statistics on the standard library Message-ID: <41fe5fc7$0$29873$636a15ce@news.free.fr> I have written a script to find the modules which export the largest number of names. The gc.getreferrers(*objs) function gives also an idea of the dependencies between the modules. The code (statsmod.py) : #!/usr/bin/env python # -*- coding: latin-1 -*- """ statsmod.py module rudimentaire de statistiques des noms export?s par les modules de la biblioth?que standard """ import sys import gc from glob import glob import os, os.path from os.path import basename def browse_stdlib(): """browse the standard library returns list of names of modules """ pyver = 'python%s' % (sys.version[:3],) pyglob = os.path.join(sys.prefix, 'lib', pyver, '*.py') # lpys = glob(pyglob) if os.path.exists(os.path.join(sys.prefix, 'Lib', 'os.pyc')): pyglob = os.path.join(sys.prefix, 'Lib', '*.py') lpys = map(basename, glob(pyglob)) names = [ name[:-3] for name in lpys ] # remove some obsolete modules ('this' + DeprecationWarning) for dontparse in ("this", "tzparse", 'FCNTL', 'posixfile', 'pre', 'regsub', 'statcache', 'TERMIOS', 'xmllib'): try: names.remove(dontparse) except ValueError: continue return names def exports(names, with_modules=False): """imports all the modules in names returns a 2-tuple : - list of tuples : NumberOfExternalNames len(dir(module)) nodname - list of modules (if with_modules is true) """ res = [] add = res.append _all = [] modules = [] # this simple minded method (__import__) doesn't include sys ? for name in names: print name, " ", try: module = __import__(name, globals(), locals(), _all) ldir = len(dir(module)) if hasattr(module, '__all__'): nexports = len(module.__all__) else: nexports = ldir add((nexports, ldir, name)) if with_modules: modules.append(module) # del sys.modules[name] except ImportError, msg: print "cannot import module", name, msg return res, modules def pm_histo(values, nbins=20): """a poor man histogram Return a list of nbins tuples (left, right) such that the union of the consecutive ranges(left, right) is range(len(values)+1) values[k] """ vlo, vhi = values[0], values[-1]+1 nbins = min(nbins, vhi-vlo) deltax = int((vhi - vlo)/nbins) assert deltax > 0 ranges = [] add = ranges.append left = 0 # left index first bin val = vlo + deltax while val < vhi: for right in range(left, len(values)): if values[right] > val: break add((left, right)) left = right val = val + deltax return ranges def basic_stat(seq): """basic statistics on the values in seq Returns NumberOfItems, MeanValue, StandardDeviation, variance """ s0, s1, s2 = 0, 0, 0 for indx, item in enumerate(seq): s0 = s0 + 1 # seq may be an iterable without len Xi = float(item) if not indx: Xmin = Xi s1 = s1 + Xi s2 = s2 + Xi*Xi # s0 = len(seq) # sum of 0 order Xm = s1/s0 # mean value Xmax = Xi median = (Xmin + Xmax)*0.5 variance = (s2 - s0*Xm*Xm)/s0 # ecart-type ** 2 import math stddev = math.sqrt(variance) # ecart-type return s0, Xmin, Xmax, median, Xm, stddev # , variance if __name__ == '__main__': names = ['cStringIO', 'sys', 'gc' ] names.extend(browse_stdlib()) freqs, modules = exports(names, True) print # exports() prints without new line print "%d imported modules and %d in sys.modules" % ( len(freqs), len(sys.modules)) print "number of unreachable objects", gc.collect() simples = [] while modules: module = modules.pop() # print module.__name__, sys.getrefcount(module) items = gc.get_referrers(module) litems = len(items) if litems <= 2: simples.append(module.__name__) del sys.modules[module.__name__], module, items else: print "referrers of %s" % (module.__name__,) for item in items[2:]: name = item.get('__file__', 'unknown') if name.endswith('__init__.pyc'): pslash = name.rfind(os.sep) pslash = name[:pslash].rfind(os.sep) name = name[pslash+1:][:-4] # strip .pyc elif name.endswith('__init__.py'): pslash = name.rfind(os.sep) pslash = name[:pslash].rfind(os.sep) name = name[pslash+1:][:-3] # strip .py elif name.endswith('.pyc'): pslash = name.rfind(os.sep) name = name[pslash+1:][:-4] # strip .pyc elif name.endswith('.py'): pslash = name.rfind(os.sep) name = name[pslash+1:][:-3] # strip .py print name, del module, items print print "number of unreachable objects", gc.collect() print "new length of sys.modules %d" % (len(sys.modules),) print "%d simple modules" % (len(simples),) freqs.sort() values = [item[0] for item in freqs ] # print freqs[-2:] # supprim?s # del values[-2:] ranges = pm_histo(values) ranges2 = [ item for item in ranges if item[1] > item[0]] limite = ranges[0][1] + 1 # first bin rangesbas = pm_histo(values[:95], 6) print rangesbas lbin = 11 start = 0 print "St Nb. min max median average stddev" fmt = "%3d%3d%6.1f%6.1f%8.3f%8.3f%8.3f" while start < len(values): res = (start,) + basic_stat(values[start:start+lbin]) print fmt % res start = start + lbin print "modules with a lot of external names :" for item in freqs[140:]: print item Parts of output of python -i statsmod.py (python2.4 windows) repr rexec rfc822 rlcompleter cannot import module rlcompleter No module named readline robotparser sched ... etc ... whrandom C:\Python24\lib\whrandom.py:38: DeprecationWarning: the whrandom module is deprecated; please use the random module DeprecationWarning) xdrlib xmlrpclib zipfile ... etc ... _threading_local __future__ __phello__.foo Hello world... cannot import module __phello__.foo No module named foo cannot import module __phello__.foo No module named foo number of unreachable objects 0 referrers of __future__ referrers of __future__ ... etc ... referrers of socket asynchat asyncore BaseHTTPServer SocketServer urllib httplib ftplib imaplib nntplib poplib smtpd smtplib Utils ... etc ... referrers of cStringIO logging\__init__ xmlrpclib number of unreachable objects 564 new length of sys.modules 154 121 simple modules [(0, 39), (39, 58), (58, 74), (74, 79), (79, 91), (91, 94)] St Nb. min max median average stddev 0 11 1.0 1.0 1.000 1.000 0.000 11 11 1.0 2.0 1.500 1.545 0.498 22 11 2.0 2.0 2.000 2.000 0.000 33 11 2.0 3.0 2.500 2.455 0.498 44 11 3.0 3.0 3.000 3.000 0.000 55 11 3.0 4.0 3.500 3.727 0.445 66 11 4.0 5.0 4.500 4.273 0.445 77 11 5.0 6.0 5.500 5.818 0.386 88 11 6.0 8.0 7.000 6.909 0.668 99 11 9.0 10.0 9.500 9.545 0.498 110 11 10.0 12.0 11.000 11.182 0.716 121 11 12.0 16.0 14.000 13.818 1.113 132 11 16.0 21.0 18.500 17.636 1.367 143 11 21.0 29.0 25.000 24.818 2.367 154 11 31.0 51.0 41.000 38.364 7.413 165 11 55.0 92.0 73.500 70.636 10.764 176 5 97.0 136.0 116.500 111.400 13.865 modules with a lot of external names : (18, 40, 'cgi') (19, 19, 'cgitb') ... etc ... (72, 72, 'pydoc') (74, 74, 'cookielib') (78, 78, 'urllib2') (86, 86, 'symbol') (92, 92, 'sre_constants') (97, 97, 'xmlrpclib') (101, 118, 'os') (107, 107, 'sre_compile') (116, 116, 'sre_parse') (136, 151, 'socket') Output with python 2.3.3 Linux gives a greater number for socket as the OpenSSL library is wrapped. gc.collect() at the interactive prompt gives 0. (good) Conclusion : sre_compile and sre_parse should be coded with a __all__ attribute The standard library contains a module 'tzparse' which cannot be imported ! Most library modules do not begin with #!/usr/bin/env python and a coding cookie. Regards From just.starting at gmail.com Tue Jan 25 03:38:05 2005 From: just.starting at gmail.com (just starting) Date: Tue, 25 Jan 2005 14:08:05 +0530 Subject: how to call python code from C# In-Reply-To: <41F54FF6.30209@pythonapocrypha.com> References: <8LGdneLOysys1WjcRVn-1Q@powergate.ca> <41F54FF6.30209@pythonapocrypha.com> Message-ID: <3898fa73050125003838dc376c@mail.gmail.com> Thanks for all your kind information. I haven't used COM objects so far.I think now I have to learn it.Anyway thanks a lot again. paritosh. On Mon, 24 Jan 2005 12:43:50 -0700, Dave Brueck wrote: > Peter Hansen wrote: > > paritosh mahana wrote: > > > >> How can I call python code from my C# code. > [snip] > > You could use ctypes or the pywin32 package to provide your > > Python code with an ActiveX interface. Then you could just > > use it via COM, like any other COM object. Lots of references > > available via Google if you want to learn more about this > > approach... > > Lemme add my two cents and say that this approach works well. > > We have a component that uses ctypes and runs as a COM local server (its own > .exe) and we currently use it both from Internet Explorer and from a C# > application. COM can be hairy initially, but if you have any experience with COM > then this approach is pretty straightforward. > > -Dave > -- > http://mail.python.org/mailman/listinfo/python-list > From aleaxit at yahoo.com Sat Jan 22 06:30:36 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 22 Jan 2005 12:30:36 +0100 Subject: Class introspection and dynamically determining function arguments References: <359lfnF4hd6e3U1@individual.net> <359nmoF4koiepU1@individual.net> Message-ID: <1gqsidn.1n13vyo85fvd7N%aleaxit@yahoo.com> Diez B. Roggisch wrote: > Nick Coghlan wrote: > > > > If this only has to work for classes created for the purpose (rather than > > for an arbitrary class): > > Certainly a step into the direction I meant - but still missing type > declarations. And that's what at least I'd like to see - as otherwise you > don't know what kind of editing widget to use for a property. Though it may be overkill for your needs, you'll be interested in Enthought's "Traits", I think; see, for example, . Facilitating such presentation tasks (no doubt including editing) appears to be a major driving force for Traits. Alex From detlev at die-offenbachs.de Sat Jan 29 12:12:41 2005 From: detlev at die-offenbachs.de (Detlev Offenbach) Date: Sat, 29 Jan 2005 18:12:41 +0100 Subject: ANN: eric3 3.6.1 released Message-ID: Hi, this is to let all of you know, that eric3 3.6.1 has just been released. It fixes a few nasty bugs, which were reported since the last release. It is available via http://www.die-offenbachs.de/detlev/eric3.html Eric3 is an Integrated Development Environment for Python. For details please see the above mentioned URL. Regards, Detlev -- Detlev Offenbach detlev at die-offenbachs.de From oceanwavecn at gmail.com Sun Jan 2 10:03:41 2005 From: oceanwavecn at gmail.com (oceanwave) Date: 2 Jan 2005 07:03:41 -0800 Subject: Gate Oxide thickness of CMOS In-Reply-To: <69fbfcd3.0108291911.76f12106@posting.google.com> References: <69fbfcd3.0108291911.76f12106@posting.google.com> Message-ID: <1104678221.272720.73830@c13g2000cwb.googlegroups.com> it's depend on the various product, 200 Angstrom or 30 Angstrom is possible. the number of mask:15 or 30 ^^^^^^ From jeff at ccvcorp.com Thu Jan 27 20:38:49 2005 From: jeff at ccvcorp.com (Jeff Shannon) Date: Thu, 27 Jan 2005 17:38:49 -0800 Subject: Question about 'None' In-Reply-To: <1106873904.761513.153710@z14g2000cwz.googlegroups.com> References: <1106852591.770254.203560@z14g2000cwz.googlegroups.com> <2fCdnYr1l-CZwmTcRVn-ig@comcast.com> <1106873904.761513.153710@z14g2000cwz.googlegroups.com> Message-ID: <10vj5hv8hcn3k9f@corp.supernews.com> flamesrock wrote: > I should also mention that I'm using > version 2.0.1 (schools retro solaris machines :( ) > At home (version 2.3.4) it prints out 'True' for the above code block. That would explain it -- as /F mentioned previously, the special case for None was added in 2.1. Jeff Shannon Technician/Programmer Credit International From spam at nospam.org Thu Jan 27 17:59:45 2005 From: spam at nospam.org (Erik Johnson) Date: Thu, 27 Jan 2005 15:59:45 -0700 Subject: building Python: up arrow broken on SuSE Linux 8.2 References: <41f6c3f7$1@nntp.zianet.com> <41f85dd8@nntp.zianet.com> Message-ID: <41f97058$1@nntp.zianet.com> "Peter Otten" <__peter__ at web.de> wrote... > Have you ensured (with yast) that readline-devel is actually installed? I had not previously, but (not surprisingly) version 4.3 is installed. :) Good idea - I thought maybe I would be able to do an online update (YOU) to it, but it is taking forever to get a patch list. I don't understand it, we have a pretty decent internet connection (DSL). I now have the readline version 5.0 library built locally. Can someone give me some clues about how to get it statically linked? Thanks, -ej From john at grulic.org.ar Tue Jan 18 18:28:14 2005 From: john at grulic.org.ar (John Lenton) Date: Tue, 18 Jan 2005 20:28:14 -0300 Subject: simultaneous multiple requests to very simple database In-Reply-To: References: Message-ID: <20050118232814.GA15780@grulic.org.ar> On Tue, Jan 18, 2005 at 11:26:46AM -0500, Eric S. Johansson wrote: > I have an application where I need a very simple database, effectively a > very large dictionary. The very large dictionary must be accessed from > multiple processes simultaneously. I need to be able to lock records > within the very large dictionary when records are written to. Estimated > number of records will be in the ballpark of 50,000 to 100,000 in his > early phase and 10 times that in the future. Each record will run about > 100 to 150 bytes. > > speed is not a huge concern although I must complete processing in less > than 90 seconds. The longer the delay however the greater number of > processes must be running parallel in order to keep the throughput up. > It's the usual trade-off we have all come to know and love. > > it is not necessary for the dictionary to persist beyond the life of the > parent process although I have another project coming up in which this > would be a good idea. > > at this point, I know they will be some kind souls suggesting various > SQL solutions. While I appreciate the idea, unfortunately I do not have > time to puzzle out yet another component. Someday I will figure it out > because I really liked what I see with SQL lite but unfortunately, today > is not that day (unless they will give me their work, home and cell > phone numbers so I can call when I am stuck. ;-) I'm sure we could agree on a fee for me to do so :) > So the solutions that come to mind are some form of dictionary in shared > memory with locking semaphore scoreboard or a multithreaded process > containing a single database (Python native dictionary, metakit, gdbm??) > and have all of my processes speak to it using xmlrpc which leaves me > with the question of how to make a multithreaded server using stock xmlrpc. berkley db (at least version 3, http://pybsddb.sourceforge.net/) supports multiple readers and writers, with fine-grained locking, it looks like a dictionary, and it isn't sql. The use you have in mind is a bit more complicated than the simple create-me-a-dictionary-in-a-file, but is pretty straightforward. The documentation mostly refers you to the C API, but fortunately it (the C API) is clear and well written. HTH -- John Lenton (john at grulic.org.ar) -- Random fortune: Today is National Existential Ennui Awareness Day. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From irmen at -nospam-remove-this-xs4all.nl Sun Jan 30 09:57:50 2005 From: irmen at -nospam-remove-this-xs4all.nl (Irmen de Jong) Date: Sun, 30 Jan 2005 15:57:50 +0100 Subject: ANN: Frog 1.3 released (python 'blog' application) Message-ID: <41fcf53b$0$28986$e4fe514c@news.xs4all.nl> I've just uploaded the Frog 1.3 release. Frog is a blog (web log) system written in 100% Python. It is a web application written for Snakelets. It outputs XHTML, is fully unicode compatible, small, and doesn't require a database. You can read about it and download it here: http://snakelets.sourceforge.net/frog/ It's 60Kb if you already have Snakelets, otherwise 122Kb. Frog 1.3 uses the same storage format as 1.2 so no conversion is required. If you encounter bugs or problems, or want to give some feedback, please let me know. Enjoy, --Irmen de Jong. PS I'm running Frog for my personal blog, so if you want to see it in action, please visit: http://www.razorvine.net/snake/frog/user/irmen/ (still somewhat experimental and most is in Dutch) From http Wed Jan 12 09:16:48 2005 From: http (Paul Rubin) Date: 12 Jan 2005 06:16:48 -0800 Subject: python and macros (again) [Was: python3: 'where' keyword] References: <1105437966.129342.304400@f14g2000cwb.googlegroups.com> <7xmzvfn096.fsf@ruckus.brouhaha.com> <1105509379.301556.178130@z14g2000cwz.googlegroups.com> Message-ID: <7xoefuenqn.fsf@ruckus.brouhaha.com> michele.simionato at gmail.com writes: > > I can't imagine how it could be worse than the learning curve of > > __metaclass__, which we already have. > > To me, learning macros *and their subtilities* was much more difficult > than learning metaclasses. I guess I've only used Lisp macros in pretty straightforward ways, that weren't hard to understand. That's enough for anything I've needed. But we don't hear much about __metaclass__ because almost nobody understands it. > Go to comp.lang.scheme and google for "macros and module system"; > you will get everything you want to know and much more! OK, I might do this. > Well, I see this as a positive fact. If a syntax is contrived (such > as a ternary operator, for instance) it is better *not* to have it > than to have one hundred custom made syntaxes. At the end, we are > just talking about syntax sugar here, not about lack of > functionality. I think the idea is there would be some experimentation and then one of the versions would make it into the standard library. > > [compiling Lisp to Python bytecode] > This is a bizarre idea if you want to make Python run faster. It is > not so bizarre if what you want is to have access to Python from > Lisp/Scheme in the same sense Jython has access to Java. Why not just use a foreign function interface? From tim.golden at viacom-outdoor.co.uk Thu Jan 20 13:58:25 2005 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Thu, 20 Jan 2005 18:58:25 -0000 Subject: Print to Windows default Printer Message-ID: <9A28C052FF32734DACB0A288A35339910359D9@vogbs009.gb.vo.local> [Samantha] | The printer is on LPT1, but I sure can't get the temp file to | print for some | reason. | I am using Windows XP SP2. | S i'm afraid I have to step out here (metaphorically speaking): I'm using Win2K and have no access to XP boxes. The technique works fine here; it may be that either they've removed the functionality under XP, or that there's some security context which is preventing you from accessing the port. Can anyone else try a "PRINT blah" or a "COPY blah LPT1:" on XP SP2? TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From steven.bethard at gmail.com Sun Jan 2 04:22:59 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Sun, 02 Jan 2005 09:22:59 GMT Subject: PEP 288 ponderings In-Reply-To: References: Message-ID: Raymond Hettinger wrote: > [Steven Bethard] >>(2) Since in all the examples there's a one-to-one correlation between >>setting a generator attribute and calling the generator's next function, >>aren't these generator attribute assignments basically just trying to >>define the 'next' parameter list? > > They are not the same. The generator needs some way to receive the values. The > function arguments cannot be used because they are needed to create the > generator-iterator. The yield statements likewise won't work because the first > yield is not encountered until well after the first next() call. Yeah, I wasn't trying to claim that passing the arguments to .next() is equivalent to generator attributes, only that the point at which new values for the generator state variables are provided correspond with calls to .next(). So if there was a means within a generator of getting access to the arguments passed to .next(), generator attributes would be unnecessary for the examples provided. > The given examples are minimal and are intended only to demonstrate the idea. Do you have an example where the generator state isn't updated in lock-step with .next() calls? I'd be interested to look at an example of this... >>I definitely don't like the >>idea of a magical __self__ variable that isn't declared anywhere. > > It is no more magical than f.__name__ or f.__doc__ for functions. I'm not sure this is quite a fair parallel. The difference here is that f.__name__ and f.__doc__ are accessed as attributes of the f object, and the __name__ and __doc__ attributes are created as a result of function creation. The proposed __self__ is (1) not an attribute that becomes available, rather, a new binding local to the function, and (2) not created as a result of generator object creation but created as a result of calling .next() on the generator object. > Also, the __self__ argument is a non-issue because there are other alternate > approaches such as providing a function that retrieves the currently > running generator. Is there a discussion of some of these alternate suggested approaches somewhere you could point me to? > The more important part of the PEP is the idea for generator exceptions. The > need arises in the context of flushing/closing resources upon generator > termination. I wonder if maybe it would be worth moving this part to a separate PEP. It seems like it could probably stand on its own merit, and having it in with the generator attributes PEP means it isn't likely to be accepted separately. Of course, I would probably declare a class and provide a .close() method. =) Steve From tim.peters at gmail.com Wed Jan 19 23:54:58 2005 From: tim.peters at gmail.com (Tim Peters) Date: Wed, 19 Jan 2005 23:54:58 -0500 Subject: Zen of Python In-Reply-To: <7xis5szpdj.fsf@ruckus.brouhaha.com> References: <972ec5bd050119111359e358f5@mail.gmail.com> <797fe3d405011911465ab59acd@mail.gmail.com> <1106177050.630141.33090@c13g2000cwb.googlegroups.com> <972ec5bd0501191641166972b0@mail.gmail.com> <7xis5szpdj.fsf@ruckus.brouhaha.com> Message-ID: <1f7befae05011920543bb58720@mail.gmail.com> [Paul Rubin] > Huh? [1,2,[3,4,5],[6,[[[[7]],8]]]] is a perfectly valid Python list. You're claiming not to know any relevant difference between Python lists and Lisp lists? Heh. > And you can break out of a containing loop from a nested loop > with try/raise. Heh heh. Yes, you can. I've never seen a real Python program that did, but there's nothing to stop you. What did you think the "direct" in "direct way" might have been intended to mean? > More troublesome is not being able to see a variable in a > containing scope from a nested scope, unless the containing > scope is the global one. Why bother debating lexical scope for > years before deciding to add it, only to stop halfway? I'd call it 80% of the way, but suit yourself. The debates are all easily found, if you really want to know. From devries at idolstarastronomer.com Sun Jan 23 14:43:06 2005 From: devries at idolstarastronomer.com (Christopher De Vries) Date: Sun, 23 Jan 2005 14:43:06 -0500 Subject: make install with python In-Reply-To: References: <35d4i9F4makucU1@individual.net> Message-ID: <20050123194306.GA1296@miyu.cjas.org> On Sat, Jan 22, 2005 at 01:54:17AM +0100, Uwe Mayer wrote: > Any suggestions how I handle uninstallation? This was provided by automake > rather mechanically. I didn't find a section on that in the distutils > documentation... :( I've been using distutils for a couple of projects I've written for work. Overall I love it as I rarely have to consult documentation (I always need to look at documentation to use autoconf, though I must admit I have only used autoconf/automake on two projects). On the distutils2.0 Wiki page (http://www.python.org/moin/DistUtils20) I found the quote: "Uninstallation is solved as soon as we have an installation database, which is part of what we're trying to do here." -- BobIppolito So it looks like they are working on it. Chris From removethis.kartic.krishnamurthy at gmail.com Thu Jan 20 20:34:17 2005 From: removethis.kartic.krishnamurthy at gmail.com (Kartic) Date: Fri, 21 Jan 2005 01:34:17 GMT Subject: Print a string in binary format In-Reply-To: <1106268802.094106.122090@c13g2000cwb.googlegroups.com> References: <1106268802.094106.122090@c13g2000cwb.googlegroups.com> Message-ID: neutrino said the following on 1/20/2005 7:53 PM: > Greetings to the Python gurus, > > I have a binary file and wish to see the "raw" content of it. So I open > it in binary mode, and read one byte at a time to a variable, which > will be of the string type. Now the problem is how to print the binary > format of that charater to the standard output. It seems a common task > but I just cannot find the appropriate method from the documentation. > Thanks a lot. Not a guru, but I will try to help out :-) how about this: >>> import binhex >>> binhex.binhex('C:/windows/system32/telnet.exe', 'C:/TEMP/telnet.hex') >>> Now this is what telnet.hex looks like: (This file must be converted with BinHex 4.0) :#R4PE'jPG#jPH'8!2j!)!!!!!4B!N!@9[deDN!!!!`!!!!3!!!$rr`!!Z!#3"d! !N#2J!!!!$Kqk$J#d#FdKZ!&-c5&8D'Pc)("bEfGbB at dJBf&ZEQpd)'*P)(*eEL" TEL"%6e-JE at pNC5i0$3SN!*!(Q$X`mpaDAU$F at PkJh&THS#Cj(U$G at PkJh&TIS'P DAU!QH8HJceTHS%Yj'k$G at PkJ"RP#S-TDAU!'H81Jh9THS#CjBk$G at PkJ8QPMD0a DAU!!N""343!!6!%$!&VGE6d!N!MJ!!m"#`%(!!$!!!!!"J)!N!AQ[3!!!"!!!!$ 3!*!&!3!3!!!!!J!!"3!"!!8!!3!%!*!)i!)!!!3!!&Hl!3!$!!#!!!!%!!!3!*! %%!!!%!#3"K!!N!Z3!-%!!-J!N!5J!J"B1!#3'[!5!!!F!*!M8!)!!-`!N!33!!$ F!J#3'LjdCAKd!!!!rVm!!!!3!!!!`!!!!!3!N!iJ!!"J,Q4KG'%!!!"mb`%!!0! (... Big Snip ...) Or how about this? >>> f = open('C:/windows/system32/telnet.exe', 'rb') >>> fcontents = f.read() >>> import binhex >>> print binhex.binascii.hexlify(fcontents[0:10]) '4d5a9000030000000400' >>> Is this what you want??? Thanks, --Kartic From tzot at sil-tec.gr Mon Jan 3 14:11:10 2005 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Mon, 03 Jan 2005 21:11:10 +0200 Subject: BASIC vs Python References: <1103327631.570908.321770@c13g2000cwb.googlegroups.com> Message-ID: <9q5jt09llq0ak9h587d2ctvq29r2ag85t9@4ax.com> On 17 Dec 2004 15:53:51 -0800, rumours say that "ladasky at my-deja.com" might have written: >> The BASICs of my youth also supported graphics and sounds. >> >> PLAY "CGFED>CC >Now wait a minute, shouldn't that be... > >PLAY "CGFED>CC': 2.0} # octave modifier def play(sequence): """Play a sequence of notes.""" octave=1.0 for note in sequence: try: # to play a note winsound.Beep(int(round(notes[note]*octave)), 200) except KeyError: # well, it wasn't octave *= modifiers[note] if __name__ == "__main__": play("CGFED>CC" and "<" for example if I got them correctly). [1] and then I "inherited" a Stride with an 68010 from a student friend who finished studies and got drafted, who himself had it borrowed from the company of a friend of his so that he would develop code that could be used by the company, and in general all my troubles seem to come from exposure to Unix in my puberty, but that's another story :) -- TZOTZIOY, I speak England very best. "Be strict when sending and tolerant when receiving." (from RFC1958) I really should keep that in mind when talking with people, actually... From rkern at ucsd.edu Fri Jan 28 20:29:22 2005 From: rkern at ucsd.edu (Robert Kern) Date: Fri, 28 Jan 2005 17:29:22 -0800 Subject: LinearAlgebra incredibly slow for eigenvalue problems In-Reply-To: <1106960619.700424.278180@z14g2000cwz.googlegroups.com> References: <1106887513.865901.154760@z14g2000cwz.googlegroups.com> <1106952951.834888.65430@f14g2000cwb.googlegroups.com> <1106957598.136667.45430@z14g2000cwz.googlegroups.com> <1106957760.485860.104760@f14g2000cwb.googlegroups.com> <1106960619.700424.278180@z14g2000cwz.googlegroups.com> Message-ID: drife wrote: > David, > > I noticed that the libraries that ATLAS builds are not shared > objects (e.g., liblapack.a). Should these be shared objects? > I see nothing in the ATLAS documentation about building > things as shared objects. > Wondering if this is why the Numeric install is failing. No, they should work just fine as static libraries. -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From peter at engcorp.com Wed Jan 26 10:33:08 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 26 Jan 2005 10:33:08 -0500 Subject: is there better 32 clock() timing? In-Reply-To: References: <41f61372.1768192005@news.oz.net> Message-ID: Stephen Kellett wrote: >>> that time.clock() is inaccurate. The problem is that the "time.clock()" >>> statement takes several hundred microseconds to execute. > > The statement is incorrect. clock() itself isn't slow, but it is > accessing a resource, the accuracy of which is no better than 1ms. > > There are various timers available, documented and undocumented, all of > which end up at 1ms or 1.1ms, give or take. For anything shorter you > need QueryPerformanceCounter() (but that *is* a slow call), or use the > RDTSC instruction which is fast but gives a count of instruction cycles > executed and is thus not totally accurate (multiple execution pipelines, > plus multithreading considerations). (I've read the five or so following messages you and Bengt have posted, but not in detail so I'm not sure where you're going with all this, but... ) According to the docs for time.clock(), "On Windows, this function returns wall-clock seconds elapsed since the first call to this function, as a floating point number, based on the Win32 function QueryPerformanceCounter(). The resolution is typically better than one microsecond." Depending on whether you really meant "accuracy" above, and on other things, this is either irrelevant, or contradicts your first statement... -Peter From ncoghlan at iinet.net.au Thu Jan 6 06:58:46 2005 From: ncoghlan at iinet.net.au (Nick Coghlan) Date: Thu, 06 Jan 2005 21:58:46 +1000 Subject: Deferred expressions (was Re: Lambda as declarative idiom) In-Reply-To: <41dc4099.75876003@news.oz.net> References: <3A81C87DC164034AA4E2DDFE11D258E3024F6B@exchange.hqamor.amorhq.net> <41dc4099.75876003@news.oz.net> Message-ID: <41DD27F6.6040700@iinet.net.au> Bengt Richter wrote: > I like the fact that 'def' can serve as a mnemonic for 'defer' or 'deferred' ;-) Yeah, me too. I didn't actually notice that until after I'd thought of the phrase. > OTOH, I like concise notation for expressions, and the def and from aren't > really necessary if you can tag the first expression with some syntax marker. > I suggested (: rather than (def since (: is illegal now and won't break anything. True, but I've always liked Python's preference for keywords over punctuation. And 'def' is only 2 characters longer than ':', too. > That is an advantage of having it inside the outer parens, which my (:expr)(params) > couldn't benefit from -- unless I just take your format and substitute ':' for > both def and from: But where does that leave "Python is executable pseudocode"? Compare: (lambda (a, b, c) : f(a) + o(b) - o(c)) (: f(a) + o(b) - o(c) : (a, b, c)) (def f(a) + o(b) - o(c) from (a, b, c)) Which of the above most clearly expresses "defer a functional expression taking arguments a, b, and c"? For comparison, named syntax requires 3 lines, since Guido also wants to remove suite one-liners in Py3k: def f1(a, b, c): return f(a) + o(b) - o(c) f1 Not so bad for a single deferred expression (particularly a not-completely-trivial one like this), but fares significantly worse for simple zero-argument functions, or if you are just setting up a couple of deferred expressions in a function call. There's no more virtue in completely squandering vertical screen real estate than there is in being overly conservative with it. > What was the point of all this again? Pretending lambda goes away without really killing it? ;-) Actually, it was started by the "please don't take our lamdbas!" comments regarding Python 3k. I suggested that one of the problems with lambda is that it is an expression but looks like a one-liner statement ("it's ugly as sin" may have been closer to my actual phrasing), that the syntax would be deservedly rejected if proposed as a new addition to the language, and a more productive response might be to consider nicer alternative syntax that Guido would consider retaining in Python 3k (since it would make sense to try out such a syntax in the Python 2.x series before committing to it for 3.0). Of course, after making that suggestion, my brain decided to start working on its *own* ideas for a more Pythonic syntax (trying to learn from generator expressions), which seemed to set off a few other people :) The name 'deferred expression' is intended to emphasise what I see as the most appropriate application for anonymous functions - using an entire named function statement to defer a simple expression is serious overkill. Recognising this use case was what switched me from "I won't miss lambdas" to "You know, I'd really regret it if they disappeared completely". Basically, I think lambda has a PR problem - its usefulness as a way to defer expression evaluation is obscured by its ugly syntax and its current explanation as "a neutered form of function definition, but at least you can use it in an expression". On backticks, they have a major problem in that many fonts make ` and ' virtually indistinguishable. A secondary problem is that printed text often renders an opening single quote like a backtick. Guido has already mentioned this in one of Python Regrets talks (in the context of the backtick repr syntax). So I don't expect any syntax involving backticks to even be looked at by the BDFL. Cheers, Nick. -- Nick Coghlan | ncoghlan at email.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.skystorm.net From gstoyanoff at gmail.com Thu Jan 27 19:39:01 2005 From: gstoyanoff at gmail.com (g_xo) Date: Thu, 27 Jan 2005 19:39:01 -0500 Subject: Hello Message-ID: Hello everyone, I am a python beginner and look forward to learning the language and working on some interesting projects using it. I was wondering if anybody may help me get access to the news group comp.lang.python I am trying to access it using KNode but I get an "unable to resolve host name" error. Thank you. George +------------------------------------------------+ Linux - the future is free +------------------------------------------------+ From bulba at bulba.com Tue Jan 4 13:13:52 2005 From: bulba at bulba.com (Bulba!) Date: Tue, 04 Jan 2005 19:13:52 +0100 Subject: The Industry choice References: <1104425916.615972.97530@z14g2000cwz.googlegroups.com> <1gpsbr7.1otvj5mkq1l96N%aleaxit@yahoo.com> Message-ID: On Sun, 2 Jan 2005 23:59:53 -0800, "Eric Pederson" wrote: >I'm decades behind on economics research, but I remember >modeling clustering based on mass and distance (the gravity model). >On a decision making basis there seems to be an aspect of it that is >binary: (0) either give in to gravity and gain shared advantage as >part of a massive object, or (1) choose an alternate "location" far >enough away not to be much affected by the force of the massive >objects, and try to build "mass" there. I suspect Python is a (1) in >that regard, but I may be wrong. Frankly, I find such models to be built on over-stretched analogies to physics - how _exactly_ is gravity supposed to be an analogy equivalent to economic "forces"? Sure such model can be built - but is it adequate in explaining real-world phenomenons? Analogy tends to be the weakest form of reasoning. I'd be wary of making such analogies. Models like this probably tend to be built by French engineers from this joke: The American and French engineers work together on some product (that would look strange nowadays but it's not impossible in principle). The Americans show the French engineers a working prototype. The French engineers scratch their heads and ask warily: "OK, it works in practice; but will it work in theory?" -- Real world is perfectly indifferent to lies that are the foundation of leftist "thinking". From tjreedy at udel.edu Sat Jan 22 18:36:12 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 22 Jan 2005 18:36:12 -0500 Subject: need help on need help on generator... References: <63b5e209.0501210558.686f5c10@posting.google.com><1gqsbex.hooytt14zucw2N%aleaxit@yahoo.com> <200501221106.49241.francis.girard@free.fr> Message-ID: "Francis Girard" wrote in message news:200501221106.49241.francis.girard at free.fr... >If I understand correctly, Almost... > a "generator" produce something over which you can > iterate with the help of an "iterator". To be exact, the producer is a generator function, a function whose body contains 'yield'. In CPython, the difference after executing the def is that a generator function has a particular flag set. People sometimes shorten 'generator function' to 'generator' as you did, but calling both a factory and its products by the same name is confusing. (For instance, try calling an automobile factory an automobile). >>> def genf(): yield 1 ... >>> genf The result of calling a generator function is a generator, which is one but only one type of iterator. >>> gen = genf() >>> gen >>> dir(gen) [, '__iter__', ' gi_frame', 'gi_running', 'next'] The .__iter__ and .next methods make this an iterator. The two data attributes are for internal use. > Can you iterate (in the strict sense >of an "iterator") over something not generated by a "generator" ? Of course. Again, a generator is one specific type of iterator, where an iterator is anything with the appropriate .__iter__ and .next methods. Terry J. Reedy From jean.rossier at epfl.ch Wed Jan 19 04:40:55 2005 From: jean.rossier at epfl.ch (jean.rossier at epfl.ch) Date: Wed, 19 Jan 2005 10:40:55 +0100 Subject: problem with import pylab from a website Message-ID: <1106127655.41ee2b2758a9a@imapwww.epfl.ch> Hello All, I am facing a problem while importing pylab library(in a .py program file) via web browser however the same program works when I execute it from the command prompt. my configuration : Fedora Core 3 Apache 2.0 python 2.3.4 postgresql 7.3.4 mod_python-3.1.3-5 Error message we get: [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] Traceback (most recent call last):, referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] File "/var/www/html/sensor_data/get_graph.py", line 15, in ?, referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] , referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] import pylab, referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] File "/usr/lib/python2.3/site-packages/pylab.py", line 1, in ?, referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] , referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] from matplotlib.pylab import *, referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] File "/usr/lib/python2.3/site-packages/matplotlib/pylab.py", line 184, in ?, referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] , referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] from axes import Axes, PolarAxes, referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] File "/usr/lib/python2.3/site-packages/matplotlib/axes.py", line 14, in ?, referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] , referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] from axis import XAxis, YAxis, referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] File "/usr/lib/python2.3/site-packages/matplotlib/axis.py", line 20, in ?, referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] , referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] from font_manager import FontProperties, referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] File "/usr/lib/python2.3/site-packages/matplotlib/font_manager.py", line 942, in ?, referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] , referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] fontManager = FontManager(), referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] File "/usr/lib/python2.3/site-packages/matplotlib/font_manager.py", line 786, in __init__, referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] , referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] rebuild(), referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] File "/usr/lib/python2.3/site-packages/matplotlib/font_manager.py", line 780, in rebuild, referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] , referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] pickle.dump(self.ttfdict, file(ttfcache, 'w')), referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] IOError, referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] : , referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] [Errno 13] Permission denied: '/usr/share/matplotlib/.ttffont.cache', referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] , referer: http://128.178.156.101/sensor_data/readings.php [Wed Jan 19 09:43:58 2005] [error] [client 128.178.156.101] Premature end of script headers: get_graph.py, referer: http://128.178.156.101/sensor_data/readings.php Thanks in advance. Regards, jean From kartic.krishnamurthy at gmail.com Thu Jan 6 07:10:45 2005 From: kartic.krishnamurthy at gmail.com (Kartic) Date: 6 Jan 2005 04:10:45 -0800 Subject: navigating/changing directories In-Reply-To: References: Message-ID: <1105013445.219752.99060@z14g2000cwz.googlegroups.com> > /this/directory when I exit the script. Is it possible to have a script > that can drop me off into a different directory than where I initiated it > from? Use os.chdir(newpath) So, you can code os.chdir(r'/a/totally/different/directory') and find yourself in /a/totally/different/directory after the script completes. Thanks, --Kartic From steven.bethard at gmail.com Wed Jan 26 15:41:20 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Wed, 26 Jan 2005 13:41:20 -0700 Subject: can not use __methods__ In-Reply-To: <1106769790.604491.290680@c13g2000cwb.googlegroups.com> References: <1106769790.604491.290680@c13g2000cwb.googlegroups.com> Message-ID: ajikoe at gmail.com wrote: > I try to use __methods__ in python 2.4 and 2.2 it always fail. > Can some one tell me if I want to itterate the methods in a class and > print it in a string format ( it is possible using __methods__ ). > Is there any replacement? py> class C(object): ... a = 1 ... b = 2 ... def f(self): ... pass ... def g(self): ... pass ... py> import inspect py> for attr, value in C.__dict__.iteritems(): ... if inspect.isroutine(value): ... print attr, value ... g f or: py> for attr, value in vars(C).iteritems(): ... if inspect.isroutine(value): ... print attr, value ... g f or if you want to include special methods: py> for attr in dir(C): ... value = getattr(C, attr) ... if inspect.isroutine(value): ... print attr, value ... __delattr__ __getattribute__ __hash__ __init__ __new__ __reduce__ __reduce_ex__ __repr__ __setattr__ __str__ f g This is probably useful for introspection at the Python prompt, but if you're planning on doing this in your code somewhere, you might present the problem you're trying to solve to the list, because this is likely not the best way to approach it... Steve From john.thingstad at chello.no Fri Jan 14 06:03:15 2005 From: john.thingstad at chello.no (John Thingstad) Date: Fri, 14 Jan 2005 12:03:15 +0100 Subject: huygens lands on titan Message-ID: -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ From lee at example.com Wed Jan 5 17:41:15 2005 From: lee at example.com (Lee Harr) Date: Wed, 05 Jan 2005 22:41:15 GMT Subject: get the IP address of a host References: Message-ID: On 2005-01-05, none <""> wrote: > I want to determine the outside (non local, a.k.a. 127.0.0.x) ip > addresses of my host. It seems that the socket module provides me with > some nifty tools for that but I cannot get it to work correctly it seems. > > Can someone enlightened show a light on this: > > import socket > def getipaddr(hostname='default'): > """Given a hostname, perform a standard (forward) lookup and return > a list of IP addresses for that host.""" > if hostname == 'default': > hostname = socket.gethostname() > ips = socket.gethostbyname_ex(hostname)[2] > return [i for i in ips if i.split('.')[0] != '127'][0] > > It does not seem to work on all hosts. Sometimes socket.gethostbyname_ex > only retrieves the 127.0.0.x ip adresses of the local loopback. Does > someone has a more robust solution? > > Targetted OS'es are Windows AND linux/unix. I found that the socket solutions only work if your DNS entries are correct ... which in my case was not true. So I came up with this: import commands ifconfig = '/sbin/ifconfig' # name of ethernet interface iface = 'eth0' # text just before inet address in ifconfig output telltale = 'inet addr:' def my_addr(): cmd = '%s %s' % (ifconfig, iface) output = commands.getoutput(cmd) inet = output.find(telltale) if inet >= 0: start = inet + len(telltale) end = output.find(' ', start) addr = output[start:end] else: addr = '' return addr Basically, it scrapes the output from ifconfig for the actual address assigned to the interface. Works perfectly on FreeBSD and Linux (given the correct configuration). From jjl at pobox.com Sun Jan 30 17:19:23 2005 From: jjl at pobox.com (John J Lee) Date: Sun, 30 Jan 2005 22:19:23 +0000 (GMT) Subject: RFC 2965 cookies, cookielib, and mailman. Message-ID: Just noticed your c.l.py post quoted below. Nobody but me knows or cares about this obscure stuff ;-) so I'm not surprised you got no answer... C. Titus Brown Dec 27 2004, 12:41 pm wrote: [...] > The issue turned out to be that mailman sends out RFC 2965 [1] cookies, > which are by default rejected by cookielib. I don't remotely pretend to > understand the issues involved; hence my post ;). > > A few questions for those more clued in than me: > > * what is the difference between RFC 2965 cookies and others? See "Where can I find out more about the HTTP cookie protocol?" here: http://wwwsearch.sourceforge.net/ClientCookie/ For both very short, slightly longer (first link in that section, to a section of the ClientCookie docs on the cookie standards), and insanely detailed (Kristol's paper) explanations. > * why would mailman implement RFC 2965 cookies over the old format? > (I'm guessing simply because it's the latest/best/format?) Because Barry didn't realise that almost no browsers implement it (and never will), I guess. > * why would cookielib NOT accept RFC 2965 cookies by default? See above: browsers don't implement it. It's essentially dead as an internet standard. The only real standard is "what IE and Mozilla do", plus some wisdom from RFCs 2109, 2965 and (more readably!) 2964. [...] > In any case, the way to make the cookielib example work for mailman is > like so: > > policy = cookielib.DefaultCookiePolicy(rfc2965=True) > cj = cookielib.LWPCookieJar('cookies.lwp', policy=policy) Hmm, cookielib should work if IE and Mozilla do, so that's a bug :( You shouldn't need to turn on 2965 handling. Do you have a script that demonstrates the problem, so I can fix it? Thanks John From mambuhl at earthlink.net Fri Jan 28 19:02:07 2005 From: mambuhl at earthlink.net (Martin Ambuhl) Date: Fri, 28 Jan 2005 19:02:07 -0500 Subject: what's OOP's jargons and complexities? In-Reply-To: References: <1106953849.915440.134710@f14g2000cwb.googlegroups.com> Message-ID: <360244F4lolueU1@individual.net> Dan Perl wrote: > Actually, it can be as simple as: > public class test { There is no "public" or "class" in C. Please don't post such trash to comp.lang.c. In fact, C++ is not topical in any of the five newsgroups you posted to. I don't know where you're posting from, so I apologize to the perl, python, lisp, scheme, and C people who see this in their newsgroups. Followup-To set to comp.lang.c++ where you can play with your bloated language all you wish. From jeff at ccvcorp.com Fri Jan 7 14:33:42 2005 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 07 Jan 2005 11:33:42 -0800 Subject: The Industry choice In-Reply-To: <7xhdluuq3k.fsf@ruckus.brouhaha.com> References: <25mlt05vtce42ohljk32qish66oj9bq049@4ax.com> <7xvfach813.fsf@ruckus.brouhaha.com> <10trej2fl8dip65@corp.supernews.com> <7xhdluuq3k.fsf@ruckus.brouhaha.com> Message-ID: <10ttomdd6mp7711@corp.supernews.com> Paul Rubin wrote: > Jeff Shannon writes: > >>Note that the so-called 'viral' nature of GPL code only applies to >>*modifications you make* to the GPL software. > > > Well, only under an unusually broad notion of "modification". True enough. It can be difficult, in software development, to define a distiction between a situation where two software products are distinct but cooperative, and a situation where one software product is derivative of another. Stallman has chosen a particular definition for use in the GPL; one may debate the value of using this definition over any other possible definition, but the line had to be drawn *somewhere*. (And given Stallman's philosophies, it shouldn't be too surprising that he's drawn it about as broadly as he reasonably could.) >>(Problems may come if someone licenses a library under the GPL; that's >>what the LGPL was invented for. But the issue here is not that the >>GPL is bad, it's that the author used the wrong form of it.) > > > The "problem" is not a problem except that in the case of some > libraries, simply being able to use a library module is often not > enough incentive to GPL a large application if the library module's > functionality is available some other way (including by > reimplemntation). If the library does something really unique and > difficult, there's more reason to GPL it instead of LGPL'ing it. To my mind, the intent of the GPL is "use it, but if you change it or make a derivative, share the changes". With libraries, though, you *can't* use it without hitting the FSF-specified definition of a derivative. The LGPL exists to make it clear that, for libraries, the common meaning of "using" and "changing" are different than they are for applications. Of course, there's nothing that stops people from insisting that, if you *use* their libraries, anything you use them for must be free-as-in-speech (which is the effect of using the GPL instead of the LGPL); it's the author's choice what restrictions should be put on the software. But the usage-restrictions on a library under GPL are more severe than they are on an application under GPL. The unfortunate thing, in my opinion, is that a fair number of library authors don't think about that when they GPL their code. Jeff Shannon Technician/Programmer Credit International From cartermark46 at ukmail.com Mon Jan 10 06:22:57 2005 From: cartermark46 at ukmail.com (Mark Carter) Date: Mon, 10 Jan 2005 11:22:57 +0000 Subject: Port blocking Message-ID: <34f6sgF4asjm7U1@individual.net> Supposing I decide to write a server-side application using something like corba or pyro. What's the chance that in big corporations, the client's ports (in both senses of the word: fee-paying, and application) will be blocked, thereby immediately scuppering whatever I have written? Has this problem ever arisen for anyone? Also, is there a good tool for writing database UIs? From dhwild at argonet.co.uk Fri Jan 28 15:41:36 2005 From: dhwild at argonet.co.uk (David H Wild) Date: Fri, 28 Jan 2005 20:41:36 +0000 (GMT) Subject: Talking to the wind References: <1106854625.289187.28710@z14g2000cwz.googlegroups.com> <1106875259.426213.252030@z14g2000cwz.googlegroups.com> Message-ID: <4d3481485adhwild@argonet.co.uk> In article , Terry Reedy wrote: > > Xah Lee, > > > > Do you want to be taken seriously? > > First, stop posting. > > Second, learn perl. > > Third, learn python. > Hey all, I have seen no evidence that XL even reads the responses that > have been directed thereto. The above is like > /dev/null, > Why don't you ever answer the messages I keep sending to you? He's been in my killfile for quite some time. If **everyone** ignored him, this newsgroup would be a better place. :-)) -- __ __ __ __ __ ___ _____________________________________________ |__||__)/ __/ \|\ ||_ | / Acorn StrongArm Risc_PC | || \\__/\__/| \||__ | /...Internet access for all Acorn RISC machines ___________________________/ dhwild at argonet.co.uk From apardon at forel.vub.ac.be Fri Jan 14 03:24:17 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 14 Jan 2005 08:24:17 GMT Subject: python and macros (again) [Was: python3: 'where' keyword] References: <1105437966.129342.304400@f14g2000cwb.googlegroups.com> <7xmzvfn096.fsf@ruckus.brouhaha.com> Message-ID: Op 2005-01-13, Terry Reedy schreef : > > "Antoon Pardon" wrote in message > news:slrncucmeo.5qu.apardon at rcpc42.vub.ac.be... >> Op 2005-01-13, Fredrik Lundh schreef : >>> Antoon Pardon wrote: >>> >>>> Well, it seems that Guido is wrong then. The documentation clearly >>>> states that an expression is a statement. >>> >>> no, it says that an expression statement is a statement. if you don't >>> understand the difference, please *plonk* yourself. >> >> And what else is an expression statement but an expression (list) used >> as a statement. > > Whereas an expression used within a statement is not a statement, and that > is the difference. > > And of course, statements, in general, are not expressions and are not used > within statements (except within compound statements). Here you are stating the opposite of what Guido is supposed to have said. IMO we have a: dogs are mamals kind of relationship in Python. Every expression can be used where a statement is expected. (And this can be worded as: every expression is a statement.) Not every statement can be used where an expression is expected. -- Antoon Pardon From max at alcyone.com Mon Jan 24 17:01:39 2005 From: max at alcyone.com (Erik Max Francis) Date: Mon, 24 Jan 2005 14:01:39 -0800 Subject: Looking for Form Feeds In-Reply-To: References: Message-ID: Greg Lindstrom wrote: > I have a file generated by an HP-9000 running Unix containing form feeds > signified by ^M^L. I am trying to scan for the linefeed to signal > certain processing to be performed but can not get the regex to "see" > it. Suppose I read my input line into a variable named "input" > > The following does not seem to work... > input = input_file.readline() > if re.match('\f', input): print 'Found a formfeed!' > else: print 'No linefeed!' > > I also tried to create a ^M^L (typed in as Q M L) but that > gives me a syntax error when I try to run the program (re does not like > the control characters, I guess). Is it possible for me to pull out the > formfeeds in a straightforward manner? What's happening is that you're using .match, so you're only checking for matches at the _start_ of the string, not anywhere within it. It's easier than you think actually; you're just looking for substrings, so searching with .find on strings is probably sufficient: if line.find('\f') >= 0: ... If you want to look for ^M^L, that'd be '\r\f': if line.find('\r\f') >= 0: ... If you want to keep a running count, you can use .count, which will count the number of substrings in the line. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis I would have liked to have seen Montana. -- Capt. Vasily Borodin From http Mon Jan 10 00:29:26 2005 From: http (Paul Rubin) Date: 09 Jan 2005 21:29:26 -0800 Subject: Python Operating System??? References: <10trb0mgiflcj4f@corp.supernews.com> <10tteh884ivk6c9@corp.supernews.com> <7xr7kx0w4m.fsf@ruckus.brouhaha.com> <7xhdlss0tl.fsf@ruckus.brouhaha.com> <7x8y734jlq.fsf@ruckus.brouhaha.com> <7xr7kv8bmt.fsf@ruckus.brouhaha.com> <7xr7kvm72c.fsf@ruckus.brouhaha.com> <7x6526otw3.fsf@ruckus.brouhaha.com> <7xvfa53obd.fsf@ruckus.brouhaha.com> Message-ID: <7x3bx9c0nd.fsf@ruckus.brouhaha.com> Arich Chanachai writes: > > And I think Pypy is currently set up to compile Python > >into Pyrex and then run the Pyrex results through GCC. > > > But of course, who's going to argue that Pyrex produces "compiled > Python"? Pyrex produces compiled Python in the same sense that asm produces "compiled C". PyPy contains a Python compiler which reads Python source and produces Pyrex output. The Pyrex output then gets compiled by the Pyrex compiler and then the C compiler before ending up with machine code. There is nothing terribly bizarre about this kind of compiler. For example, Gnu Common Lisp compiles Lisp code into C, then runs the C code through gcc. For that matter, the Yacc/Bison parser generators do something similiar. From timr at probo.com Sun Jan 9 03:05:51 2005 From: timr at probo.com (Tim Roberts) Date: Sun, 09 Jan 2005 00:05:51 -0800 Subject: Getting rid of "self." References: Message-ID: BJ?rn Lindqvist wrote: >I think it would be cool if you could refer to instance variables >without prefixing with "self." I know noone else thinks like me so >Python will never be changed, but maybe you can already do it with >Python today? > >.import sys >. >.def magic(): >. s = "" >. for var in sys._getframe(1).f_locals["self"].__dict__: >. s += var + " = self." + var + "\n" >. return s >. >.class A: >. def __init__(self): >. self.hi = "yo" >. >. def meth(self): >. exec(magic()) >. print hi >. >.a = A() >.a.meth() > >It works! exec(magic()) does the needed hi = self.hi. Does it? class A: def __init__(self): self.hi = "yo" def meth(self): exec(magic()) print hi hi = "baby" print hi def other(self): exec(magic()) print hi a = A() a.meth() a.other() That's way too fragile to be useful. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From dan.gass at gmail.com Sun Jan 30 21:04:58 2005 From: dan.gass at gmail.com (Dan Gass) Date: Sun, 30 Jan 2005 20:04:58 -0600 Subject: [Python-Announce] cfgparse v01_00 released Message-ID: I'm pleased to announce the initial release of cfgparse (V01_00) Background ------------------------------------------------------------- cfgparse is a more convenient, flexible, and powerful module for parsing configuration files than the standard library ConfigParser module. cfgparse uses a more declarative style modelled after the popular optparse standard library module. cfgparse can optionally cooperate with the optparse module to provide coordination between command line and configuration file options. In addition, the cooperation can be used to allow the user to control features of the parser from the command line. URLs ------------------------------------------------------------- Docs/home page: http://cfgparse.sourceforge.net/ Download: http://sourceforge.net/projects/cfgparse/ Feature Summary ------------------------------------------------------------- + Simple ini style configuration syntax + Type checking with error handling and help messages + Help summary modelled after that in optparse + Round trip - read, modify, write configuration files with comment retention + Cooperates with optparse for configuration file options that should be overridden by command line options + Supports heirarchically organized option settings * User may store multiple option settings in a arbitrarily deep keyed dictionary. * Application uses a key list to walk into the dictionary to obtain a setting. * User controls key list with setting in configuration file. * Supports adding keys to the list through a command line option or from environment variables. + Supports allowing user control of configuration files used. * Environment variables may be used to allow user to specify a default configuration file. * Command line options to specify configuration file supported. * Configuration files may include other configuration files where where sections are read in parallel. * Configuration files may be nested heirarchically by including configuration files from within a section or subsection. + Configuration files may alternatively be written in Python. * full power and flexibility of Python available for creation of option settings * allows options settings to be real Python objects * this feature is NOT enabled by default + May be extended to support syntax such as XML. Enjoy, Dan Gass From fredrik at pythonware.com Mon Jan 24 02:22:53 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 24 Jan 2005 08:22:53 +0100 Subject: Asynchronous event handling...? References: Message-ID: Chris Line wrote: > When the 'stop' button is selected after 'count', it does > not execute until the count command finishes at 500. > Instead, it is desired to stop counting immediately and > execute the 'stop' method. > > Is there a simple way to handle this situation? calling self.update() at regular intervals inside the loop (at least a couple of times per second, if you can arrange that) will give Tkinter a chance to process incoming events. another possibility is to use a thread to do the processing, but that involves other tricky issues (especially if you want to update the UI from the thread). From fredrik at pythonware.com Wed Jan 12 18:19:49 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 13 Jan 2005 00:19:49 +0100 Subject: What strategy for random accession of records in massive FASTA file? References: <1105569967.129284.85470@c13g2000cwb.googlegroups.com> Message-ID: Chris Lasher wrote: > Since the file I'm working with contains tens of thousands of these > records, I believe I need to find a way to hash this file such that I > can retrieve the respective sequence more quickly than I could by > parsing through the file request-by-request. However, I'm very new to > Python and am still very low on the learning curve for programming and > algorithms in general; while I'm certain there are ubiquitous > algorithms for this type of problem, I don't know what they are or > where to look for them. So I turn to the gurus and accost you for help > once again. :-) If you could help me figure out how to code a solution > that won't be a resource whore, I'd be _very_ grateful. (I'd prefer to > keep it in Python only, even though I know interaction with a > relational database would provide the fastest method--the group I'm > trying to write this for does not have access to a RDBMS.) keeping an index in memory might be reasonable. the following class creates an index file by scanning the FASTA file, and uses the "marshal" module to save it to disk. if the index file already exists, it's used as is. to regenerate the index, just remove the index file, and run the program again. import os, marshal class FASTA: def __init__(self, file): self.file = open(file) self.checkindex() def __getitem__(self, key): try: pos = self.index[key] except KeyError: raise IndexError("no such item") else: f = self.file f.seek(pos) header = f.readline() assert ">" + header + "\n" data = [] while 1: line = f.readline() if not line or line[0] == ">": break data.append(line) return data def checkindex(self): indexfile = self.file.name + ".index" try: self.index = marshal.load(open(indexfile, "rb")) except IOError: print "building index..." index = {} # scan the file f = self.file f.seek(0) while 1: pos = f.tell() line = f.readline() if not line: break if line[0] == ">": # save offset to header line header = line[1:].strip() index[header] = pos # save index to disk f = open(indexfile, "wb") marshal.dump(index, f) f.close() self.index = index db = FASTA("myfastafile.dat") print db["CW127_A02"] ['TGCAGTCGAACGAGAACGGTCCTTCGGGATGTCAGCTAAG... tweak as necessary. From vincent at visualtrans.de Mon Jan 3 15:10:43 2005 From: vincent at visualtrans.de (vincent wehren) Date: Mon, 03 Jan 2005 21:10:43 +0100 Subject: Developing Commercial Applications in Python In-Reply-To: <1104750017.235937.181370@c13g2000cwb.googlegroups.com> References: <1104750017.235937.181370@c13g2000cwb.googlegroups.com> Message-ID: eeykay at gmail.com wrote: > Hello All, > I am trying to convince my client to use Python in his new product. He > is worried about the license issues. Can somebody there to point me any > good commercial applications developed using python ?. The licence > clearly says Python can be used for commercial applications. Is there > any other implications like that of GPL to make the source open ? > Thanks for any help. > eeykay At CSB-System AG, we use Python extensively as embedded scripting language throughout the ERP system we develop (fields of application: system automation, GUI scripting, programmable user exits, reporting, data access/replication, autotests, and apart from that, everywhere we need something done fast ;-). I'm sure that its liberal license was among the main drivers to use it in the first place! -- Vincent Wehren From simon.alexandre at cetic.be Tue Jan 11 08:17:42 2005 From: simon.alexandre at cetic.be (simon.alexandre) Date: Tue, 11 Jan 2005 14:17:42 +0100 Subject: [csv module] duplication of end of line character in output file generated References: <41e3ceb6$1_3@newspeer2.tds.net> Message-ID: ok thanks it works S. "Kent Johnson" a ?crit dans le message de news:41e3ceb6$1_3 at newspeer2.tds.net... > simon.alexandre wrote: > > Hi all, > > > > I use csv module included in python 2.3. I use the writer and encouter the > > following problem: in my output file (.csv) there is a duplication of the > > end of line character, so when I open the csv file in Ms-Excel a blank line > > is inserted between each data line. > > From the docs for csv.writer(): > writer( csvfile[, dialect='excel'[, fmtparam]]) > ...If csvfile is a file object, it must be opened with the 'b' flag on platforms where that > makes a difference. > > Windows is a "platform where that makes a difference." So try > self.writer = csv.writer(file("Test.csv", "wb")) > > Kent > > > > > OS: W2k > > > > Someone has an idea ? > > > > thanks in advance > > > > the source code is the following: > > > > --------------------------------------------------> > > import csv > > > > class CsvDumper: > > > > def __init__(self): > > self.object = > > [['la','mb','mc','md'],['ma','mb','mc','md'],['ma','mb','mc','md']] > > self.writer = csv.writer(file("Test.csv", "w")) > > > > def DumpCsvFile(self): > > for row in self.object: > > self.writer.writerow(row) > > > > c = CsvDumper() > > c.DumpCsvFile() > > > > From daranrife at yahoo.com Fri Jan 28 17:55:51 2005 From: daranrife at yahoo.com (drife) Date: 28 Jan 2005 14:55:51 -0800 Subject: LinearAlgebra incredibly slow for eigenvalue problems In-Reply-To: References: <1106887513.865901.154760@z14g2000cwz.googlegroups.com> Message-ID: <1106952951.834888.65430@f14g2000cwb.googlegroups.com> Hi David, I performed the above check, and sure enough, Numeric is --not-- linked to the ATLAS libraries. I followed each of your steps outlined above, and Numeric still is not linking to the ATLAS libraries. My setup.py file is attached below. Thanks , Daran --#!/usr/bin/env python # To use: # python setup.py install # or: # python setup.py bdist_rpm (you'll end up with RPMs in dist) # import os, sys, string, re from glob import glob if not hasattr(sys, 'version_info') or sys.version_info < (2,0,0,'alpha',0): raise SystemExit, "Python 2.0 or later required to build Numeric." import distutils from distutils.core import setup, Extension # Get all version numbers execfile(os.path.join('Lib','numeric_version.py')) numeric_version = version execfile(os.path.join('Packages', 'MA', 'Lib', 'MA_version.py')) MA_version = version headers = glob (os.path.join ("Include","Numeric","*.h")) extra_compile_args = [] # You could put "-O4" etc. here. mathlibs = ['m'] define_macros = [('HAVE_INVERSE_HYPERBOLIC',None)] undef_macros = [] # You might need to add a case here for your system if sys.platform in ['win32']: mathlibs = [] define_macros = [] undef_macros = ['HAVE_INVERSE_HYPERBOLIC'] elif sys.platform in ['mac', 'beos5']: mathlibs = [] # delete all but the first one in this list if using your own LAPACK/BLAS sourcelist = [os.path.join('Src', 'lapack_litemodule.c')] # set these to use your own BLAS; library_dirs_list = ['/d2/lib/atlas'] libraries_list = ['lapack', 'ptcblas', 'ptf77blas', 'atlas', 'g2c'] # set to true (1), if you also want BLAS optimized matrixmultiply/dot/innerproduct use_dotblas = 1 include_dirs = ['/d2/include'] # You may need to set this to find cblas.h # e.g. on UNIX using ATLAS this should be ['/usr/include/atlas'] extra_link_args = [] # for MacOS X to link against vecLib if present VECLIB_PATH = '/System/Library/Frameworks/vecLib.framework' if os.path.exists(VECLIB_PATH): extra_link_args = ['-framework', 'vecLib'] include_dirs = [os.path.join(VECLIB_PATH, 'Headers')] # The packages are split in this way to allow future optional inclusion # Numeric package packages = [''] package_dir = {'': 'Lib'} include_dirs.append('Include') ext_modules = [ Extension('_numpy', [os.path.join('Src', '_numpymodule.c'), os.path.join('Src', 'arrayobject.c'), os.path.join('Src', 'ufuncobject.c')], extra_compile_args = extra_compile_args), Extension('multiarray', [os.path.join('Src', 'multiarraymodule.c')], extra_compile_args = extra_compile_args), Extension('umath', [os.path.join('Src', 'umathmodule.c')], libraries = mathlibs, define_macros = define_macros, undef_macros = undef_macros, extra_compile_args = extra_compile_args), Extension('arrayfns', [os.path.join('Src', 'arrayfnsmodule.c')], extra_compile_args = extra_compile_args), Extension('ranlib', [os.path.join('Src', 'ranlibmodule.c'), os.path.join('Src', 'ranlib.c'), os.path.join('Src', 'com.c'), os.path.join('Src', 'linpack.c')], extra_compile_args = extra_compile_args), Extension('lapack_lite', sourcelist, library_dirs = library_dirs_list, libraries = libraries_list, extra_link_args = extra_link_args, extra_compile_args = extra_compile_args) ] # add FFT package (optional) packages.append('FFT') package_dir['FFT'] = os.path.join('Packages','FFT','Lib') include_dirs.append(os.path.join('Packages','FFT','Include')) ext_modules.append(Extension('FFT.fftpack', [os.path.join('Packages','FFT','Src', 'fftpackmodule.c'), os.path.join('Packages', 'FFT', 'Src', 'fftpack.c')], extra_compile_args = extra_compile_args)) # add MA package (optional) packages.append('MA') package_dir['MA'] = os.path.join('Packages', 'MA', 'Lib') # add RNG package (optional) packages.append('RNG') packages.append('RNG') package_dir['RNG'] = os.path.join('Packages', 'RNG', 'Lib') include_dirs.append(os.path.join('Packages', 'RNG', 'Include')) ext_modules.append(Extension('RNG.RNG', [os.path.join('Packages', 'RNG', 'Src', 'RNGmodule.c'), os.path.join('Packages', 'RNG', 'Src', 'ranf.c'), os.path.join('Packages', 'RNG', 'Src', 'pmath_rng.c')], extra_compile_args = extra_compile_args)) # add dotblas package (optional) if use_dotblas: packages.append('dotblas') package_dir['dotblas'] = os.path.join('Packages', 'dotblas', 'dotblas') ext_modules.append(Extension('_dotblas', [os.path.join('Packages', 'dotblas', 'dotblas', '_dotblas.c')], library_dirs = library_dirs_list, libraries = libraries_list, extra_compile_args=extra_compile_args)) long_description = """ Numerical Extension to Python with subpackages. The authors and maintainers of the subpackages are: FFTPACK-3.1 maintainer = "Numerical Python Developers" maintainer_email = "numpy-discussion at lists.sourceforge.net" description = "Fast Fourier Transforms" url = "http://numpy.sourceforge.net" MA-%s author = "Paul F. Dubois" description = "Masked Array facility" maintainer = "Paul F. Dubois" maintainer_email = "dubois at users.sf.net" url = "http://sourceforge.net/projects/numpy" RNG-3.1 author = "Lee Busby, Paul F. Dubois, Fred Fritsch" maintainer = "Paul F. Dubois" maintainer_email = "dubois at users.sf.net" description = "Cray-like Random number package." """ % (MA_version, ) # Oops, another bug in Distutils!? # Write rpm_build.sh pointing to this python rpm_build_text="""env CFLAGS="$RPM_OPT_FLAGS" %setup.py build\n""" % sys.executable rpm_script = open("rpm_build.sh", "w") rpm_script.write(rpm_build_text) rpm_script.close() # Write rpm_install.sh pointing to this python rpm_install_text=sys.executable +""" setup.py install --root=$RPM_BUILD_ROOT cat >INSTALLED_FILES <>INSTALLED_FILES """ rpm_script = open("rpm_install.sh", "w") rpm_script.write(rpm_install_text) rpm_script.close() setup (name = "Numeric", version = numeric_version, maintainer = "Numerical Python Developers", maintainer_email = "numpy-developers at lists.sourceforge.net", description = "Numerical Extension to Python", long_description = long_description, url = "http://numpy.sourceforge.net", # distutils allows you to fix or fudge anything :-) extra_path = 'Numeric', packages = packages, package_dir = package_dir, headers = headers, include_dirs = include_dirs, ext_modules = ext_modules ) print 'MA Version', MA_version print 'Numeric Version', numeric_version From peter at engcorp.com Tue Jan 18 01:00:18 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 18 Jan 2005 01:00:18 -0500 Subject: python execution path In-Reply-To: <1106027652.064860.12650@z14g2000cwz.googlegroups.com> References: <1106027652.064860.12650@z14g2000cwz.googlegroups.com> Message-ID: qhfgva at gmail.com wrote: > Peter Hansen wrote: >>The best approach, if it's really intended to be a debugging >>aid, might be to learn about "pdb" .... > > This is more of a what if-ish question I guess. I use pdb fairly > regularly, I'm just looking to extend my debugging toolkit. I saw an > article recently about how perl has the sh -x type functionality and I > was curious if anything like that was possible in python. Not entirely > sure how it would make my life better, but it seems intriguing. Ah. In that case, investigate sys.settrace(). There are doubtless a variety of recipes and snippets available in either the Cookbook or in the mailing list archives, after you do the basic reading in http://www.python.org/doc/2.4/lib/module-sys.html . -Peter From skip at pobox.com Thu Jan 6 21:02:44 2005 From: skip at pobox.com (Skip Montanaro) Date: Thu, 6 Jan 2005 20:02:44 -0600 Subject: Please Contribute Python Documentation! In-Reply-To: <10to8qulnc3vke1@news.supernews.com> References: <7xacrpdxy3.fsf@ruckus.brouhaha.com> <7x652che6z.fsf@ruckus.brouhaha.com> <7xoeg4txrp.fsf@ruckus.brouhaha.com> <1104895842.200010.42720@z14g2000cwz.googlegroups.com> <7xhdlwh5qs.fsf@ruckus.brouhaha.com> <10to8qulnc3vke1@news.supernews.com> Message-ID: <16861.60868.409947.889215@montanaro.dyndns.org> I'm changing the subject so that hopefully people who have long ago tuned out the "Python evolution: Unease" subject will read this note. John> I would like to contribute some documentation to Python. I've got John> the time, I write quite a bit, etc. I've got fairly strong John> opinions about some things that need to be documented, (such as John> all the new style class descriptor stuff from 2.2) and I have John> relatively little difficulty matching the existing style. John> However, I don't know TEX, Latex, CVS or Sourceforge. (The latter John> two are on my "learn sometime soon so I can put PyFIT where it John> belongs" list.) John> I have no desire to install Perl to run the documentation John> toolchain. I also have no particular desire to write up a bunch John> of final format stuff and drop it on someone else to put into the John> latex format so it can be included. I'm really not picking on John. I just happen to be replying to his message. Others have echoed sentiments similar to his. Let me emphasize this. You do not (repeat, *do not*) need to install any tools to contribute content to the documentation. Just whip out your favorite text editor and type plain old text. There are plenty of us around who know enough LaTeX to markup anything you contribute. Don't let lack of a specific set of tools be a barrier to contribution! The preferred way to submit documentation changes is by submitting a patch to the Python project on SourceForge: http://sourceforge.net/projects/python If you discover an error that requires little more than calling attention to the problem (or if you don't know how to fix it), just submit a bug report instead of a patch. In either case, select "Documentation" as the category. There is no need to assign it to anyone. It will get seen shortly. The correctness of a documentation fix is generally easier to verify than that for a code fix, so they tend to get applied pretty quickly. The only (small) barrier to submitting bug reports and patches via SourceForge is that you must register first. We used to allow anonymous reports but found that too often they were incomplete and required further input. With no way to contact the submitter of an anonymous report we had no choice but to hope they returned to check for progress. That only happened rarely, so the usual resolution was simply to delete the report. Fred Drake releases new development versions of the docs frequently (typically once every month or two). I normally use the development docs instead of the regular ones for my day-to-day work. They are available here: http://www.python.org/dev/doc/devel/ It's useful to check to see the most current status of the docs. The only thing more current is the source in CVS. Skip From rparnes at megalink.net Sat Jan 29 07:58:57 2005 From: rparnes at megalink.net (Bob Parnes) Date: Sat, 29 Jan 2005 12:58:57 -0000 Subject: Maximum Number of Class Attributes References: Message-ID: On Wed, 26 Jan 2005 10:03:47 +0100, Sylvain Thenault wrote: > On Wed, 26 Jan 2005 02:03:12 +0000, Bob Parnes wrote: > >> In its default configuration, my version of pylint (0.5.0) sets the >> maximum number of class attributes at 7. This seems low to me, but I can >> see how an excessive number might make maintenance more difficult. Is this >> indeed the best value for a maximum under ordinary conditions? If not, can >> anyone suggest a more reasonable value? > > well, this value is very subjective, and may change from one context to > another... For instance at some point I hope that pylint will detect "GUI" > classes and allow more attributes (and methods?) to those. > Anyway that's just an indicator, not a rule of thumb (and pylint itself > has some class with more than 7 attributes...). > > And FYI, this value has been taken from a post to the > testdrivendevelopment at yahoogroups (as most others default values in the > "design analysis" checker). Hum, well... After checking it seems that the > post said 20 attributes. I don't remember why did i get this number down > to 7. If this discussion leads to an agreement for a better number, I > can change the default value. > > -- > Sylvain Th?nault LOGILAB, Paris (France). > > http://www.logilab.com http://www.logilab.fr http://www.logilab.org > > Thanks for the information. I *am* using gui classes. -- Bob Parnes rparnes at megalink.net From martin at v.loewis.de Tue Jan 4 03:44:49 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 04 Jan 2005 09:44:49 +0100 Subject: Using ICL to compile C extensions In-Reply-To: <1104815892.984903.182190@f14g2000cwb.googlegroups.com> References: <1104815892.984903.182190@f14g2000cwb.googlegroups.com> Message-ID: <41da5779$0$1652$9b622d9e@news.freenet.de> dayzman at hotmail.com wrote: > Does anyone know how I can use "icl" (Intel C++) to compile C > extensions? I'm on Windows, and my Python is compiled using VS7.1 > (binary distribution). Right now, when I run setup.py install, it uses > cl.exe (MSVC++ Toolkit 2003), and I would like to use icl because > MSVC++ 2003 does not support C99. It should be possible to use this compiler, as long as you can link to msvcr71.dll (i.e. as long as you have header files of the MS C library, and an import library that links to msvcr71). Whether you can use distutils to run the build process is a different issue - you might need to extend distutils. Regards, Martin From aahz at pythoncraft.com Tue Jan 4 10:12:05 2005 From: aahz at pythoncraft.com (Aahz) Date: 4 Jan 2005 10:12:05 -0500 Subject: Python evolution: Unease References: <41da4a3f$0$17626$e4fe514c@dreader13.news.xs4all.nl> <1104830276.579755.133870@f14g2000cwb.googlegroups.com> <7x652dk0gh.fsf@ruckus.brouhaha.com> <1104831798.408560.228940@c13g2000cwb.googlegroups.com> Message-ID: In article <1104831798.408560.228940 at c13g2000cwb.googlegroups.com>, wrote: > >Maybe a PSF grant would help? I guess this has been considered ... The first three PSF grants were all in some way not directly related to changing the core language. One was for a library, one for improving Jython, and one for improving docs. Giving the PSF more money increases the chances for additional work. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "19. A language that doesn't affect the way you think about programming, is not worth knowing." --Alan Perlis From steve at holdenweb.com Mon Jan 31 09:37:04 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 31 Jan 2005 09:37:04 -0500 Subject: Want to meet any of these people? They are registered for PyCon Message-ID: In accordance with PyCon's privacy policy, there are currently 29 PyCon registrants who have asked that their names not be published. The remainder, however, are listed here just in case you've ever wanted to meet any of them, and could do so by registering for PyCon at http://www.python.org/pycon/2005/register.html Note that the sort order isn't perfect - I just sorted on the second "word" in each name. PyCon is a *great* place to meet people and discuss ideas. Hope to see you there. regards Steve Chris Akre Brad Allen Kevin Altis Ummesalma Amil Stephen Apiki Dan Arico Larry Austin Suresh Babu Eddala Jim Baker Amir Bakhtiar Greg Barr Facundo Batista Anton Benard Thomas Bennett Bill Bergmann Ian Bicking Brian Bilbrey David Binger Zachery Bir Matthew Blecker Chris Blunck Ben Bodner Jonah Bossewitch Ivo Busko Theodore C. Pollari Matthew Cahn JP Calderone Brett Cannon Katie Capps Parlante Vern Ceder Michael Chermside Martin Chilvers Anders Chrigstrom Daniel Chudnov Tom Cocagne Eric Coffman Kevin Cole Tim Couper Matt Croydon Kevin Cully Andrew Dalke R. David Murray Zoltan Deak Stephan Deibel Catherine Devlin Cory Dodt Bruce Donald Campbell Brian Dorsey Scott Downie Fred Drake Matt Drew Michael Droettboom Reggie Dugard Donovan Eastman Bruce Eckel John Ehresman Alan Elkner Jeffrey Elkner Richard Emslie Mathieu Fenniak Robert Ferguson Abe Fettig Russell Finn Timothy Fitz Mike Fletcher Alec Flett Paul Flint Mitchell Foral Doug Fort Robin Friedrich Phil Frost Jim Fulton Patrick Garrett Philip Gaudette David Geller Grig Gheorghiu Christopher Gillett John Goebel Matthew Good David Goodger Nat Goodspeed Perry Greenfield Joe Grossberg David Grumm Walter H. Rauser Warren Hack Walker Hale IV Jacob Hallen David Hancock Andrew Harrington Travis Hartwell Randy Heiland Mark Hertel Raymond Hettinger Rob Hill Tom Hoffman Steve Holden Jim Hugunin John Hunter Jeremy Hylton Bob Ippolito Joseph J. Pamer Kevin Jacobs Vineet Jain Michael Johnson Eric Jones Evan Jones Ian Jones Richard Jones Francisco Juarez Patrick K. O'Brien Jacob Kaplan-Moss Don Kauffman David Keeney Peter Kessler Shahthureen Khan Brian Kirsch Sally Kleinfeldt Josheph Kocherhans Jeff Kowalczyk Daniel Krech Kartic Krishnamurthy Peter Kropf Andrew Kuchling Bob Kuehne Jeff Kunce Lloyd Kvam Jason L Asbahr MAN-YONG LEE Cameron Laird LD Landis Jukka Laurila Aaron Lav Phil Lawrence Edward Leafe Charles Leake Glyph Lefkowitz Ted Leung Michelle Levesque Bailing Li Greg Lindstrom Yihsiang Liow Peter Lyons John M. Camara Matthew MacInnes Andrew MacKeith Bryan MacRae Brian Mahoney Alex Martelli Andrej Masiar Peter Masiar Roger Masse Mark McClain Alan McIntyre Michael McLay Paul McNett Simon Michael Charles Moad Andrew Moore David Morrill David Muffley Edward Muller Robin Munn Eric Newton Edward Ng Rob Nichols Nestor Nissen Greg Noble Neal Norwitz Peter Olsen Mike Orr Brad Palmquist Guy Pardoe Bob Parks Thomas Parsli Anders Pearson Joel Pearson Samuele Pedroni Dave Perkins Tim Peters Carl Phillips Charles Phillips John Pinner Mike Pirnat Patrick Power Mark Pratt Kashif Qureshi James R Hall-Morrison Michael R. Bernstein Douglas R. Caldwell Andrew R. Gross Robert R. Knight Christian R. Simms Anna Ravenscroft Jimmy Retzlaff John Rhodes Anthony Rhudd Armin Rigo Nicholas Riley Arnaldo Riquelme Tracy Ruggles Jeff Rush Ollie Rutherfurd Dr. S. Candelaria de Ram Mike Salib Prasan Samtani Michel Sanner Phil Schumm Bill Sconce Chris Shenton Allen Short Jim Sizelove Brian Skahan Erik Smartt Garrett Smith Jason Smith Jacob Smullyan Jeff Sprandel David Stanek William Stein Yusei TAHARA Geoff Talvola Lee Taylor Mike Taylor Christian Theune Rick Thomas Andy Trice George Trojan Jamie Turner Karl Ulbrich Kirby Urner Eric V. Smith Andi Vajda Hernando Vera Thomas Verghese Martin Walsh Barry Warsaw Steve Waterbury Michael Weigend Chad Whitacre Kendall Whitesell Frank Wilder Derek Willis Simon Willison Mark Wittner Russ Woodman Andy Wright Linden Wright Peter Wu Yahong Wu James Y Knight Ka-Ping Yee Nathan Yergler Wai Yip Tung Rici Yu Peter Zhang Brian Zimmer matthew daiprai holger krekel clint malone Martin v. Loewis Guido van Rossum Tom von Schwerdtner -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 From ebbaalm at uiuc.edu Fri Jan 7 16:00:54 2005 From: ebbaalm at uiuc.edu (Ebba Cecilia Ovesdotter Alm) Date: Fri, 7 Jan 2005 15:00:54 -0600 Subject: Tkinter: using a Listbox Message-ID: <6fb0c302.bb18916d.865c900@expms2.cites.uiuc.edu> Hello, I'm learning how to use the Tkinter module. I would like to use an element similar to a drop-down form, where the user can select one option out of many. I thought that a Listbox item could do just this. The following extract from my code (with the listbox part basically mirroring http://effbot.org/books/tkinterbook/listbox.htm), does, however, not create a visable Listbox. Am I interpreting the Listbox incorrectly? Ideas or suggestions are appreciated. #Frame & label for the listbox self.selectFrame = Frame(self.root) self.selectFrame.pack(side=TOP, fill=X, padx=10) Label(self.selectFrame, text='Primary choice').pack(side=LEFT) #Listbox self.listbox = Listbox(self.selectFrame) self.listbox.insert(END, "a list entry") for item in ["A","B","C"]: self.listbox.insert(END, item) Thanks, Cecilia From tim.golden at viacom-outdoor.co.uk Thu Jan 20 04:03:17 2005 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Thu, 20 Jan 2005 09:03:17 -0000 Subject: Print to Windows default Printer Message-ID: <9A28C052FF32734DACB0A288A35339910359D1@vogbs009.gb.vo.local> [Samantha] | Thanks Tim. I didn't realize it would be so difficult. | S Strictly, if all you want to do is print text and you have mapped LPTx: to some printer (local or network) then the venerable "PRINT " or "COPY LPTx:" may well be what you want. You can issue these via an os.system call from within Python, and if that serves the purpose, well... import os f = open ("temp.txt", "w") f.write ("""I must go down to the sea again, To the lonely sea and the sky. And all I ask is a tall ship And a star to steer her by. """) f.close () os.system ("print temp.txt") TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From http Fri Jan 7 21:54:26 2005 From: http (Paul Rubin) Date: 07 Jan 2005 18:54:26 -0800 Subject: Python Operating System??? References: <10trb0mgiflcj4f@corp.supernews.com> <10tteh884ivk6c9@corp.supernews.com> <7xr7kx0w4m.fsf@ruckus.brouhaha.com> Message-ID: <7xk6qoeil9.fsf@ruckus.brouhaha.com> Arich Chanachai writes: > >But I thought Python was an all-purpose language. After all, OS's > >have been written in Lisp before too. > > > Pure Lisp? Or a Lisp/C/Asm combo? Lisp has a compiled flavor by the way. Compiled flavor? Lisp has been compiled since the 1950's. No, there was no C code on Lisp machines. There was some low-level code at the bottom whose capabilities were such that you could accurately call it asm, but it was Lisp too, just a very restricted form. From peter at engcorp.com Tue Jan 18 14:53:10 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 18 Jan 2005 14:53:10 -0500 Subject: hex notation funtion In-Reply-To: <41ed66d5$0$92053$a1866201@visi.com> References: <41ed60f9$0$29427$a1866201@visi.com> <41ed66d5$0$92053$a1866201@visi.com> Message-ID: Grant Edwards wrote: > On 2005-01-18, Grant Edwards wrote: > >>On 2005-01-18, tertius wrote: >> >> >>>Is there a builtin function that will enable me to display the hex >>>notation of a given binary string? (example below) >> >>' '.join('%02x' % ord(b) for b in s) > > > Oops. Should be: > > ' '.join(['%02x' % ord(b) for b in s]) The first works fine under Python 2.4, actually... you need the list comprehension only on previous versions. -Peter From aahz at pythoncraft.com Thu Jan 6 19:01:46 2005 From: aahz at pythoncraft.com (Aahz) Date: 6 Jan 2005 19:01:46 -0500 Subject: The Industry choice References: <10trej2fl8dip65@corp.supernews.com> Message-ID: In article <10trej2fl8dip65 at corp.supernews.com>, Jeff Shannon wrote: > >Note that the so-called 'viral' nature of GPL code only applies to >*modifications you make* to the GPL software. The *only* way in which >your code can be 'infected' by the GPL is if you copy GPL source. That's not true -- consider linking to a GPL library. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "19. A language that doesn't affect the way you think about programming, is not worth knowing." --Alan Perlis From steven.bethard at gmail.com Sun Jan 23 15:08:11 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Sun, 23 Jan 2005 13:08:11 -0700 Subject: specifying constants for a function (WAS: generator expressions: performance anomaly?) In-Reply-To: References: Message-ID: Nick Coghlan wrote: > Steven Bethard wrote: > >> I wrote: >> > If you really want locals that don't contribute to arguments, I'd be >> > much happier with something like a decorator, e.g.[1]: >> > >> > @with_consts(i=1, deftime=time.ctime()) >> > def foo(x, y=123, *args, **kw): >> > return x*y, kw.get('which_time')=='now' and time.ctime() or deftime >> > >> > Then you don't have to mix parameter declarations with locals >> > definitions. >> > >> > Steve >> > >> > [1] I have no idea how implementable such a decorator would be. I'd >> > just like to see function constants declared separate from arguments >> > since they mean such different things. >> >> I played around with this, and I think it's basically implementable: > > > Raymond's constant binding decorator is probably a good model for how to > do it: > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/277940 Yeah, I thought about this recipe, but opcodes always scare me too much. ;) Steve From jeff at ccvcorp.com Thu Jan 6 16:00:18 2005 From: jeff at ccvcorp.com (Jeff Shannon) Date: Thu, 06 Jan 2005 13:00:18 -0800 Subject: sorting on keys in a list of dicts In-Reply-To: References: Message-ID: <10tr9ejf05pv660@corp.supernews.com> Jp Calderone wrote: > L2 = [(d[key], i, d) for (i, d) in enumerate(L)] > L2.sort() > L = [d for (v, i, d) in L2] Out of curiosity, any reason that you're including the index? I'd have expected to just do L2 = [(d[key], d) for d in L] L2.sort() L = [d for (v, d) in L2] I suppose that your version has the virtue that, if the sortkey value is equal, items retain the order that they were in the original list, whereas my version will sort them into an essentially arbitrary order. Is there anything else that I'm missing here? Jeff Shannon Technician/Programmer Credit International From holbertr at dma.org Wed Jan 5 10:37:53 2005 From: holbertr at dma.org (Rick Holbert) Date: Wed, 05 Jan 2005 10:37:53 -0500 Subject: % operation References: Message-ID: It also looks like you are using an old version of Python running on an old version of Linux. Time to upgrade? Christopher Koppler wrote: > On Wed, 05 Jan 2005 15:36:30 +0900, Daewon YOON wrote: > >> ==== >> Python 1.5.2 (#1, Jul 5 2001, 03:02:19) [GCC 2.96 20000731 (Red Hat >> Linux 7.1 2 on linux-i386 >> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >> >>> x=9 >> >>> y=4 >> >>> x%y >> 1 >> >>> for z in range(44): >> ... z%9 >> File "", line 2 >> z%9 >> ^ >> SyntaxError: invalid syntax >> >> ==== >> What's wrong with the above operation and how can I get the correct >> modulo result with Python? > > There's nothing wrong with the operation, but it looks like you forgot to > indent your loop body (which the interactive shell doesn't automagically > do for you): > >>>> for z in range(44): > ... z%9 > ... > > [result snipped] > From case.nelson at gmail.com Wed Jan 12 21:47:50 2005 From: case.nelson at gmail.com (snoe) Date: 12 Jan 2005 18:47:50 -0800 Subject: Help Optimizing Word Search In-Reply-To: References: <1105486769.730769.165710@c13g2000cwb.googlegroups.com> Message-ID: <1105584470.524744.324640@z14g2000cwz.googlegroups.com> With a list of letters: 'ABAE?S?' your implementation ran 3.5 times faster than the one from http://blog.vrplumber.com/427 (in 0.437 seconds vs 1.515) Without wildcards yours runs slightly quicker as well. I guess with the wildcards, using an re as a quick filter against each word, versus the translate method is much faster. From macrocosm at fastmail.fm Sun Jan 9 10:01:08 2005 From: macrocosm at fastmail.fm (Arich Chanachai) Date: Sun, 09 Jan 2005 10:01:08 -0500 Subject: Python Operating System??? In-Reply-To: <7xr7kvm72c.fsf@ruckus.brouhaha.com> References: <10trb0mgiflcj4f@corp.supernews.com> <10tteh884ivk6c9@corp.supernews.com> <7xr7kx0w4m.fsf@ruckus.brouhaha.com> <7xhdlss0tl.fsf@ruckus.brouhaha.com> <7x8y734jlq.fsf@ruckus.brouhaha.com> <7xr7kv8bmt.fsf@ruckus.brouhaha.com> <7xr7kvm72c.fsf@ruckus.brouhaha.com> Message-ID: <41E14734.5050908@fastmail.fm> Paul Rubin wrote: > ... > >>OK, then give me an example of Lisp OS that runs on a PC. I would like to >>install it on my PC tomorrow. Or maybe my Mac. That was your whole point, >>originally, that since it could be done in Lisp, why not Python? >> >> > >Huh? That's a non-sequitur, nothing prevents you from running Lisp on >your PC or Mac. The same issues issues that apply to OS code, also >apply to user code. The Lisp machine hardware wasn't needed only to >make the OS run fast. The Lisp machine was developed so that people >could deploy large user-level applications written in Lisp, and the >hardware was there to support those applications. And given such a >good Lisp environment, there was no reason to think of writing the OS >in anything other than Lisp. > >In fact, the reason the Lisp machine died off was because general >purpose workstation hardware (and later, PC-class hardware) became >fast enough to run Lisp applications without needing special purpose >CPU's. That same PC hardware speed is what makes it possible to run >user applications in Python. > > So true, there was indeed a contextual reason for special hardware, and the context has since changed (dramatically). From uche at ogbuji.net Sat Jan 15 01:07:06 2005 From: uche at ogbuji.net (Uche Ogbuji) Date: 14 Jan 2005 22:07:06 -0800 Subject: XPath and XQuery in Python? In-Reply-To: References: Message-ID: <1105769226.435105.19310@c13g2000cwb.googlegroups.com> Interesting discussion. My own thoughts: http://www.oreillynet.com/pub/wlg/6224 http://www.oreillynet.com/pub/wlg/6225 Meanwhile, please don't make the mistake of bothering with XQuery. It's despicable crap. And a huge impedance mismatch with Python. --Uche From hpk at trillke.net Fri Jan 7 19:14:11 2005 From: hpk at trillke.net (holger krekel) Date: Sat, 8 Jan 2005 01:14:11 +0100 Subject: AttributeError of a module instance In-Reply-To: <43B02B32.6010805@yahoo.it> References: <43B02B32.6010805@yahoo.it> Message-ID: <20050108001411.GC7646@solar.trillke.net> On Mon, Dec 26, 2005 at 17:41 +0000, Paolino wrote: > I'd like to catch AttributeError on the module level,so that I can > declare default bindings for useds defore definition.How is this to be > done?Thanks for help. It cannot be done directly but with a small hack. This is the idea: import sys class A: def __getattr__(self,name): if name[:1] != '_': return name raise AttributeError(name) sys.modules['a'] = A() import a print a.helloworld # will print "helloworld" Note, that subsequently you can "import a" also from other modules because the import statement consults sys.modules. This is all a bit bothersome and thus it's often easier to just do "from somemod import a" directly and forget about the above magic. cheers, holger From tmohr at s.netic.de Wed Jan 26 00:44:51 2005 From: tmohr at s.netic.de (Torsten Mohr) Date: Wed, 26 Jan 2005 06:44:51 +0100 Subject: import hook, overwrite import? Message-ID: Hi, is there some description available to overwrite the import hook? By googling i found out so far that i need to overwrite __builtins__.__import__ with something else. Can i also do this with a C function that is provided when using an embedded python interpreter? So my own C program provides this and when linking with python.lib the function is overwritten? Or is there some extension hook? Does this also handle "from module import *" not only the normal "import module"? Thanks for any hints, Torsten. From nick at craig-wood.com Sat Jan 22 05:30:22 2005 From: nick at craig-wood.com (Nick Craig-Wood) Date: 22 Jan 2005 10:30:22 GMT Subject: default value in a list References: <1106349263.943972.72710@f14g2000cwb.googlegroups.com> Message-ID: TB wrote: > Is there an elegant way to assign to a list from a list of unknown > size? For example, how could you do something like: > > >>> a, b, c = (line.split(':')) > if line could have less than three fields? You could use this old trick... a, b, c = (line+"::").split(':')[:3] Or this version if you want something other than "" as the default a, b, b = (line.split(':') + 3*[None])[:3] BTW This is a feature I miss from perl... -- Nick Craig-Wood -- http://www.craig-wood.com/nick From list.adam at twardoch.com Sat Jan 29 23:15:34 2005 From: list.adam at twardoch.com (Adam Twardoch) Date: Sun, 30 Jan 2005 05:15:34 +0100 Subject: [Plone] Detailed poll results? Message-ID: Hello, Is there a method, or an alternative module that could be used, to have "polls" in Plone that display detailed results of the poll, i.e. all users and the votes they have given? Adam From jdhunter at ace.bsd.uchicago.edu Thu Jan 20 15:27:56 2005 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Thu, 20 Jan 2005 14:27:56 -0600 Subject: problem with import pylab from a website In-Reply-To: <1106127655.41ee2b2758a9a@imapwww.epfl.ch> (jean.rossier@epfl.ch's message of "Wed, 19 Jan 2005 10:40:55 +0100") References: <1106127655.41ee2b2758a9a@imapwww.epfl.ch> Message-ID: >>>>> "jean" == jean rossier writes: jean> Hello All, I am facing a problem while importing pylab jean> library(in a .py program file) via web browser however the jean> same program works when I execute it from the command jean> prompt. jean> Error message we get: Permission denied: '/usr/share/matplotlib/.ttffont.cache', referer: One solution is to give yourself write permission to /usr/share/matplotlib. If this is not possible or in unpalatable for sysadmin reasons, you have a couple of options. matplotlib creates a font cache .ttffont.cache of the ttf files it finds on your system. If the HOME environment variable is set, it places the cache file in the HOME dir. So if setting HOME is a viable option for you, simply set this to a writable directory on your system and you are good to go. This is the approach I recommend. If HOME does not exist, matplotlib falls back on its data path: this is where fonts, icons and other goodies live. You can also customize this directory by setting the MATPLOTLIBDATA environment variable. If you go this route, more all the files currently in /usr/share/matplotlib to some other directory, say /my/dir, and make sure it is writable, and then set MATPLOTLIBDATA to point to it. Note matplotlib has a configuration file that controls all of the default settings for the plot. If you want to edit these, the edited file can also be placed in the HOME directory. See http://matplotlib.sf.net/.matplotlibrc . Hope this helps, JDH From a at b.c Sat Jan 15 10:55:41 2005 From: a at b.c (Doug Holton) Date: Sat, 15 Jan 2005 09:55:41 -0600 Subject: java 5 could like python? In-Reply-To: References: Message-ID: vegetax wrote: > In the other hand, with the recent changes in java 5 i can pythonize > java, Have you seen Jython? http://www.jython.org/ It may be the best option for you. It will run just as fast as a regular java program. Also there is groovy: http://groovy.codehaus.org/ From TheDolphin at ivonet.nl Wed Jan 26 16:56:12 2005 From: TheDolphin at ivonet.nl (Ivo Woltring) Date: Wed, 26 Jan 2005 22:56:12 +0100 Subject: subprocess.Popen() redirecting to TKinter or WXPython textwidget??? References: <41f80b1b$0$148$3a628fcd@reader1.nntp.hccnet.nl> <1106775371.049857.36360@z14g2000cwz.googlegroups.com> Message-ID: <41f811fe$0$148$3a628fcd@reader1.nntp.hccnet.nl> wrote in message news:1106775371.049857.36360 at z14g2000cwz.googlegroups.com... > Ivo, my initial thought would be, you need to know how much text you > will get back from popen. My Python reference has the following > example: > > import os > dir = os.popen('ls -al', 'r') > while (1): > line = dir.readline() > if line: > print line, > else: > break > > that example shows how to capture the process output in a file-type > object, then bring it into a string with readline(). > >[.... snip ....] > cheers > S > Thanx for trying Stewart, but that is not what I need The output of mencoder is not readable with readlines (i tried it) because after the initial informational lines You don't get lines anymore (you get a linefeed but no newline) The prints are all on the same line (like a status line) something like Pos: 3,1s 96f ( 0%) 42fps Trem: 0min 0mb A-V:0,038 [171:63] which is coninually updated while the process runs... > in your app, you could create a Tkinter stringVar, say myOutput, for > the process output. In your Tkinter widget, you could then set a > textvariable=myOutput. also use the wait_variable and watch options How does this work? wait?? anyone? > (hope I recall these correctly, don't have my Tkinter ref. at hand) to > detect when there's been a change to the contents of the StringVar and > update the contents of the label. > Hope this helps, if not, write back. I really like to know how I can catch the output of a subproces.Popen() command and redirect it to something else (like a textwidget ) and I really like to use the subprocess module (standard in v2.4) to get to know it. Another reason to use the subprocess module is I can stop the process because I know the handle of the thread. The subprocess module knows all this. cheerz, Ivo. From starbuck_ms at yahoo.com Fri Jan 21 17:56:31 2005 From: starbuck_ms at yahoo.com (PyStarbuck) Date: 21 Jan 2005 14:56:31 -0800 Subject: PyXML problem between python 2.3 and python 2.4 Message-ID: <1106348191.156451.282180@c13g2000cwb.googlegroups.com> Hi All, Has anybody had an issue with compatiblity between XML files between python 2.3 and python 2.4. I have PyXML 0.8.3 installed in ClearCase and it is shared between Solaris and Windows. Here is an example on my system: ActivePython 2.3.4 Build 233 (ActiveState Corp.) based on Python 2.3.4 (#53, Oct 18 2004, 20:35:07) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.insert(0, r"C:\cc\sweeneym_atf\reuse_python") >>> import xml >>> xml.__file__ 'C:\\cc\\sweeneym_atf\\reuse_python\\xml\\__init__.py' >>> import xml.marshal.generic as m >>> f = open(r"C:\test.xml", "w+") >>> m.dump_format(sys.path, f) >>> f.close() ActivePython 2.4 Build 243 (ActiveState Corp.) based on Python 2.4 (#60, Nov 30 2004, 09:34:21) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.insert(0, r"C:\cc\sweeneym_atf\reuse_python") >>> import xml >>> import xml.marshal.generic as m >>> fd = open(r"C:\test.xml", "r") >>> l = m.load(fd) Traceback (most recent call last): File "", line 1, in ? File "C:\cc\sweeneym_atf\reuse_python\xml\marshal\generic.py", line 377, in load return m._load(file) File "C:\cc\sweeneym_atf\reuse_python\xml\marshal\generic.py", line 396, in _load p.parseFile(file) File "C:\cc\sweeneym_atf\reuse_python\xml\sax\drivers\drv_pyexpat.py", line 74, in parseFile self.close() File "C:\cc\sweeneym_atf\reuse_python\xml\sax\drivers\drv_pyexpat.py", line 132, in close if self.parser.Parse("", 0) != 1: xml.parsers.expat.ExpatError: parsing finished: line 17, column 0 I then performed a test by doing the following: 1) From python 2.4, marshal sys.path into a test24.xml file. 2) From python 2.3 un-marshal the test24.xml file, it workes. 3) From python 2.3 re-marshal the just un-marshaled list into test23.xml 4) Back in python24, un-marshal test23.xml, it failed. 5) Perform a diff on the new files, identical. Any Ideas? From francis.girard at free.fr Wed Jan 26 16:18:30 2005 From: francis.girard at free.fr (Francis Girard) Date: Wed, 26 Jan 2005 22:18:30 +0100 Subject: python without OO In-Reply-To: References: <1106689788.676121.48490@c13g2000cwb.googlegroups.com> <200501262135.30872.francis.girard@free.fr> Message-ID: <200501262218.31133.francis.girard@free.fr> Le mercredi 26 Janvier 2005 21:44, PA a ?crit?: > On Jan 26, 2005, at 21:35, Francis Girard wrote: > >> Project fails for many reasons but seldomly because one language is > >> "better" or "worst" than another one. > > > > I think you're right. But you have to choose the right tools that fit > > your > > needs. But I think that's what you meant anyway. > > Yes. But even with the "best" tool and the "best" intents, projects > still fail. In fact, most IT projects are considered failures: > > http://www.economist.com/business/PrinterFriendly.cfm?Story_ID=3423238 Well, let's go back home for some gardening. My wife will be happy. > > Cheers > > -- > PA > http://alt.textdrive.com/ From genezhang at gmail.com Sun Jan 9 20:21:24 2005 From: genezhang at gmail.com (Gene) Date: 9 Jan 2005 17:21:24 -0800 Subject: path to python file given module In-Reply-To: <1105319404.902746.179690@c13g2000cwb.googlegroups.com> References: <1105315568.887724.260370@c13g2000cwb.googlegroups.com> <1105315923.520581.280580@c13g2000cwb.googlegroups.com> <1105317971.205487.82770@c13g2000cwb.googlegroups.com> <1105319404.902746.179690@c13g2000cwb.googlegroups.com> Message-ID: <1105320084.044360.221800@c13g2000cwb.googlegroups.com> It works now. Thanks. From steven.bethard at gmail.com Tue Jan 25 15:24:03 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Tue, 25 Jan 2005 13:24:03 -0700 Subject: limited python virtual machine (WAS: Another scripting language implemented into Python itself?) In-Reply-To: References: Message-ID: Michael Spencer wrote: > Safe eval recipe posted to cookbook: > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469 This recipe only evaluates constant expressions: "Description: Evaluate constant expressions, including list, dict and tuple using the abstract syntax tree created by compiler.parse" It means you can't eval arbitrary Python code -- it's basically just a data parser. Handy in some situations, but not the equivalent of a limited Python virtual machine. > Likewise, function calls are easily intercepted I'm not sure I follow this... How do you intend to intercept all function calls? > As you say, attribute access to core functions appears to present the > challenge. It is easy to intercept attribute access, harder to know > what's safe. If there were a known set of 'dangerous' objects e.g., > sys, file, os etc... then these could be checked by identity against any > attribute returned It sounds like you're suggesting overriding the global attribute access mechanism. Is that right? So that every time Python encountered an attribute access, you would verify that the attribute being accessed is not on the 'dangerous' list? I don't know how to do that without basically rewriting some of Python's C code, though certainly I'm no expert in the area... Also, I'm not sure identity is sufficient: py> import sys py> import new py> new.module('newsys') py> newsys = new.module('newsys') py> newsys.__dict__.update(sys.__dict__) py> newsys is sys False py> newsys == sys False Steve From PeterMayne at ap.spherion.com Mon Jan 3 22:25:02 2005 From: PeterMayne at ap.spherion.com (PJDM) Date: 3 Jan 2005 19:25:02 -0800 Subject: [Hack] Import binary extensions from zipfiles, windows only References: Message-ID: <1104809102.966779.18480@f14g2000cwb.googlegroups.com> I'm trying to make ZopeX3 start faster by zipping up the "zope" directory. (Because this will be stored on a CD, having less data to read will make it quicker to start.) The standard python zipimporter won't work with the ZopeX3 .pyd files, so zipextimporter came along at just the right time. However, it doesn't seem to work for me (Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32, Windows XP SP2). Sample script: ---- import zipextimporter zipextimporter.install() import sys print 'Hooks:\n', sys.path_hooks sys.path.append(r'C:\tmp\zope.zip') print 'Path:\n', sys.path # Try an innocuous import first to make sure we have the path correct. import zope.server print 'Server file:\n', zope.server.__file__ # Now try a .pyd import. import zope.thread._zope_thread print 'Thread file:\n', zope.thread._zope_thread.__file__ ---- Output: ---- Hooks: [, ] Path: ['C:\\tmp', 'C:\\WINDOWS\\system32\\python23.zip', 'C:\\tmp', 'C:\\opt\\Python23\\DLLs', 'C:\\opt\\Python23\\lib', 'C:\\opt\\Python23\\lib\\plat-win', 'C:\\opt\\Python23\\lib\\lib-tk', 'C:\\opt\\Python23', 'C:\\opt\\Python23\\lib\\site-packages', 'C:\\tmp\\zope.zip'] Server file: C:\tmp\zope.zip\zope\server\__init__.py Traceback (most recent call last): File "zei.py", line 15, in ? import zope.thread._zope_thread ImportError: No module named _zope_thread ---- The zope.zip file contains zope.thread: ---- $ unzip -l zope.zip |grep zope/thread 0 11-08-04 11:00 zope/thread/ 0 07-03-04 04:34 zope/thread/DEPENDENCIES.cfg 65 07-28-04 22:52 zope/thread/SETUP.cfg 994 07-03-04 04:34 zope/thread/tests.py 748 11-08-04 11:00 zope/thread/tests.pyc 748 11-08-04 11:00 zope/thread/tests.pyo 20480 11-07-04 00:54 zope/thread/_zope_thread.pyd 7838 08-17-04 17:20 zope/thread/__init__.py 7808 11-08-04 11:00 zope/thread/__init__.pyc 7808 11-08-04 11:00 zope/thread/__init__.pyo ---- What am I missing? Thanks. PJDM From michele.simionato at gmail.com Wed Jan 26 08:27:48 2005 From: michele.simionato at gmail.com (michele.simionato at gmail.com) Date: 26 Jan 2005 05:27:48 -0800 Subject: FTP Server In-Reply-To: References: <1106743852.600769.72820@c13g2000cwb.googlegroups.com> Message-ID: <1106746068.798541.219240@c13g2000cwb.googlegroups.com> > If you're after a simple FTP server, have a look at medusa. Uhm ... Medusa does not seem actively maintained nowadays. M.S. From as006d4848 at blueyonder.co.uk Fri Jan 28 23:41:57 2005 From: as006d4848 at blueyonder.co.uk (Philip Smith) Date: Sat, 29 Jan 2005 04:41:57 GMT Subject: Elliptic Code References: <7x3bwl9n40.fsf@ruckus.brouhaha.com> Message-ID: Quite so - but thanks for your help in any case "Paul Rubin" wrote in message news:7x3bwl9n40.fsf at ruckus.brouhaha.com... > Nick Craig-Wood writes: >> > I understand the algorithm quite well but how to code the >> > multiplication >> > stage most efficiently in python eludes me. >> >> You might want to look at >> >> http://gmpy.sourceforge.net/ >> >> It has very fast multiplication up to any size you like! > > I think he's talking about point multiplication on the elliptic curve > group, not integer multiplication. From reinhold-birkenfeld-nospam at wolke7.net Sat Jan 1 16:25:53 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Sat, 01 Jan 2005 22:25:53 +0100 Subject: What can I do with Python ?? In-Reply-To: <1ssrl3pa3wawq.l1h3dq25szp9$.dlg@40tude.net> References: <1ssrl3pa3wawq.l1h3dq25szp9$.dlg@40tude.net> Message-ID: <33oir1F40vpumU2@individual.net> BOOGIEMAN wrote: > Beginners question, but really what can you do with it ? > How hard is Python to learn compared with other languages > (let's say C#). Can you make fullscreen game with it (for example) ? > I've looked at http://www.python.org but nothing concrete there For fullscreen games, see PyGame (www.pygame.org). BTW, I don't know of a way to write fullscreen games in C#... Reinhold From itsme at yahoo.com Tue Jan 4 13:16:39 2005 From: itsme at yahoo.com (It's me) Date: Tue, 04 Jan 2005 18:16:39 GMT Subject: Hlelp clean up clumpsy code References: Message-ID: What's "LBYL"? Oh...Look-before-you-leap. OK. I think I understand what's going on now (I read up on generator and iterators and my head still hurts). I knew there must be a cleaner way of "walking" around in Python. I will experiment with generator more. Thanks everybody. "Jp Calderone" wrote in message news:mailman.140.1104857018.22381.python-list at python.org... > > > On Tue, 04 Jan 2005 08:18:58 -0800, Scott David Daniels wrote: > >Nick Coghlan wrote: > > > A custom generator will do nicely: > > > > > > Py> def flatten(seq): > > > ... for x in seq: > > > ... if hasattr(x, "__iter__"): > > > ... for y in flatten(x): > > > ... yield y > > > ... else: > > > ... yield x > > > > Avoiding LBYL gives you: > > def flatten(seq): > > for x in seq: > > try: > > for y in flatten(x): > > yield y > > except TypeError: > > yield x > > But totally messes up on error handling. Instead: > > def flatten(seq): > for x in seq: > try: > subseq = iter(x) > except TypeError: > yield x > else: > for subx in flatten(subseq): > yield subx > > to avoid catching TypeErrors from .next(). > > Jp From bokr at oz.net Thu Jan 13 18:04:21 2005 From: bokr at oz.net (Bengt Richter) Date: Thu, 13 Jan 2005 23:04:21 GMT Subject: Octal notation: severe deprecation References: <1105481767.711530.116290@z14g2000cwz.googlegroups.com> <1105587098.932273.315230@c13g2000cwb.googlegroups.com> <39ednWfqlrgB6HvcRVn-iA@powergate.ca> Message-ID: <41e6f606.777680996@news.oz.net> On Thu, 13 Jan 2005 08:18:25 -0500, Peter Hansen wrote: >and-google at doxdesk.com wrote: >> In Mythical Future Python I would like to be able to use any base in >> integer literals, which would be better. Example random syntax: >> >> flags= 2x00011010101001 >> umask= 8x664 >> answer= 10x42 >> addr= 16x0E800004 # 16x == 0x >> gunk= 36x8H6Z9A0X > >I think I kinda like this idea. Allowing arbitrary values, >however, would probably be pointless, as there are very >few bases in common enough use that a language should make >it easy to write literals in any of them. So I think "36x" >is silly, and would suggest limiting this to 2, 8, 10, and >16. At the very least, a range of 2-16 should be used. >(It would be cute but pointless to allow 1x000000000. :-) > My concern is negative numbers when you are interested in the bits of a typical twos-complement number. (BTW, please don't tell me that's platform-specific hardware oriented stuff: Two's complement is a fine abstraction for interpreting a bit vector, which is another fine abstraction ;-) One way to do it consistently is to have a sign digit as the first digit after the x, which is either 0 or base-1 -- e.g., +3 and -3 would be 2x011 2x101 8x03 8x75 16x03 16xfd 10x03 10x97 Then the "sign digit" can be extended indefinitely to the left without changing the value, noting that -3 == 97-100 == 997-1000) and similarly for other bases: -3 == binary 101-1000 == 111101-1000000 etc. IOW, you just subtract base** if the first digit is base-1, to get the negative value. This would let us have a %.b format to generate the digits part and would get around the ugly hack for writing hex literals of negative numbers. def __repr__(self): return '<%s object at %08.16b>' %(type(self).__name__, id(self)) and you could write based literals in the above formats with e.g., with '16x%.16b' % number or '2x%.2b' % number etc. Regards, Bengt Richter From mhartl at post.harvard.edu Thu Jan 6 15:40:49 2005 From: mhartl at post.harvard.edu (mhartl at post.harvard.edu) Date: 6 Jan 2005 12:40:49 -0800 Subject: File Handling Problems Python I/O References: <1105025341.708019.126030@f14g2000cwb.googlegroups.com> <1105034789.700445.291380@z14g2000cwz.googlegroups.com> <1105043692.497106.315270@z14g2000cwz.googlegroups.com> Message-ID: <1105044049.815913.17830@z14g2000cwz.googlegroups.com> Sorry, the BASE variable should be 'C:\\' on Windows: >>> BASE = 'C:\\' >>> import os >>> os.path.join(BASE, 'foo', 'bar', 'baz') 'C:\\foo\\bar\\baz' From vze4rx4y at verizon.net Sun Jan 16 07:18:23 2005 From: vze4rx4y at verizon.net (Raymond Hettinger) Date: Sun, 16 Jan 2005 12:18:23 GMT Subject: generator expressions: performance anomaly? References: <1105854381.117059.59940@c13g2000cwb.googlegroups.com> Message-ID: "John Machin" wrote in message news:1105854381.117059.59940 at c13g2000cwb.googlegroups.com... > Please consider the timings below, where a generator expression starts > out slower than the equivalent list comprehension, and gets worse: > > >python -m timeit -s "orig=range(100000)" "lst=orig[:];lst[:]=(x for x > in orig)" . . . > >python -m timeit -s "orig=range(200000)" "lst=orig[:];lst[:]=(x for x > in orig)" This has nothing to do with genexps and everything to do with list slice assignment. List slice assignment is an example of a tool with a special case optimization for inputs that know their own length -- that enables the tool to pre-allocate its result rather than growing and resizing in spurts. Other such tools include tuple(), map() and zip(). The incredulous tone of the posting suggests a presumption that genexps always outperform list comps. That is not the case. Sometimes you want a list instead of a generator because you want more than just iteration; perhaps the consumer function may be able to take advantage of length reporting, indexing, slicing, re-iterability or other useful list behaviors. Also, the timing jig bites. Use xrange() instead of range(). Otherwise, there's an immediate forfeit of the memory savings normally being sought by the use of generators and iterators. > Background: There was/is a very recent thread about ways of removing > all instances of x from a list. /F proposed a list comprehension to > build the result list. FWIW, deques have a natural idiom for this kind of situation: for i in xrange(len(mydeque)): x = mydeque.popleft() if some_condition(x): mydeque.append(x) > Given a requirement to mutate the original list, > this necessitates the assignment to lst[:]. Sometimes people introduce arbitrary requirements and twist themselves in knots when real applications tend to allow a wider range of alternative solutions. There is a funky code smell emanating from any code resembling a[:]=some_iterator. It would make me examine how 'a' is being used and check whether the surrounding code can use the iterator or an new object. > Comments, clues, ... please. As a point of interest, note that Py2.4 improved some of its built-in iterators to report their length if requested. Now you now why. >>> d = dict(a=1, b=2, c=3, d=4) >>> len(d.iteritems()) 4 Raymond Hettinger From gene.tani at gmail.com Sun Jan 30 20:40:08 2005 From: gene.tani at gmail.com (gene.tani at gmail.com) Date: 30 Jan 2005 17:40:08 -0800 Subject: Help! Host is reluctant to install Python In-Reply-To: References: Message-ID: <1107135608.548166.243620@f14g2000cwb.googlegroups.com> Based on discusses with these guys, who know LAMP, python, ruby inside and out, and support it well: http://textdrive.com/ I'm guessing you'd have a hard time finding mod_python / apache hosting unless you get a dedicated server. It's pretty labor-intensive setup and admin-wise. linux shell / python / SSH shdn't be a big deal, tho. From tim.peters at gmail.com Wed Jan 26 22:51:02 2005 From: tim.peters at gmail.com (Tim Peters) Date: Wed, 26 Jan 2005 22:51:02 -0500 Subject: threading.py Condition wait overflow error In-Reply-To: <40E605146701DE428FAF21286A97D309174516@wphexa02.corp.lh.int> References: <40E605146701DE428FAF21286A97D309174516@wphexa02.corp.lh.int> Message-ID: <1f7befae050126195119b1ba9@mail.gmail.com> [Tim Peters] ... >> The most common cause for "impossible exceptions" > is flawed C code in an extension that fails to >> check a Python C API call for an error return. [Mark English] > Yes, I use a lot of C modules which I wrote. Then you know where to start looking . > It could certainly be one of them (although which one could be an > interesting challenge to find out). It may even have something to do > with moving to the VC7.1 compiler. Hard to say in advance. Since you have VC7.1, that opens a world of possiblities if you recompile Python. There are extra checks in ceval.c in a debug build, trying to catch "a call lied about whether it raised an exception" soon(er) after it happens. Rebuilding all your extensions in debug mode too could be a PITA, so you could get the same effect by #define'ing CHECKEXC in a release build. But a debug build has all sorts of extra checks that can help, and you could get into the debugger then and set a breakpoint on the unexpected OverflowError ... a quick check of the source shows that "long int too large to convert to int" is produced only by longobject.c's PyLong_AsLong() function. There's no way we _should_ be getting into that function by applying min() to floats, of course. > Thank you very much for your suggestion. Without it I would never have > thought to look at that code. Nobody ever does . From steve at holdenweb.com Fri Jan 14 16:55:56 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 14 Jan 2005 16:55:56 -0500 Subject: Refactoring; arbitrary expression in lists In-Reply-To: References: Message-ID: <_hXFd.75450$Jk5.55685@lakeread01> Peter Maas wrote: > Steven Bethard schrieb: > >> BJ?rn Lindqvist wrote: > > [...] > >>> I believe this can be nicelier written as: >>> >>> if "Makefile" in basename: >>> >> >> +1 for "nicelier" as VOTW (Vocabulation of the week) =) > > > Me too, because nicelier is nicer than more nicely. :) > Is that really the niceliest way to express that thought? regards-li-er y'rs - steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 From limodou at gmail.com Wed Jan 19 02:46:36 2005 From: limodou at gmail.com (limodou) Date: Wed, 19 Jan 2005 15:46:36 +0800 Subject: safest way to kill a thread In-Reply-To: <1106115159.200989.60870@c13g2000cwb.googlegroups.com> References: <1106106497.429643.307440@f14g2000cwb.googlegroups.com> <1106115159.200989.60870@c13g2000cwb.googlegroups.com> Message-ID: <41EE105C.6060407@gmail.com> I think only those threads which invoked with setDaemon() method will exit, and others will not, as the main program exit. martinnitram at excite.com wrote: > limodou wrote: > >>Using Thread's method setDaemon() before you call the start() method. >>Just like : >>t.setDaemon(True) >>t.start() > > thank for fast reply. > from python.org doc, said that setDaemon() function as > "The entire Python program exits when no active non-daemon threads > are left." > is it mean that when the main program exit (normally/abnormally), all > threads created will also exit? > Thank again. > -- I love python! My Blog: http://www.donews.net/limodou From gdr at integrable-solutions.net Sat Jan 29 00:57:11 2005 From: gdr at integrable-solutions.net (Gabriel Dos Reis) Date: 29 Jan 2005 06:57:11 +0100 Subject: what's OOP's jargons and complexities? References: <1106953849.915440.134710@f14g2000cwb.googlegroups.com> <360244F4lolueU1@individual.net> Message-ID: Martin Ambuhl writes: | Dan Perl wrote: | | > Actually, it can be as simple as: | > public class test { | | There is no "public" or "class" in C. Please don't post such trash to | comp.lang.c. In fact, C++ is not topical in any of the five But, it was anything but C++. Maybe Java. -- Gabriel Dos Reis gdr at integrable-solutions.net From richie at entrian.com Tue Jan 4 05:55:29 2005 From: richie at entrian.com (Richie Hindle) Date: Tue, 04 Jan 2005 10:55:29 +0000 Subject: Python! Is! Truly! Amazing! In-Reply-To: <1104657461.868175.252380@c13g2000cwb.googlegroups.com> References: <1104657461.868175.252380@c13g2000cwb.googlegroups.com> Message-ID: <2etkt0pstn12l5d4l2o28ivei9np7cl3a2@4ax.com> [Erik] > I am now a super gushing fan-boy. +1 Quote of the Week! -- Richie Hindle From bokr at oz.net Tue Jan 18 23:55:53 2005 From: bokr at oz.net (Bengt Richter) Date: Wed, 19 Jan 2005 04:55:53 GMT Subject: Has apparent 2.4b1 bug been fixed? flatten in Lib\compiler\ast.py overloads 'list' name Message-ID: <41ede67e.1232456679@news.oz.net> What am I missing? (this is from 2.4b1, so probably it has been fixed?) def flatten(list): l = [] for elt in list: ^^^^--must be expecting list instance or other sequence t = type(elt) if t is tuple or t is list: ^^^^--looks like it expects to refer to the type, not the arg for elt2 in flatten(elt): l.append(elt2) else: l.append(elt) return l Regards, Bengt Richter From fredrik at pythonware.com Thu Jan 27 15:44:50 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 27 Jan 2005 21:44:50 +0100 Subject: Question about 'None' References: <1106852591.770254.203560@z14g2000cwz.googlegroups.com> Message-ID: Steven Bethard wrote: > So None being smaller than anything (except itself) is hard-coded into Python's compare routine. > My suspicion is that even if/when objects of different types are no longer comparable by default > (as has been suggested for Python 3.0), None will still compare as smaller than anything... from the change log for Python 2.1: "An implementation detail changed in 2.1a1 such that None now compares less than any other object. Code relying on this new behavior (like code that relied on the previous behavior) does so at its own risk." the documentation (which I quoted earlier) still applies. From ncoghlan at iinet.net.au Fri Jan 14 02:15:02 2005 From: ncoghlan at iinet.net.au (Nick Coghlan) Date: Fri, 14 Jan 2005 17:15:02 +1000 Subject: Statement local namespaces summary (was Re: python3: 'where' keyword) In-Reply-To: <41e6dc9b.771173178@news.oz.net> References: <3480qqF46jprlU1@individual.net> <41DF78EB.6040502@iinet.net.au> <41dfc018.305122743@news.oz.net> <34cieoF489ejfU1@individual.net> <41E12700.8000106@iinet.net.au> <41e6dc9b.771173178@news.oz.net> Message-ID: <41E77176.9070002@iinet.net.au> Bengt Richter wrote: > Problems? (Besides NIH, which I struggle with regularly, and had to overcome to accept Tim's > starting point in this ;-) The ideas regarding creating blocks whose name bindings affect a different scope are certainly interesting (and relevant to the 'using' out-of-order execution syntax as well). Out-of-order execution appeals to me, but the ability to flag 'hey, this is just setup for something I'm doing later' might be a reasonable alternative (particularly with the affected names highlighted on the first line). As Jeff pointed out, it would be significantly less surprising for those encountering the construct for the first time. Folding code editors would be able to keep the setup clause out of the way if you really wanted to hide it. On the other hand, it might be feasible to construct a virtually identical out-of-order two suite syntax, similar to the mathematical phrasing "let f = c/lambda where f is the frequency, c is the speed of light and lambda is the wavelength". Either way, you've convinced me that two suites (and a new compound statement), as well as specifying which names can be rebound in the containing scope, is a better way to go than trying to mess with the definition of Python statements. On keywords, while 'let' is nice for assignments, I find it just doesn't parse properly when I put function or class definitions in the clause. So, I'll swap it for 'use' in the examples below. The statement could then be read "use these outer bindable names, and this additional code, in this suite". YMMV, naturally. Let's consider some of the examples given for 'where' using an in-order let/in type syntax (the examples only bind one name at a time, but would allow multiple names): # Anonymous functions use res: def f(x): d = {} exec x in d return d in: res = [f(i) for i in executable] # Declaring properties class C(object): use x: def get(self): print "Demo default" def set(self, value): print "Demo default set" in: x = property(get, set) # Design by contract use foo: def pre(): pass def post(): pass in: @dbc(pre, post) def foo(): pass # Singleton classes use C: class _C: pass in: C = _C() # Complex default values use f: def default(): return "Demo default" in: def f(x=default()): pass They actually read better than I expected. Nicely, the semantics of this form of the syntax *can* be articulated cleanly with current Python: use : in: as equivalent to: def __use_stmt(): def _in_clause(): return return _in_clause() __use_stmt_args = {} = __use_stmt() del __use_stmt Those semantics don't allow your switch statement example, though, since it doesn't use any magic to write to the outer scope - it's just a normal return and assign. However, I don't think starting with these semantics would *preclude* adding the ability to name the second block at a later date, and make the name rebinding part of executing that block - the standard usage doesn't really care *how* the names in the outer scope get bound, just so long as they do. Whether I think that's a good idea or not is an entirely different question :) Another aspect to consider is whether augmented assignment operations in the inner-scopes should work normally - if so, it would be possible to alter the semantics to include passing the existing values as arguments to the inner scopes. Moving on to considering a two-suite out-of-order syntax, this would have identical semantics to the above, but a syntax that might look something like: as : using: # Anonymous functions as res: res = [f(i) for i in executable] using: def f(x): d = {} exec x in d return d # Declaring properties class C(object): as x: x = property(get, set) using: def get(self): print "Demo default" def set(self, value): print "Demo default set" # Design by contract as foo: @dbc(pre, post) def foo(): pass using: def pre(): pass def post(): pass # Singleton classes as C: C = _C() using: class _C: pass # Complex default values as f: def f(x=default()): pass using: def default(): return "Demo default" Cheers, Nick. -- Nick Coghlan | ncoghlan at email.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.skystorm.net From http Fri Jan 7 02:20:40 2005 From: http (Paul Rubin) Date: 06 Jan 2005 23:20:40 -0800 Subject: Python evolution: Unease References: <7xacrpdxy3.fsf@ruckus.brouhaha.com> <7x652che6z.fsf@ruckus.brouhaha.com> <7x4qhw859p.fsf@ruckus.brouhaha.com> <7xk6qrnbum.fsf@ruckus.brouhaha.com> <41dcaa00.102858012@news.oz.net> <7x652bnhx0.fsf@ruckus.brouhaha.com> <41dcf582.122188317@news.oz.net> <7xd5wh7qdf.fsf@ruckus.brouhaha.com> Message-ID: <7xpt0h66yf.fsf@ruckus.brouhaha.com> Roman Suzi writes: > I do not like the idea of having stubs. Once I had an experience working with > CPAN (I tried to install SpamAssassin and it required some specific modules.) > "Magic" install shell, provided by Perl, upgraded half the Perl distro, > including newer version of Perl! > > So, I do like Python distutils better. it is not a major problem to > install something even if it required something else. Of course, > this depends on the package authors. But distutils don't help the problem that the module requires stuff that's missing. That's what happened with the thing I downloaded last week, that needed wxPython. I don't understand why the author felt he had to use wxPython instead of tkinter, since it wasn't a really fancy gui, but after already-described hassles trying to instead wxPython, I just used the application's command line interface instead, which worked fine. But if wxPython is so much better, maybe it's time for Python to include it. I want to start using Audacity pretty soon, which I think really does depend on wxPython, so I'm going to have to deal with this wxPython installation problem which is definitely not completely trivial. What a pain. > Yes, probably there could be a no-brainer script to run install > directly from zip and/or tar.gz/bz2 file, but I usually check > md5, pgp sigs and look inside anyway before running something. I thought distutils doesn't have any code-signing features. From kartic.krishnamurthy at gmail.com Thu Jan 13 11:01:52 2005 From: kartic.krishnamurthy at gmail.com (Kartic) Date: 13 Jan 2005 08:01:52 -0800 Subject: Free python server. In-Reply-To: <1105631360.938494.286750@c13g2000cwb.googlegroups.com> References: <1105631360.938494.286750@c13g2000cwb.googlegroups.com> Message-ID: <1105632112.104412.183870@f14g2000cwb.googlegroups.com> And yes, they have python installed... From richie at entrian.com Tue Jan 4 06:06:50 2005 From: richie at entrian.com (Richie Hindle) Date: Tue, 04 Jan 2005 11:06:50 +0000 Subject: hidding the "console" window + system global shortcut keys In-Reply-To: <2814F26DA6908F41927A81C410C4991A02079C19@siamun.server.bl.corp.intranet> References: <2814F26DA6908F41927A81C410C4991A02079C19@siamun.server.bl.corp.intranet> Message-ID: [Gabriel] > 2. Set global key biddings. You can do this using ctypes: http://groups.google.co.uk/groups?selm=mailman.929.1069345408.702.python-list%40python.org -- Richie Hindle richie at entrian.com From craig at postnewspapers.com.au Mon Jan 3 10:28:32 2005 From: craig at postnewspapers.com.au (Craig Ringer) Date: Mon, 03 Jan 2005 23:28:32 +0800 Subject: removing comments form a file In-Reply-To: References: Message-ID: <1104766112.4535.5.camel@albert.localnet> On Mon, 2005-01-03 at 11:46 -0300, Batista, Facundo wrote: > - Used file instead of open, to don't read the whole file in memory. [craig at albert ~]$ python Python 2.3.4 (#1, Oct 26 2004, 16:42:40) .>>> file is open True .>>> print repr(file), repr(open) I'd be interested if you could clarify what you mean there. As far as I know, the whole file will only be read into memory if you use file.read () or file.readlines(). If you use an iterator it does internal readahead, but won't read the lot at once. If you use read() it reads only what you say. -- Craig Ringer From pedro.werneck at terra.com.br Mon Jan 24 10:04:11 2005 From: pedro.werneck at terra.com.br (Pedro Werneck) Date: Mon, 24 Jan 2005 13:04:11 -0200 Subject: TCP server In-Reply-To: <1106576718.263709.280380@c13g2000cwb.googlegroups.com> References: <1106576718.263709.280380@c13g2000cwb.googlegroups.com> Message-ID: <20050124130411.1a91fa65.pedro.werneck@terra.com.br> A quick example for you: ### import SocketServer class EchoRequestHandler(SocketServer.BaseRequestHandler): def setup(self): print self.client_address, 'connected!' self.request.send('hi ' + str(self.client_address) + '\n') def handle(self): while 1: data = self.request.recv(1024) self.request.send(data) if data.strip() == 'bye': return def finish(self): print self.client_address, 'disconnected!' self.request.send('bye ' + str(self.client_address) + '\n') #server host is a tuple ('host', port) server = SocketServer.ThreadingTCPServer(('', 5000), EchoRequestHandler) server.serve_forever() ### Telnet to localhost 5000 and any data you sent will be echoed back to you... send 'bye' and the connection is closed On 24 Jan 2005 06:25:18 -0800 "assaf" wrote: > i am try to create a server > what am i suppose to send to SocketServer.TCPServer > what is the client_address ("127.0.0.1:80" ?) > and BaseRequestHandler = ? > > thanks > > -- > http://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Fri Jan 28 14:48:24 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 28 Jan 2005 14:48:24 -0500 Subject: py.dll for version 2.2.1 (Windows) References: <1106937199.667357.42040@z14g2000cwz.googlegroups.com> Message-ID: "mike" wrote in message news:1106937199.667357.42040 at z14g2000cwz.googlegroups.com... > Just recently, my virus checker detected what it called a Trojan Horse > in the py.dll file in the python22 folder. Installation is version > 2.2.1 and I think that it came installed when I bought the PC in > October 2002. My HP came with 2.2 also, but nothing caught by McAfee > Does anyone know where I can get a copy of the py.dll file from version > 2.2.1 for Windows (XP) ? > > I looked at www.python.org and do not see a py.dll file in the > self-installation or .tgz versions of 2.2.1 that are posted. If the installer is not a selectively extractable archive, delete and reinstall fresh might be easiest. Terry J. Reedy From deetsNOSPAM at web.de Thu Jan 20 12:20:33 2005 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Thu, 20 Jan 2005 18:20:33 +0100 Subject: What YAML engine do you use? References: <35a6tpF4gmat2U1@individual.net> Message-ID: <35a7grF4jjrcsU1@individual.net> > I know that there are different YAML engines for Python out there (Syck, > PyYaml, more?). > > Which one do you use, and why? I first used yaml, tried to migrate to syck. What I like about syck is that it is faster and doesn't try to create objects but only dicts - but it crashed if the number of yaml objects grew larger. So I still use yaml. > > For those of you who don't know what YAML is: visit http://yaml.org/! > You will be amazed, and never think of XML again. Well, almost. It is certainly nice. -- Regards, Diez B. Roggisch From fredrik at pythonware.com Mon Jan 24 17:19:06 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 24 Jan 2005 23:19:06 +0100 Subject: What's so funny? WAS Re: rotor replacement References: <7x1xcidnp1.fsf@ruckus.brouhaha.com><41EE24F7.7030303@jessikat.fsnet.co.uk><7x1xchlpqv.fsf@ruckus.brouhaha.com><41efeb82$0$27807$9b622d9e@news.freenet.de><41f1a70b$0$25959$9b622d9e@news.freenet.de><7xbrbiqdhk.fsf@ruckus.brouhaha.com><7xllalljah.fsf@ruckus.brouhaha.com><7xekgdmpll.fsf@ruckus.brouhaha.com><7xpszxcnfa.fsf@ruckus.brouhaha.com><7xllalcmqc.fsf@ruckus.brouhaha.com><7xbrbhosh7.fsf@ruckus.brouhaha.com><7xzmz0lw6h.fsf@ruckus.bro Message-ID: wrote > As an app writer I want to publish code that runs on multiple > platforms without needing special attention from the end user, and > preferably without needing special platform-specific attention from > me. please answer the question: have you done this? what kind of programs have you successfully delivered as "self-contained apps" for use on arbi- trary platforms? From klachemin at comcast.net Fri Jan 7 11:02:23 2005 From: klachemin at comcast.net (Kamilche) Date: 7 Jan 2005 08:02:23 -0800 Subject: Calling Function Without Parentheses! In-Reply-To: <41D8B5F4.1010903@mxm.dk> References: <1104715584.407505.190910@f14g2000cwb.googlegroups.com> <41D8B5F4.1010903@mxm.dk> Message-ID: <1105113743.189469.115440@f14g2000cwb.googlegroups.com> Yeah, but still. If they even had the most basic check, like 'an object is being referred to on this line, but you're not doing anything with it' would be handy in catching that. When you use an object like that, usually you're doing something with it, like assigning it to a variable. From sean_mcilroy at yahoo.com Fri Jan 14 15:28:37 2005 From: sean_mcilroy at yahoo.com (Sean McIlroy) Date: 14 Jan 2005 12:28:37 -0800 Subject: reusing Tkinter Canvases Message-ID: I'd like to save one Tkinter Canvas in order to use it on another Canvas later. The problem is that it gets saved as EPS but it needs to be GIF to be reuseable. How can I convert that format? Peace, STM From aleaxit at yahoo.com Fri Jan 28 04:20:17 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 28 Jan 2005 10:20:17 +0100 Subject: Question about 'None' References: <1106852591.770254.203560@z14g2000cwz.googlegroups.com> Message-ID: <1gr3gdr.15hwalixjl91xN%aleaxit@yahoo.com> flamesrock wrote: ... > (The reason I ask is sortof unrelated. I wanted to use None as a > variable for which any integer, including negative ones have a greater > value so that I wouldn't need to implement any tests or initializations > for a loop that finds the maximum of a polynomial between certain x > values. Anything is greater than nothing, no?) To have this work reliably across versions of Python (and you mentioned you need it to work on 2.0 as well as 2.3...) you have to make your own sentinel class, such as: class MinusInfinity: def __cmp__(self, other): if isinstance(other, MinusInfinity): return 0 else: return -1 minusInfinity = MinusInfinity() Now, you should be able to use this 'minusInfinity" as ``a variable for which any integer ... has a greater value'', as you wished to use None. (Untested code, as I don't have any 2.0 on which to test it anyway). Alex From peter at engcorp.com Sun Jan 9 13:51:59 2005 From: peter at engcorp.com (Peter Hansen) Date: Sun, 09 Jan 2005 13:51:59 -0500 Subject: read numbers from file and covert to integer In-Reply-To: References: Message-ID: ?ystein Western wrote: > I got a file with a lot blocks of numbers that are strings. I'd like to read > all > this numbers and convert them to numbers for futher compareation. How can I > convert all this numbers to integer? Do I have to put all numbers into a > list? It would help immensely if you could post some kind of example of the sorts of data you are talking about, perhaps a hex representation of the bytes (if it's a binary file). Otherwise we are just guessing how you are using the terms "block", "number", "string", and even "integer". -Peter From itsme at yahoo.com Mon Jan 10 19:11:01 2005 From: itsme at yahoo.com (It's me) Date: Tue, 11 Jan 2005 00:11:01 GMT Subject: complex numbers References: <1105259798.863970.314750@c13g2000cwb.googlegroups.com> Message-ID: For those of us that works with complex numbers, having complex number as a natively supported data type is a big advantage. Non-native add-ons are not sufficient and lead to very awkward program code. "J?rgen Exner" wrote in message news:Fm6Ed.3556$u47.321 at trnddc09... > xah at xahlee.org wrote: > > #python supports complex numbers. > [...] > > So? > The world would come to a halt if all of a sudden nobody understands complex numbers anymore. :-) > > # Perl doesn't support complex numbers. But there are packages that > > supports it. > > The Math::Complex module is part of the standard installation already, no > need for any "packages" (whatever that might be). > Did you check "perldoc Math::Complex" > > NAME > Math::Complex - complex numbers and associated mathematical functions > [...] > > jue > > From http Sun Jan 9 20:49:19 2005 From: http (Paul Rubin) Date: 09 Jan 2005 17:49:19 -0800 Subject: python3: 'where' keyword References: <3480qqF46jprlU1@individual.net> <1105228549.608275.148740@c13g2000cwb.googlegroups.com> <7xk6qnzd3d.fsf@ruckus.brouhaha.com> <1105230350.861683.265970@c13g2000cwb.googlegroups.com> <7x3bxbe97m.fsf@ruckus.brouhaha.com> <7xsm5b2m93.fsf@ruckus.brouhaha.com> <7xr7ku26zs.fsf@ruckus.brouhaha.com> <1105319590.641211.191630@c13g2000cwb.googlegroups.com> Message-ID: <7xllb2f3z4.fsf@ruckus.brouhaha.com> "Carl Banks" writes: > And a suite, be it a def statement, a where block, or whatever, belongs > in a statement, not an expression. So do you approve of the movement to get rid of the print statement? From db3l at fitlinxx.com Mon Jan 17 17:34:35 2005 From: db3l at fitlinxx.com (David Bolen) Date: 17 Jan 2005 17:34:35 -0500 Subject: extension module, thread safety? References: Message-ID: Torsten Mohr writes: > The question came up if this is by itself thread safe, > if some two or more threads try to change these data types, > are the C functions by themselves are "atomic" or can they > be interrupted be the perl interpreter and then (data types > are in some inconsistent half-changed state) another function > that works on these data is called? I presume you mean "Python" and not "perl"... If the threads under discussion are all Python threads, then by default yes, the extension module C functions will appear to be atomic from the perspective of the Python code. When the Python code calls into the extension module, the GIL (global interpreter lock) is still being held. Unless the extension module code explicitly releases the GIL, no other Python threads can execute (even though those threads are in fact implemented as native platform threads). So in general, if you write an extension module where none of its functions ever release the GIL, there's no way for two of its functions to be run from different Python threads simultaneously. Note that this restriction won't necessarily hold if there are other ways (at the C level, or from other extension modules) to trigger code in the extension module, since that's outside of the control of the Python GIL. Nor will it necessarily hold true if your extension module calls back out into Python (as a callback, or whatever) since once the interpreter is back in Python code the interpreter itself will periodically release the GIL, or some other extension code that the callback code runs may release it. To the extent possible, it's considered good practice to release the GIL in an extension module whenever you are doing lengthy processing so as to permit other Python threads (that may have nothing to do with using your extension module) to execute. For short routines this really isn't an issue, but if your extension module will be spending some time managing its data, you may wish to add some internal thread protection around that data, so that you can use your own locks rather than depending on the GIL. -- David From boomberschloss at yahoo.com Fri Jan 14 10:46:48 2005 From: boomberschloss at yahoo.com (Joachim Boomberschloss) Date: Fri, 14 Jan 2005 07:46:48 -0800 (PST) Subject: Integration with java In-Reply-To: Message-ID: <20050114154648.70925.qmail@web53103.mail.yahoo.com> Hello, I am working on a project in Python, and I"m currently looking into the possibiliy of writing some of the project"s modules in Java. Given that a large part of the code is already written in Python, using the standard libraries and several extension modules, I am trying to gauge the viability of integration with Java via Jython with minimal impact on present code, on the complexity of future code, and on deadlines! I need to know in general how dirty it will be to combine the two languages, and what the costs I should take into account are. I"m also interested to know if there are any commonly accepted strategies to fully switch project languages (I"m considering, in the extreme case, to change it all into Java), and if writing some modules in Java and replacing the rest gradually makes sense. Three more specific questions I thought of: 1. Is is possible to pack a Jython/Java program in a py2exe-like fashion? Is it possible to pack in such a way both Python, Jython and Java code? 2. Does transferring large data structures between Java and Python code running by Jython have a significant effect on memory? For example, would passing the result of a large database query from Java to Jython, for further processing, cause the entire data to be duplicated or something similar? 3. Did I miss anything fundemental? Thanks! Joe. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From reinhold-birkenfeld-nospam at wolke7.net Fri Jan 21 14:26:36 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Fri, 21 Jan 2005 20:26:36 +0100 Subject: What YAML engine do you use? In-Reply-To: References: <35a6tpF4gmat2U1@individual.net> <7x1xcfwbab.fsf@ruckus.brouhaha.com> <35csm7F4l57inU1@individual.net> Message-ID: <35d3bcF4k9t5mU1@individual.net> A.M. Kuchling wrote: > On Fri, 21 Jan 2005 18:54:50 +0100, > Fredrik Lundh wrote: >> judging from http://yaml.org/spec/current.html (750k), the YAML designers are >> clearly insane. that's the most absurd software specification I've ever seen. they >> need help, not users. > > IMHO that's a bit extreme. Specifications are written to be detailed, so > consequently they're torture to read. Seen the ReStructured Text spec > lately? Agreed. If you just want to use it, you don't need the spec anyway. > The basic idea -- a data dumping format that's human-readable -- isn't a bad > one. OTOH, I can't recall wanting such a thing -- when I want readable > output I'm happy using > unreadable pickle files, unpickling the object and calling a .dump() or > .as_text() method.) > > But YAML seems to have started out with the goal of being human-writable, > something you would write in Emacs, Exactly. I use it as a format for config files the user can edit directly without much thinking (the explanation on top of the file are 3 lines). > and that seems to have gotten lost; the > format is now just as complicated as Restructured Text, but more cryptic > (the URI namespacing for tags, for example), not really simpler than > XML and in some ways weaker (e.g. only two encodings supported, more > complicated escaping rules). In most cases you don't need the complicated things, and the http://www.yaml.org/refcard.html isn't very complex either. Reinhold From pierre.barbier at cirad.fr Fri Jan 14 02:36:46 2005 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Fri, 14 Jan 2005 08:36:46 +0100 Subject: Unclear On Class Variables In-Reply-To: References: Message-ID: <41e77621$0$19576$636a15ce@news.free.fr> Antoon Pardon a ?crit : >>Well I find this a confusing behaviour on python's part. The fact >>that instance.field can mean something different, depending on >>where in a statement you find it, makes the behaviour inconsistent. >> >>I know people in general here are against declarations, but declarations >>could IMO provide more consistency here and thus more obvious behaviour. > > > Well just to show how confusing python can be, the following piece of > code. > > | class Spam: > | eggs = [2, 3] > | > | > | sp1 = Spam() > | sp2 = Spam() > | > | print sp1.eggs, id(sp1.eggs) > | print sp2.eggs, id(sp2.eggs) > | print '--------------------' > | > | sp1.eggs += [4,] > | > | print sp1.eggs, id(sp1.eggs) > | print sp2.eggs, id(sp2.eggs) > | print '--------------------' > | > | Spam.eggs = [3,5] > | > | print sp1.eggs, id(sp1.eggs) > | print sp2.eggs, id(sp2.eggs) > | print '--------------------' > > Which produces: > > [2, 3] 1075958860 > [2, 3] 1075958860 > -------------------- > [2, 3, 4] 1075958860 > [2, 3, 4] 1075958860 > -------------------- > [2, 3, 4] 1075958860 > [3, 5] 1075959084 > -------------------- > Well ... and could someone explain this behaviour ? I don't catch it ! Pierre From invalidemail at aerojockey.com Sun Jan 9 00:44:47 2005 From: invalidemail at aerojockey.com (Carl Banks) Date: 8 Jan 2005 21:44:47 -0800 Subject: python3: accessing the result of 'if' In-Reply-To: References: <3480qqF46jprlU1@individual.net> <1105169372.800346.298830@f14g2000cwb.googlegroups.com> <1105236383.521393.40680@c13g2000cwb.googlegroups.com> Message-ID: <1105249487.644698.309100@c13g2000cwb.googlegroups.com> Nick Coghlan wrote: > Carl Banks wrote: > > What if the condition you wanted to test wasn't the same as the thing > > you want to save? In other words, how would you convert this? > > > > . where: > > . m = something() > > . if m > 20: > > . do_something_with(m) > > Yeah, this problem eventually occurred to me as well. However, I think a little > utility function can help solve it: > > def test(val, condition): > if condition(val): > return val > else: > return None > > if test(something(), lambda x: x < 10) as m: > print "Case 1:", m > elif test(something(), lambda x: x > 20) as m: > print "Case 2:", m > else: > print "No case at all!" I'm sorry, I really can't agree that this helper function "solves" it. IMO, it's a workaround, not a solution. And, if I may be frank, it's a pretty ugly one. Not only that, but it still doesn't work. What if the object itself is false? -- CARL BANKS From tjreedy at udel.edu Tue Jan 4 16:53:08 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 4 Jan 2005 16:53:08 -0500 Subject: Python evolution: Unease References: <41da4a3f$0$17626$e4fe514c@dreader13.news.xs4all.nl><1gpv286.1kccndo1l4coseN%aleaxit@yahoo.com> Message-ID: "Bulba!" wrote in message > E.g. right now I would kill for a standard, built-in matrix > type The array types of Numerical Python (NumPy) and now Numarray are, defacto, Python's standard 1 to n dimensional array types. Once installed, they are as builtin as anything else. Several other packages build on top of them. > that would be as flexible as lists and dictionaries are > in Python, so that I could slurp the whole CSV file or some > other table in one instruction into a matrix that could > accomodate data types likes strings and floats (just like > dictionaries do - just, say, declare, "column 1 of matrix > contains strings, and please convert the values in column 2 > into floats"), and then easily do some fancy matrix > transformations. Numarray has a record array type. If there is not one publicly available, perhaps you could write a CSV file to record-array slurper and contribute it to the Recipes site or maybe even the CSV module. Terry J. Reedy From hodmann at lycos.nl Wed Jan 26 07:56:10 2005 From: hodmann at lycos.nl (robert) Date: 26 Jan 2005 04:56:10 -0800 Subject: execute python code from db Message-ID: Hello, Anybody knows if it's possible to execute python code from an db. db=MySQLdb.connect(host="localhost",user="r",passwd="j",db="v") c=db.cursor() c.execute("""SELECT * FROM table WHERE id = %s""", (id,)) for python_code in c.fetchall(): execute (python_code) Maybe feed python with stdin??. robert. From xah at xahlee.org Thu Jan 13 07:41:38 2005 From: xah at xahlee.org (Xah Lee) Date: 13 Jan 2005 04:41:38 -0800 Subject: how to stop google from messing Python code Message-ID: <1105620098.878376.110250@z14g2000cwz.googlegroups.com> i'm using groups-beta.google.com to post python code. Is there a way to stop google from messing with my format? it seems to have eaten the spaces in my python code. thanks. Xah xah at xahlee.org http://xahlee.org/PageTwo_dir/more.html From dbickett at gmail.com Sun Jan 16 13:27:57 2005 From: dbickett at gmail.com (Daniel Bickett) Date: Sun, 16 Jan 2005 13:27:57 -0500 Subject: threading and sockets ? In-Reply-To: References: Message-ID: <1d6cdae3050116102711c5c041@mail.gmail.com> http://www.twistedmatrix.com/ Daniel Bickett From harold.fellermann at upf.edu Tue Jan 18 14:54:42 2005 From: harold.fellermann at upf.edu (harold fellermann) Date: Tue, 18 Jan 2005 20:54:42 +0100 Subject: pickling extension class In-Reply-To: <1gqlpxp.g66j8sl6zkutN%aleaxit@yahoo.com> References: <1gqlpxp.g66j8sl6zkutN%aleaxit@yahoo.com> Message-ID: On 18.01.2005, at 20:31, Alex Martelli wrote: > harold fellermann wrote: > >> File "/sw/lib/python2.4/pickle.py", line 760, in save_global >> raise PicklingError( >> pickle.PicklingError: Can't pickle : it's >> not found as hyper.PeriodicGrid >>>>> dir(hyper) >> ['Dir', 'Neighbors', 'PeriodicGrid', 'PeriodicPos', '__doc__', >> '__file__', '__name__', 'refcount'] >>>>> hyper.PeriodicGrid >> >> >> So pickle complains about the class PeriodicGrid not being found in >> the >> module hyper, but a dir() >> proves that python can find it. Has anyone an idea what's going wrong >> here? > > These symptomps are pretty weird -- let's try to pin things down a bit > more. The relevant few lines of pickle.py are: > > try: > __import__(module) > mod = sys.modules[module] > klass = getattr(mod, name) > except (ImportError, KeyError, AttributeError): > raise PicklingError( > > so, could you please edit your pickle.py to provide VASTLY more info, [...] > and let us know exactly what his modified pickle.py outputs...? Here it goes...: OOPS, error (exceptions.ImportError): No module named hyper Traceback (most recent call last): File "pickle_test.py", line 5, in ? pickle.dump(g,file("test","w")) File "/Volumes/space/Users/harold/uni/pace/ono/pickle.py", line 1387, in dump Pickler(file, protocol, bin).dump(obj) File "/Volumes/space/Users/harold/uni/pace/ono/pickle.py", line 231, in dump self.save(obj) File "/Volumes/space/Users/harold/uni/pace/ono/pickle.py", line 338, in save self.save_reduce(obj=obj, *rv) File "/Volumes/space/Users/harold/uni/pace/ono/pickle.py", line 414, in save_reduce save(func) File "/Volumes/space/Users/harold/uni/pace/ono/pickle.py", line 293, in save f(self, obj) # Call unbound method with explicit self File "/Volumes/space/Users/harold/uni/pace/ono/pickle.py", line 765, in save_global raise PicklingError( pickle.PicklingError: Can't pickle : it's not found as hyper.PeriodicGrid I have noticed that the error does not occur, when the imported module ('hyper') is in the same directory as the script that pickles. When it is imported from a subpackage (like in the code I sent you) it goes wrong. - harold - -- Reality is for people who lack imagination. From http Sun Jan 2 00:08:58 2005 From: http (Paul Rubin) Date: 01 Jan 2005 21:08:58 -0800 Subject: Frameworks for "Non-Content Oriented Web Apps" References: <1104641466.776338.71700@z14g2000cwz.googlegroups.com> Message-ID: <7xd5woa045.fsf@ruckus.brouhaha.com> Tim Churches writes: > Can you give some URL for publicly accessible examples of what you > mean by a "NON CONTENT-ORIENTED WEB APPLICATIONS", so we can get a > better idea of what you mean? I don't think there was anything unclear about it. A spreadsheet might be a good example. From ianb at colorstudy.com Fri Jan 7 15:39:01 2005 From: ianb at colorstudy.com (Ian Bicking) Date: Fri, 07 Jan 2005 14:39:01 -0600 Subject: Exception report library Message-ID: <41DEF365.4030209@colorstudy.com> I've been using one of several systems to catch unexpected exceptions and log them (e.g., write to a file, display on web page, email me, etc). But many are built into a particular system, or have an interesting but incomplete set of features. E.g., many web frameworks have exception reporters (and the stdlib includes cgitb), but I want to handle non-web exceptions in the same way as exceptions from web requests, and that's not generally easy. So, I'm figuring there should be some generic library that does this. Does anyone have experience with one they could recommend? PyCrash comes to mind: http://pycrash.sourceforge.net/, though the XML output doesn't excite me (but the post-mortem debugging data is nice). py.test makes nice tracebacks with extra data as well, and cgitb is another option, though I've found the code to be poorly factored for reusability when I've looked at it in the past. Zope includes an otherwise-Zope-neutral ExceptionFormatter, which isn't terribly exciting, except that it does look for __traceback_info__ local variables and create reports with those inlined. Maybe there's something better that's packaged as part of a larger framework? Does anyone have good or bad experience with PyCrash? Localized application extensibility is really useful to me as well; for instance, in a web application I like to know who the logged-in user is, and all sorts of environment information, and there's no way to do that that is common to all the environments I'd like this to work in. On the reporting end configuration and hooks are also really useful; e.g., there's no general way to display an exception report on a web page, so a web framework would have to hook into it in some way as well. I feel like there must be something out there, since every Python programmer has to deal with this sort of thing to some degree...? -- Ian Bicking / ianb at colorstudy.com / http://blog.ianbicking.org From macrocosm at fastmail.fm Thu Jan 6 18:37:29 2005 From: macrocosm at fastmail.fm (Arich Chanachai) Date: Thu, 06 Jan 2005 18:37:29 -0500 Subject: Python Operating System??? In-Reply-To: <10trb0mgiflcj4f@corp.supernews.com> References: <10trb0mgiflcj4f@corp.supernews.com> Message-ID: <41DDCBB9.9020202@fastmail.fm> David Brown wrote: >Hello. I recently came across a free operating system called Unununium (or >something like that) and it was developed in Python and Assembly. > >Now, I have been looking for a way to make an operating system for a long >long time and the only possibilities I could find were C++ and assembly. I >don't mind assembly so much if I don't have to use it very often. But C++ is >so complicated and errors are pretty much impossible to find in the code for >me. > >So, I was wondering if it would be possible to find a bootloader that loads >a python file at startup or something... > >Is there an example somewhere of a Python OS? > >Thanks! > > > > People don't make Python OSs because it's a serious pain in the Deng-Xiao-ping. J/k, I am half kidding. Go to google groups, and search for Python OS. You will find that this topic has been discussed numerous times. There was another project other than Unununium which was Python based, but it is not being developed any longer and I fail to remember what it was called. So search away, you will find many results! Alternatively you could contact the Unununium folks for help. Note also that there are Java OSs as well (and probably others). But then again, if you don't like C++, you probably won't like Java. They can be very different languages, but in my experience, the reasons why one does not like C++ is usually due to a quality/flaw that can also be found in Java. From jbperez808 at wahoo.com Wed Jan 12 17:06:30 2005 From: jbperez808 at wahoo.com (Jon Perez) Date: Thu, 13 Jan 2005 06:06:30 +0800 Subject: "Architecture of Python" was removed ? In-Reply-To: References: <004801c4f7cb$f62d1d30$1d02a8c0@cr> Message-ID: <34llb0F4apou6U1@individual.net> Skip Montanaro wrote: > Yes, perhaps. Note that it doesn't appear that the Wayback Machine contains > the meat of the essay, just the front page. It came from a wiki. Perhaps Most of the text seems to be there, but there are some critical diagrams (images) which the Wayback Machine did not archive. From stephen.thorne at gmail.com Wed Jan 12 22:07:12 2005 From: stephen.thorne at gmail.com (Stephen Thorne) Date: Thu, 13 Jan 2005 13:07:12 +1000 Subject: Octal notation: severe deprecation In-Reply-To: <1105575689.335040.174490@c13g2000cwb.googlegroups.com> References: <1105481767.711530.116290@z14g2000cwz.googlegroups.com> <1105575689.335040.174490@c13g2000cwb.googlegroups.com> Message-ID: <3e8ca5c805011219073b98cb64@mail.gmail.com> On 12 Jan 2005 16:21:29 -0800, PJDM wrote: > Maybe P3K will have an integer literal like "n_b" for "the integer n in > base b". I would actually like to see pychecker pick up conceptual errors like this: import datetime datetime.datetime(2005, 04,04) Regards, Stephen Thorne From jeff at ccvcorp.com Fri Jan 7 15:06:42 2005 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 07 Jan 2005 12:06:42 -0800 Subject: The Industry choice In-Reply-To: References: <10trej2fl8dip65@corp.supernews.com> Message-ID: <10ttqk8k1e64495@corp.supernews.com> Bulba! wrote: > On 6 Jan 2005 19:01:46 -0500, aahz at pythoncraft.com (Aahz) wrote: > > >>>Note that the so-called 'viral' nature of GPL code only applies to >>>*modifications you make* to the GPL software. The *only* way in which >>>your code can be 'infected' by the GPL is if you copy GPL source. > > >>That's not true -- consider linking to a GPL library. > > > Will someone please explain to me in simple terms what's > the difference between linking to LGPLed library and linking > to GPLed library - obviously in terms of consequences of > what happens to _your_ source code? > > Because if there isn't any, why bother with distinguishing > between the two? Releasing a product in which your code is linked together with GPL'ed code requires that your code also be GPL'ed. The GPL goes to some lengths to define what exactly "linked together" means. Releasing a product in which your code is linked together with LGPL'ed code does *not* require that your code also be (L)GPL'ed. Changes to the core library must still be released under (L)GPL, but application code which merely *uses* the library does not. (I've forgotten, now, exactly how LGPL defines this distinction...) Jeff Shannon Technician/Programmer Credit International From jstroud at mbi.ucla.edu Mon Jan 24 19:31:13 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 24 Jan 2005 16:31:13 -0800 Subject: What's so funny? WAS Re: rotor replacement In-Reply-To: <41f589f9$0$3357$9b622d9e@news.freenet.de> References: <7x1xcidnp1.fsf@ruckus.brouhaha.com> <41EE24F7.7030303@jessikat.fsnet.co.uk> <7x1xchlpqv.fsf@ruckus.brouhaha.com> <41efeb82$0$27807$9b622d9e@news.freenet.de> <41f1a70b$0$25959$9b622d9e@news.freenet.de> <7xbrbiqdhk.fsf@ruckus.brouhaha.com> <7xllalljah.fsf@ruckus.brouhaha.com> <7xekgdmpll.fsf@ruckus.brouhaha.com> <7xpszxcnfa.fsf@ruckus.brouhaha.com> <7xllalcmqc.fsf@ruckus.brouhaha.com> <7xbrbhosh7.fsf@ruckus.brouhaha.com> <7xzmz0lw6h.fsf@ruckus.brouhaha.com> <41f4324a$0$1547$9b622d9e@news.freenet.de> <41f589f9$0$3357$9b622d9e@news.freenet.de> Message-ID: <1106613073.2400.104.camel@lipscomb.mbi.ucla.edu> Martin v. L?wi said > Hmm. Most applications don't have any crypto needs. Any program where one stores data would have crypto needs. Here are some examples: Database, wordprocessor, spreadsheet, address book, mail program, (should I go on?). What would be the alternative to encryption to satisfy the functionality encryption provides...memorization? But I believe this may be a case of things being so obvious people forget their importance (e.g. breathing). I have written a class that goes something like this (highly simplified) class encryptFilter: def __init__(acipher): self.mycipher = acipher def open(self, filename): self.myfile = open(filename,"w") def write(data): encrypted_data = self.encrypt(data) self.myfile.write(encrypted_data) etc... Now what if acipher and this class could be made from part of the core distro? Any application could have the option of encryption with only a few lines of code: import std_crypt # other code here if get_user_pref("do_encryption"): password = my_get_password() acipher = std_crypt.AES(password) outfile = std_crypt.encryptFilter(acipher) outfile.open(filename) else: outfile = open(filename,"w") # all other code doesn't change... outfile.write(buncha_data) This could be even more simpler, but that's the general idea. The usefulness would be tremendous. From me at yahoo.com Sun Jan 2 18:02:26 2005 From: me at yahoo.com (it's me) Date: Sun, 2 Jan 2005 15:02:26 -0800 Subject: arbitrary number of arguments in a function declaration References: Message-ID: And in case it's not obvious already, you get the number of arguments that got passed down from: len(args) "Nick Coghlan" wrote in message news:mailman.65.1104694009.22381.python-list at python.org... > rbt wrote: > > How do I set up a function so that it can take an arbitrary number of > > arguments? For example, I have a bunch of expenses which may grow or > > shrink depending on the client's circumstance and a function that sums > > them up... hard coding them is tedious. How might I make this dynamic so > > that it can handle any amount of expenses? > > > > def tot_expenses(self, e0, e1, e2, e3): > > pass > > The Python Tutorial is a wonderful thing. . . > > Anyway, you can either set up your function to take a proper list, and then > discover that the sum function already exists to add up the contents of a list: > > def tot_expenses(self, expenses): > self.total_expenses = sum(expenses) > > Or, have the function take a variable number of arguments, and do the same thing: > > def tot_expenses(self, *args): > self.total_expenses = sum(args) > > Cheers, > Nick. > > -- > Nick Coghlan | ncoghlan at email.com | Brisbane, Australia > --------------------------------------------------------------- > http://boredomandlaziness.skystorm.net From sesquile at gmail.com Mon Jan 31 16:17:39 2005 From: sesquile at gmail.com (mh) Date: 31 Jan 2005 13:17:39 -0800 Subject: [ANN] Spike Asset Manager release 0.13 In-Reply-To: References: <1107196878.026930.154270@c13g2000cwb.googlegroups.com> <16894.36152.345508.583247@montanaro.dyndns.org> Message-ID: <1107206259.910842.111840@f14g2000cwb.googlegroups.com> Fredrik- This is a known issue. The tool currently only looks in certain locations or hints rather then spidering the whole hard drive (which could take a bit of time). If you have installed in a non-standard location (or are using a platform or version of software that hasn't been tested against) the tool won't find the component. One way around this is manually enter more "hints" but this doesn't scale. I'm open to suggestions for handling this in a better way. matt ps-I assume you are running on windows. Where is python installed on your machine? From ncoghlan at iinet.net.au Sat Jan 8 01:38:04 2005 From: ncoghlan at iinet.net.au (Nick Coghlan) Date: Sat, 08 Jan 2005 16:38:04 +1000 Subject: switching an instance variable between a property and a normal value In-Reply-To: References: Message-ID: <41DF7FCC.8070503@iinet.net.au> Steven Bethard wrote: > I'd like to be able to have an instance variable that can sometimes be > accessed as a property, and sometimes as a regular value, e.g. something > like: If you want the behaviour to be switchable per-instance, you have to go the route of always running through the property machinery, since property() creates a descriptor on the class, not the instance. On the other hand, if you want to switch the behaviour of every instance, then making usevalue and usefunc class methods may give you some mileage. I'm rather curious about your use case, though. . . Here's a different way of using the property machinery, too: Py> class C(object): ... def __init__(self): ... self._use_val = None ... def useval(self, x): ... self._val = x ... self._use_val = True ... def usefunc(self, func, *args, **kwds): ... self._func, self._args, self._kwds = (func, args, kwds) ... def _get(self): ... use_val = self._use_val ... if use_val is None: ... raise AttributeError('x') ... if use_val: ... return self._val ... else: ... return self._func(*self._args, **self._kwds) ... x = property(_get) ... Py> c = C() Py> c.useval(4) Py> c.x 4 Py> c.usefunc(list) Py> c.x [] -- Nick Coghlan | ncoghlan at email.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.skystorm.net From janeaustine50 at hotmail.com Sat Jan 8 23:13:49 2005 From: janeaustine50 at hotmail.com (Jane Austine) Date: 8 Jan 2005 20:13:49 -0800 Subject: time module precision Message-ID: What is the precision (and accuracy) of time module on a Windows XP machine? threading module depends on time module so it's precision(and accuracy) is up to time module's. | for i in xrange(1000): | time.sleep(0.001) This sleeps for awhile, which means 0.001 sec is not ignored. On the other hand, | for i in xrange(10000): | time.sleep(0.0001) This returns right away. 0.0001 sec is ignored and lost in the air. So can I tell the time.sleep's precision is 1ms? Any other way to increase the precision? (Using busy waiting -- spinning loop -- is not a good option, it makes over 90% cpu usage) Jane From ptmcg at austin.rr._bogus_.com Tue Jan 11 18:28:54 2005 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Tue, 11 Jan 2005 23:28:54 GMT Subject: Time script help sought! References: <1105464345.433117.109300@z14g2000cwz.googlegroups.com> <1105470872.613166.187800@f14g2000cwb.googlegroups.com> <1105471266.880133.318470@c13g2000cwb.googlegroups.com> <1105474524.083536.129220@f14g2000cwb.googlegroups.com> <1105477084.525279.312970@f14g2000cwb.googlegroups.com> <1105479292.689762.155510@f14g2000cwb.googlegroups.com> <1105480151.431987.327080@c13g2000cwb.googlegroups.com> <1105485509.346577.292130@f14g2000cwb.googlegroups.com> Message-ID: wrote in message news:1105485509.346577.292130 at f14g2000cwb.googlegroups.com... > man, now that is beautifully done. Paul, I wish I knew about pyparsing > a while ago. I could have used it in a few projects. :) > Thanks for the compliment! I'll be the first to admit that pyparsing can be a bit persnickety in some applications, especially when you have to trap on end-of-line, or have some columnar-dependent syntax. pyparsing really works best with data that has some syntactic structure to it, but is not whitespace sensitive (pyparsing's default behavior is to skip over whitespace). I don't recommend it when the data is well-formed - regexp's or even just string.split() will blow it away from a performance (and simplicity) standpoint. For instance, if the OP knew that all his data was itemId, tapeId, recordNum, startTime, endTime, comment, he could have most easily parsed it with item, tape, recordNum, startTime, endTime, comment = dataline.split(None,5) It's just those optional and variable-formatted fields that getcha. :) -- Paul pyparsing can be downloaded at http://pyparsing.sourceforge.net. From jerf at jerf.org Mon Jan 31 00:00:22 2005 From: jerf at jerf.org (Jeremy Bowers) Date: Mon, 31 Jan 2005 00:00:22 -0500 Subject: python and gpl References: Message-ID: On Sun, 30 Jan 2005 22:25:10 -0600, John Hunter wrote: > The question is: does shipping a backend which imports a module that > links with GPL code make some or all of the library GPL. This > question is complicated, in my mind at least, by several factors. I believe the best and most honest answer right now is, "Nobody knows." In fact, a careful reading of at least the LGPL (which I recently carefully read before putting a project under it, so I can speak to it where I can't speak to the GPL with quite as much confidence) shows that it is almost hopelessly based on the C way of doing things, with "linking" and "executables", that not only doesn't apply to Python, but doesn't apply to a lot of other modern languages as well. (I am fairly confident that the GPL has identical shortcomings, I just haven't read it as recently.) Specifically, I put a Javascript project under the LGPL and felt compelled to augment it with an appendix of just under 3K, just to make the LGPL make sense. I had to redefine "library", clarify the "work based on the library" and "work using the library" distinction in a context where there is no "linking" occurring, and correctly apply my Appendix to the clause that allows you to use future versions of the LGPL. And my problem is much simpler than yours. (I'm in control of the license, so I was able to simply clarify it, but there would still be the problem of what the raw LGPL would mean to someone had I not amended it, so from a certain point of view there is some similarity despite the difference in our positions; it is the user dilemma that prompted my solution.) Right now, when it comes down to it, I don't think we can even define "program" in a legal sense that is clear and useful; without that, trying to *deeply* understand the (L)GPL is probably a hopeless affair. From fredrik at pythonware.com Wed Jan 26 11:49:35 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 26 Jan 2005 17:49:35 +0100 Subject: Help With Python References: Message-ID: Peter Maas wrote: > > Can anybody help me get started? I am completely new to programming! > Online: > > - http://www.python.org/moin/BeginnersGuide (Beginner, Advanced) > - http://www.freenetpages.co.uk/hp/alan.gauld/ (Beginner) > - http://docs.python.org/tut/tut.html (Beginner) > - http://diveintopython.org/ (Advanced) also: http://www.byteofpython.info/ > Books (Look for most recent editions): > > - Mark Lutz, Learning Python (Beginner) > - Alex Martelli, Python in a Nutshell (Beginner, Advanced) > - Frederik Lundh, Python Standard Library (Beginner, Advanced) on-line here: http://effbot.org/librarybook on-line here: http://effbot.org/zone/librarybook.htm (pdf version) > - Alex Martelli, Python Cookbook (Beginner, Advanced) > - Mark Pilgrim Dive Into Python (Advanced) on-line here: http://diveintopython.org From michele.simionato at gmail.com Thu Jan 27 06:40:24 2005 From: michele.simionato at gmail.com (michele.simionato at gmail.com) Date: 27 Jan 2005 03:40:24 -0800 Subject: python without OO In-Reply-To: References: <1106689788.676121.48490@c13g2000cwb.googlegroups.com> <1106694083.199064.240680@f14g2000cwb.googlegroups.com> <1106814263.835719.181360@z14g2000cwz.googlegroups.com> Message-ID: <1106826024.655143.227050@c13g2000cwb.googlegroups.com> Peter Maas: >michele.simion... at gmail.com schrieb: >> Davor is right: even if >> you do not want to use it, the stuff is *there* and somebody in your >> team will. So definitely there is an audience of programmers that just >> do not have an use for all the sophistication and actually are >> penalized by it. >No, because Python does not enforce using advanced concepts. You >can write programs that are as simple as in 1991. A group of developers >always has to find some kind of common style with a chance that some >are penalized. This can happen with every language. No. In theory C++ could be kept as simple as C but in practice it is not. >> There is not much than can be done at the Python level. But I would >> see with interest a Python spinoff geared towards simplicity. >I think this would be useless because advanced concepts exist for >a reason. A simplified spin-off would aquire advanced concepts >over time and would just become a clone of Python. And then we will need another simplified spinoff ;) There is always a fight between simplificity and complexity. Some complexity is not needed, and I am sure even in Python something could be dropped. But it is difficult to find what can be removed. Remember that Saint-Exupery quote? Something like "a work of art is finished when there is nothing left to remove?" M.S. From jeff at ccvcorp.com Tue Jan 11 15:41:44 2005 From: jeff at ccvcorp.com (Jeff Shannon) Date: Tue, 11 Jan 2005 12:41:44 -0800 Subject: Securing a future for anonymous functions in Python In-Reply-To: References: <1105098890.358721.279550@f14g2000cwb.googlegroups.com> <1105289391.534192.74060@c13g2000cwb.googlegroups.com> <1105357625.835608.299560@c13g2000cwb.googlegroups.com> <10u5fu3o7v4h9e3@corp.supernews.com> Message-ID: <10u8e65lju3atbd@corp.supernews.com> Jacek Generowicz wrote: > Given a population with previous exposure to computer programming, my > money is on the map-lambda version. But this last point is mostly > irrelevant. The fact is that you cannot program computers without > doing a bit of learning ... and the lambda, map and friends really do > not take any significant learning. I guess we'll have to agree to disagree, because given the same conditions, I *still* think that a list comprehension expresses its semantics more clearly than map/lambda. I'd also point out that not all Python programmers will have significant prior exposure to programming ideas, and even those who do will not necessarily have prior exposure to lambdas. It's true that programming requires learning, and that map/lambda aren't a tremendous burden to learn. Still, to my mind they make a program a tiny increment more complicated. (I find that reading a lambda requires mentally pushing a stack frame to parse the lambda and another to translate map() into a loop, whereas a list comp's expression doesn't require such a shift, and a function name works as a good placeholder that makes reading easier.) It's not a big difference in any individual case, but incremental differences build up. From the sounds of it, you may have the opposite experience with reading map/lambda vs. reading list comps, though, so we could go back and forth on this all week without convincing the other. :) >>Speaking for *this* laboratory rat, at least, map/lambda was always a >>nasty puzzle for me and difficult to sort out. But when list comps >>were introduced, after reading just a sentence or two on how they >>worked, they were completely clear and understandable -- much more so >>than map/lambda after many months of exposure. > > Forgetting about lambda, map, filter and reduce, do you find that you > pass callables around in your Python programs, or is this not > typically done in your programs? Sure, I pass callables around quite a bit. Usually they're GUI callbacks or the like. Usually they're also either complex enough that lambda would be undesireable if not impossible, or they're simple and numerous (e.g. calling a function with different parameters) such that it's easy to write a factory function that returns closures rather than feed the parameter in with a lambda. Jeff Shannon Technician/Programmer Credit International From tim at pollenation.net Sat Jan 29 09:41:05 2005 From: tim at pollenation.net (Tim Parkin) Date: Sat, 29 Jan 2005 14:41:05 +0000 Subject: Textual markup languages (was Re: What YAML engine do you use?) In-Reply-To: References: <35a6tpF4gmat2U1@individual.net> <7x1xcfwbab.fsf@ruckus.brouhaha.com><35csm7F4l57inU1@individual.net> Message-ID: <1107009665.5655.19.camel@localhost.localdomain> On Sun, 2005-01-23 at 13:41 +0100, Fredrik Lundh wrote: > Alan Kennedy wrote: > > If I can't find such a markup language, then I might instead end up using a WYSIWYG editing > > component that gives the user a GUI and generates (x)html. > > > > htmlArea: http://www.htmlarea.com/ > > Editlet: http://www.editlet.com/ > > > > But I'd prefer a markup solution. > > some of these are amazingly usable. have you asked your users what they > prefer? (or maybe you are your user? ;-) Most users prefer to write documents in word and then paste them into textareas. Not surprisingly means no semantic content, little chance of restyling, horrible encoding problems and far too long spent on the phone trying to explain why it's not a good idea. Giving users a wysiwyg textarea creates the problems that users start to spend time trying to create a 'styled' document, inevitably sacrificing semantics (many is the user that has applied a header style to make things bold or a quote sytle to indent a paragraph). Using text based layouts reinforces the perception that you aren't creating a styled document and that the semantic structure is important. People who have used non-wysiwyg editors have found that their initial reticence has been quickly overtaken by their joy at not having to fight with 'style' and the reassurance that their content is now 'redesign proof'. Tim Parkin http://www.pollenation.net From tjreedy at udel.edu Mon Jan 24 20:36:56 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 24 Jan 2005 20:36:56 -0500 Subject: Another scripting language implemented into Python itself? References: Message-ID: "Roy Smith" wrote in message news:roy-97DBC5.19403124012005 at reader1.panix.com... > In article , > Quest Master wrote: > >> So, my question is simply this: is there an implementation of another >> scripting language into Python? > > Python *is* a scripting language. Why not just let your users write > Python modules which you them import and execute via some defined API? That was my thought also, with the note that you only need to document as much users will need, including specific modules (if any) to import. Terry J. Reedy From wittempj at hotmail.com Mon Jan 17 06:25:21 2005 From: wittempj at hotmail.com (wittempj at hotmail.com) Date: 17 Jan 2005 03:25:21 -0800 Subject: getting a class attribute using a keyword argument In-Reply-To: References: Message-ID: <1105961121.277992.105630@f14g2000cwb.googlegroups.com> Guy Robinson wrote: > Hello, > > I have a list of class instances. I wish to get the appropriate class attribute > in each class instance depending on a SINGLE keyword in the calling class. > > How do I get the calling method to correctly recognise the keyword as a keyword > and not a class attribute? See example code below (which doesn't work). > > class tocall: > def __init__(self): > self.title = "test" > self.name = "name" > > def callingmethod(self,**kw): > for key in kw: > if tocall.key == kw[key]: > return tocall.key > > which should work as such(but doesn't): > > print callmethod(title = "test") > print callmethod(name = "name") > > Regards, > > Guy You probably want something like this: class tocall: def __init__(self): self.title = "test" self.name = "name" x = tocall() print getattr(x, 'title') print getattr(x, 'name') print getattr(x, 'bogus') From john.abel at pa.press.net Wed Jan 26 08:18:36 2005 From: john.abel at pa.press.net (John Abel) Date: Wed, 26 Jan 2005 13:18:36 +0000 Subject: FTP Server In-Reply-To: <1106743852.600769.72820@c13g2000cwb.googlegroups.com> References: <1106743852.600769.72820@c13g2000cwb.googlegroups.com> Message-ID: <41F798AC.3010305@pa.press.net> If you're after a simple FTP server, have a look at medusa. Regards John michele.simionato at gmail.com wrote: >What's the simplest way to write an FTP Server in Python? >A short research on the newsgroup and on the Cookbook did not >bring out anything relevant (but I hear a little voice in the >back of my head saying Twisted, Twisted! ...) >Michele Simionato > > > From Sibylle.Koczian at Bibliothek.Uni-Augsburg.de Tue Jan 25 06:15:03 2005 From: Sibylle.Koczian at Bibliothek.Uni-Augsburg.de (Sibylle Koczian) Date: Tue, 25 Jan 2005 12:15:03 +0100 Subject: Right place for third party modules (here: fixedpoint) In-Reply-To: References: <35kj2iF4n6sokU1@news.dfncis.de> Message-ID: <35mo1gF4oqib4U1@news.dfncis.de> Fredrik Lundh schrieb: > > ah, forget what I said. you need to put the fixedpoint.py *file* under site-packages, > not the entire directory. as that "python -v -v" would have told you: > Thank you (and Steve Holden), that did it. > >>more out > > ... > # trying C:\python24\lib\site-packages\fixedpoint.pyd > # trying C:\python24\lib\site-packages\fixedpoint.dll > # trying C:\python24\lib\site-packages\fixedpoint.py > # trying C:\python24\lib\site-packages\fixedpoint.pyw > # trying C:\python24\lib\site-packages\fixedpoint.pyc > Traceback (most recent call last): > File "", line 1, in ? > ImportError: No module named fixedpoint > ... > > > Very helpful, not only directories, but full module names. I hope I'll remember (or find) "python -v -v" next time around. Python is nice, but Python + c.l.p. is a Really Good Thing. Koczian -- Dr. Sibylle Koczian Universitaetsbibliothek, Abt. Naturwiss. D-86135 Augsburg Tel.: (0821) 598-2400, Fax : (0821) 598-2410 e-mail : Sibylle.Koczian at Bibliothek.Uni-Augsburg.DE From stephen.thorne at gmail.com Sun Jan 9 05:45:16 2005 From: stephen.thorne at gmail.com (Stephen Thorne) Date: Sun, 9 Jan 2005 20:45:16 +1000 Subject: Pre/Postconditions with decorators In-Reply-To: <7x1xcvwkdj.fsf@ruckus.brouhaha.com> References: <1105094828.619317.315340@z14g2000cwz.googlegroups.com> <34814fF43bm4cU1@individual.net> <7x1xcvwkdj.fsf@ruckus.brouhaha.com> Message-ID: <3e8ca5c805010902455ef60947@mail.gmail.com> On 08 Jan 2005 15:50:48 -0800, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > Stephen Thorne writes: > > Unresolved Problems: > > 1) How do you handle duck types, i.e. a method that accepts StringIO, > > cStringIO or any other object that has a .readlines(), .seek() and > > .read() method? > > That should really be done through having those classes inherit a > file-operations mixin, or else through interfaces (which might get > added to Python). Working under the assumption we cannot change the existing standard library. > > 2) How do you turn off the type checking for production code? > > It should be left on. Leaving it in for development and turning it > off for production is like wearing a parachute during ground training > and taking it off once you're in the air. So we can't use this for a case where we have an extremely large list then ;). Its an O(n) operation to just call a function that takes a list of a specific type. Stephen. From python-url at phaseit.net Sun Jan 9 12:11:09 2005 From: python-url at phaseit.net (Josiah Carlson) Date: Sun, 09 Jan 2005 17:11:09 +0000 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Jan 9) Message-ID: QOTW: Jim Fulton: "[What's] duck typing?" Andrew Koenig: "That's the Australian pronunciation of 'duct taping'." "I'm thinking that the I-Ching is a vast untapped resource for programming wisdom, plus it makes it funny." -- Mark Carter Nick Coghlan brings up the 'lambdas are going away in 3.0' topic, which has been discussed before: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/81e17b1d3ccba538 A user asks about a non-generator-based method for iteration using class __iter__ and next() methods: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/6336a00ad217888a Daniel Bickett asks about getting Twisted and wxPython working together, and receives both a threaded and non-threaded version: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/73f1e7758225afc3 A question about iterating over floats...be careful! http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/1278866159ac4429 A Boogieman asks whether Python is easily learned and what can be done with it. Quick answer: yes, and anything you are capable of doing: This Boogieman later asks about GUI toolkits: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/e67b776df72eb336 http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/d502698b4adacd01 Erik Bethke writes Majong game after using Python for a month. Ahh, will the wonders of Python never cease? http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/6d710e35007f0f32 Kamilche asks about getting warnings when not calling a function, and gets pointed to pychecker, something more of us should be using: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/dff810b7dacd247c Are people allowed to build commercial applications in Python? YES! http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/aa953388db68b196 Questions about asyncore brings up a web server in asyncore from _Python Web Programming_, and a pointer to Twisted. Alternatively, one could look at the asynchat or smtpd modules in the standard library as sources of inspiration: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/81360ec06013e36d ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Mygale is a news-gathering webcrawler that specializes in (new) World-Wide Web articles related to Python. http://www.awaretek.com/nowak/mygale.html While cosmetically similar, Mygale and the Daily Python-URL are utterly different in their technologies and generally in their results. comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Brett Cannon continues the marvelous tradition established by Andrew Kuchling and Michael Hudson of intelligently summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Business Forum "further[s] the interests of companies that base their business on ... Python." http://www.python-in-business.org Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donate.html Kurt B. Kaiser publishes a weekly report on faults and patches. http://www.google.com/groups?as_usubject=weekly%20python%20patch Cetus collects Python hyperlinks. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://aspn.activestate.com/ASPN/Cookbook/Python Among several Python-oriented RSS/RDF feeds available are http://www.python.org/channews.rdf http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi http://python.de/backend.php For more, see http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. deli.cio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python *Py: the Journal of the Python Language* http://www.pyzine.com Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. From pythongnome at hotmail.com Thu Jan 6 17:10:33 2005 From: pythongnome at hotmail.com (Lucas Raab) Date: Thu, 06 Jan 2005 22:10:33 GMT Subject: Python Operating System??? In-Reply-To: <10trb0mgiflcj4f@corp.supernews.com> References: <10trb0mgiflcj4f@corp.supernews.com> Message-ID: David Brown wrote: > Hello. I recently came across a free operating system called Unununium (or > something like that) and it was developed in Python and Assembly. > > Now, I have been looking for a way to make an operating system for a long > long time and the only possibilities I could find were C++ and assembly. I > don't mind assembly so much if I don't have to use it very often. But C++ is > so complicated and errors are pretty much impossible to find in the code for > me. > > So, I was wondering if it would be possible to find a bootloader that loads > a python file at startup or something... > > Is there an example somewhere of a Python OS? > > Thanks! > > Hasn't there been numerous discussions about this in the past?? From lbates at syscononline.com Wed Jan 19 11:01:43 2005 From: lbates at syscononline.com (Larry Bates) Date: Wed, 19 Jan 2005 10:01:43 -0600 Subject: Accessing MDB files on Windows In-Reply-To: <1635068.ZTfiooUzB4@strongwill.g2ctech> References: <1635068.ZTfiooUzB4@strongwill.g2ctech> Message-ID: I'm assuming the application will be run on Windows. You can use ODBC or DAO. An DAO solution that I wrote (and use) can be found at: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303349 For ODBC you would just use the standard library module. Larry Bates Syscon, Inc. Jorge Luiz Godoy Filho wrote: > Hi, > > > What is the best way to deal with MDB files? I was thinking on using > ODBC... I'll need to read and write some information to it. The load > won't be so high, but there might be a lot of data. > > Any advices? Will my approach work? I'm not a Windows guy... :-) > From b_b at net.hr Sat Jan 15 11:29:57 2005 From: b_b at net.hr (Brane) Date: Sat, 15 Jan 2005 17:29:57 +0100 Subject: python to mssql References: Message-ID: <19womotgpx7sg.qru1ognhkyt7.dlg@40tude.net> On Fri, 14 Jan 2005 15:22:44 -0500, Richards Noah (IFR LIT MET) wrote: > "Robert Brewer" wrote in message > news:mailman.722.1105724341.22381.python-list at python.org... > Brane wrote: >> can someone please give me some info regarding subject >> >>http://sourceforge.net/projects/mysql-python >> >>Ask a broad question... >> >> >>Robert Brewer > > Robert, the question was about 'mssql', not 'mysql'. As for mssql, a search > on google will give you the following as the first result: > http://pymssql.sourceforge.net/ > > with others on the page that include: > http://www.object-craft.com.au/projects/mssql/ > http://www.egenix.com/files/python/eGenix-mx-Extensions.html > > > Don't be lazy, Brane. Your first point of reference should _always_ be > google. The fact that "I'm Feeling Lucky" points you to pymssql shows that > you didn't do any research before posting here. > > -Noah well i wonted to hear frome someone who already used it because there is lots of topics about subject anyway thnks for info brane From enleverlesO.OmcO at OmclaveauO.com Mon Jan 24 17:52:19 2005 From: enleverlesO.OmcO at OmclaveauO.com (Do Re Mi chel La Si Do) Date: Mon, 24 Jan 2005 23:52:19 +0100 Subject: add indexes on the fly to lists References: Message-ID: <41f69f0b$0$6606$8fcfb975@news.wanadoo.fr> Hi ! If you want only "search and found" element, look dictionnary ; if you want also to have the order, see the module set. Good night -- Michel Claveau From smitsky at mindspring.com Sat Jan 8 19:37:50 2005 From: smitsky at mindspring.com (Smitsky) Date: Sun, 09 Jan 2005 00:37:50 GMT Subject: Windows XP Installation Message-ID: Hi. I am a newbie to Python. I am running Win XP and want to know what the best course is for installing Python on my system. Could someone kindly direct me to some related resources? Thanks in advance, Steve From sjmachin at lexicon.net Tue Jan 18 02:41:31 2005 From: sjmachin at lexicon.net (John Machin) Date: 17 Jan 2005 23:41:31 -0800 Subject: Fuzzy matching of postal addresses References: <96B2w2E$HF7BFwSq@at-andros.demon.co.uk> Message-ID: <1106034091.153664.309670@z14g2000cwz.googlegroups.com> You can't even get anywhere near 100% accuracy when comparing "authoritative sources" e.g. postal authority and the body charged with maintaining a database of which streets are in which electoral district -- no, not AUS, but close :-) From mmokrejs at ribosome.natur.cuni.cz Mon Jan 10 12:27:15 2005 From: mmokrejs at ribosome.natur.cuni.cz (=?UTF-8?B?TWFydGluIE1PS1JFSsWg?=) Date: Mon, 10 Jan 2005 18:27:15 +0100 Subject: Writing huge Sets() to disk In-Reply-To: References: Message-ID: <41E2BAF3.9070106@ribosome.natur.cuni.cz> Paul McGuire wrote: > "Martin MOKREJ?" wrote in message > news:mailman.448.1105373471.22381.python-list at python.org... > >>Hi, >> I have sets.Set() objects having up to 20E20 items, >>each is composed of up to 20 characters. Keeping >>them in memory on !GB machine put's me quickly into swap. >>I don't want to use dictionary approach, as I don't see a sense >>to store None as a value. The items in a set are unique. >> >> How can I write them efficiently to disk? To be more exact, >>I have 20 sets. _set1 has 1E20 keys of size 1 character. >> >>alphabet = ('G', 'A', 'V', 'L', 'I', 'P', 'S', 'T', 'C', 'M', 'A', 'Q', > > 'F', 'Y', 'W', 'K', 'R', 'H', 'D', 'E') > >>for aa1 in alphabet: >> # l = [aa1] >> #_set1.add(aa1) >> for aa2 in alphabet: >> # l.append(aa2) >> #_set2.add(''.join(l)) >>[cut] >> >> The reason I went for sets instead of lists is the speed, >>availability of unique, common and other methods. >>What would you propose as an elegant solution? >>Actually, even those nested for loops take ages. :( >>M. > > > _set1 only has 19 keys of size 1 character - 'A' is duplicated. Ahh, you are right. That's a typo, yet I have to figure out which char I have to use. But 'Z' will do for the tests anyway. > > Assuming you replace 'A' with another character (say 'Z'), then here is what > you get: > _set1 - 20 elements (20**1) > _set2 - 400 elements (20**2) > _set3 - 8000 elements (20**3) > ... > _set20 - 20**20 ~ 10 ^ (1.301*20) or 1E26 > > If you have no duplicates in your alphabet, then you wont need to use sets, > every combination will be unique. In this case, just use a generator. As I noted in later response, actually I will compare these ideal sets to some real world examples. I have no expectation how many entries will be common and how many unique. The only thing I know even in real world, I might be in size ranges of 2E6 or perhaps 2E8? > Here's a recursive generator approach that may save you a bunch of nested > editing (set maxDepth as high as you dare): > > alphabet = ('G', 'A', 'V', 'L', 'I', 'P', 'S', 'T', 'C', 'M', 'Z', 'Q', 'F', > 'Y', 'W', 'K', 'R', 'H', 'D', 'E') > > maxDepth = 3 > > def genNextCombo(root=list(),depth=1): > for a in alphabet: > thisRoot = root + [a] > yield "".join( thisRoot ) > if depth < maxDepth: > for c in genNextCombo(thisRoot, depth+1): > yield c > > for c in genNextCombo(): > print c # or write to file, or whatever Works nice, but http://www.python.org/doc/2.3.4/ref/yield.html doesn't really tell what happens here. :( But is quite fast and definitely saves those the stupid recursively hand-written for loops. Thanks Paul! M. From pierre.barbier at cirad.fr Wed Jan 19 03:07:59 2005 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Wed, 19 Jan 2005 09:07:59 +0100 Subject: extension module, thread safety? In-Reply-To: References: <41ecbaae$0$1046$626a14ce@news.free.fr> <41eccfe4$0$16621$636a15ce@news.free.fr> Message-ID: <41ee14f7$0$26194$626a14ce@news.free.fr> David Bolen a ?crit : > Nick Coghlan writes: > > And even before that it was certainly possible to call into the Python > interpreter from a native thread using existing functions, albeit the > newer functions are more convenient (and perhaps more robust, I don't > know). > > My earliest interaction with Python (~1999, while writing a module > that extended and embedded Python 1.5.2) used PyEval_AcquireThread() > and PyEval_ReleaseThread() to get access to a thread state from a > native C application thread (not initiated by the Python interpreter) > to allow me to call safely into an executing Python script upon > asynchronous data reception by the C code. > > -- David Yes, now you mention this I remember trying to use these functions ! But there is two problems with them (and only one is solved by the new functions) ! The first problem is the dead lock is you try to acquire the same thread twice. This implies a very low level use of these function, and it can be a real pain to find where to put them without risking this dead lock. This is no more a problem with the new functions. But the second (and not solved) problem is: these functions block the current thread when you try to get the GIL ! This is an issue if you don't want your GUI thread to be blocked when a buggy module does not release the GIL during long computations. I didn't find any function like "test the state of the GIL and if it's free, then acquire it" ! And, IMO, it's missing ... Then, if python goes to a model where critical sections are identified and the GIL acquired only there, all these problems will disappear ! That's why I really hope Python 3 will include this kind of thread support ... Pierre From dw at botanicus.net Sun Jan 9 18:23:58 2005 From: dw at botanicus.net (David Wilson) Date: Sun, 09 Jan 2005 23:23:58 +0000 Subject: vi and python In-Reply-To: <20050110032348.GA1960@mrna.tn.nic.in> References: <20050110032348.GA1960@mrna.tn.nic.in> Message-ID: <41E1BD0E.1010805@botanicus.net> km wrote: >Is there a way to display inbuilt function syntax as the user starts typing a function name with 'Vi' editor in console mode? > > Hi there, Unfortunately due to the highly dynamic nature of Python, this is difficult to do reliably. It is one benefit that static typing, to a certain extent, would bring to the language. Sadly we don't have that, yet. :) David. From bokr at oz.net Wed Jan 5 15:07:43 2005 From: bokr at oz.net (Bengt Richter) Date: Wed, 05 Jan 2005 20:07:43 GMT Subject: Deferred expressions (was Re: Lambda as declarative idiom) References: <3A81C87DC164034AA4E2DDFE11D258E3024F6B@exchange.hqamor.amorhq.net> Message-ID: <41dc4099.75876003@news.oz.net> On Tue, 04 Jan 2005 19:31:37 +1000, Nick Coghlan wrote: >Steven Bethard wrote: >> Nick Coghlan: def-from syntax [4] >> (def f(a) + o(b) - o(c) from (a, b, c)) >> (def x * x from (x)) >> (def x from ()) >> (def x.bar(*a, **k) from (*a, **k)) >> ((def x(*a, **k) from ()) for x, a, k in funcs_and_args_list) > >After a bit more musing, this is definitely my preferred syntax. I'd call it a >'deferred expression' rather than an anonymous function, though. The name change >may seem minor, but it changes the emphasis of the feature from how it's >implemented to what it is useful for (i.e. deferring evaluation of an expression >until call time). I like the fact that 'def' can serve as a mnemonic for 'defer' or 'deferred' ;-) OTOH, I like concise notation for expressions, and the def and from aren't really necessary if you can tag the first expression with some syntax marker. I suggested (: rather than (def since (: is illegal now and won't break anything. But all this is just a rewrite of lambda params:expr as (def expr from params). What is the point again? (Not that my rewrite to (:expr)(params) is any more than a lambda rewrite either). If backticks could be used, `(expr:params) might be an interesting spelling of lambda params:expr. I do like being able to leave out the from clause. `(expr) would let you do that too, just as well as (:expr). > >It's also conducive to a clean no-argument syntax - simply make the 'from' claus >optional when the argument list is empty. That is an advantage of having it inside the outer parens, which my (:expr)(params) couldn't benefit from -- unless I just take your format and substitute ':' for both def and from: (: f(a) + o(b) - o(c) : (a, b, c)) (: x * x : (x)) (: x) # empty arg list (: x.bar(*a, **k) : (*a, **k)) ((: x(*a, **k) : (x=x, a=a, k=k) for x, a, k in funcs_and_args_list) > >'def' and 'from' are already keywords, so there shouldn't be any compatibility >problems. > >Michael Spencer's idea of using 'for' instead of 'from' was quite interesting, >but the use of 'for' without a corresponding 'in' feels a bit misleading :) What was the point of all this again? Pretending lambda goes away without really killing it? ;-) Regards, Bengt Richter From kent3737 at yahoo.com Wed Jan 26 11:21:40 2005 From: kent3737 at yahoo.com (Kent Johnson) Date: Wed, 26 Jan 2005 11:21:40 -0500 Subject: re.search - just skip it In-Reply-To: <1106754436.876675.144290@c13g2000cwb.googlegroups.com> References: <1106754436.876675.144290@c13g2000cwb.googlegroups.com> Message-ID: <41f7c10b$1_1@newspeer2.tds.net> rasdj at frontiernet.net wrote: > Input is this: > > SET1_S_W CHAR(1) NOT NULL, > SET2_S_W CHAR(1) NOT NULL, > SET3_S_W CHAR(1) NOT NULL, > SET4_S_W CHAR(1) NOT NULL, > ; > > .py says: > > import re, string, sys > s_ora = re.compile('.*S_W.*') > lines = open("y.sql").readlines() > for i in range(len(lines)): > try: > if s_ora.search(lines[i]): del lines[i] When you delete for example lines[0], the indices of the following lines change. So the former lines[1] is now lines[0] and will not be checked. The simplest way to do this is with a list comprehension: lines = [ line for line in lines if not s_ora.search(line) ] Even better, there is no need to make the intermediate list of all lines, you can say lines = [ line for line in open("y.sql") if not s_ora.search(line) ] In Python 2.4 you don't have to make a list at all, you can just say open("z.sql","w").writelines(line for line in open("y.sql") if not s_ora.search(line)) ;) Kent > except IndexError: > open("z.sql","w").writelines(lines) > > but output is: > > SET2_S_W CHAR(1) NOT NULL, > SET4_S_W CHAR(1) NOT NULL, > ; > > It should delete every, not every other! > > thx, > > RasDJ > From http Sat Jan 29 07:11:41 2005 From: http (Paul Rubin) Date: 29 Jan 2005 04:11:41 -0800 Subject: What's so funny? WAS Re: rotor replacement References: <7xzmz0lw6h.fsf@ruckus.brouhaha.com> <41f4324a$0$1547$9b622d9e@news.freenet.de> <41f589f9$0$3357$9b622d9e@news.freenet.de> <41f6a8ef$0$27790$9b622d9e@news.freenet.de> <41f7efc2$0$11596$9b622d9e@news.freenet.de> <41f97630$0$11586$9b622d9e@news.freenet.de> <7xu0p2dvsa.fsf@ruckus.brouhaha.com> <41f9f5e6$0$25927$9b622d9e@news.freenet.de> <7x4qh13o0o.fsf@ruckus.brouhaha.com> <41FACD1C.6000301@v.loewis.de> <7xacqt56ga.fsf@ruckus.brouhaha.com> <41fb646a$0$31784$9b622d9e@news.freenet.de> Message-ID: <7xacqsbfk2.fsf@ruckus.brouhaha.com> "Martin v. L?wis" writes: > Indeed, if it was a single new function to an existing module, I would > not require that this be delivered to users first. It is entire new > libraries that I worry about. Why is it different if a single new function is added to an existing module, or if the single new function has the boilerplate of a new module wrapped around it? Look at the sha and md5 modules. They are very similar in both interface and implementation. The only internal function that's really different is the update operation; they actually might have been combined into one module that did the other operations with the same code. But, it's also reasonable to have them as separate modules. If users start needing sha256, it could be done the same way, one new update operation and the rest boilerplate, but in practice it would probably be a separate module. Are you saying if there was user demand for an sha256 module and someone wrote one, you'd still require a year of separate distribution? > A module *is* typically more complex than a single function. If > your new module has only a single new function, we should discuss > whether it really needs to be a separate module. I previously had the mistaken belief that urandom was a new module rather than a function inserted into an existing module. Note that the urandom's implementation is not ultra-trivial. An AES or DES addition to an existing module that implements just one call: ECB(key, data, direction) would be a huge improvement over what we have now. A more complete crypto module would have some additional operations, but ECB is the only one that's really essential. I already have a pure-Python module that does all the other operations using ECB as a subroutine. It's speed isn't great but it's useable in some real applications. It's only the ECB operation that's intolerably slow in Python. If you think a function like that could be added to some existing module with less hassle than adding a new module, then I can write one and submit it. > > Well, if he indicates that it's not a policy and that the question is > > still open, then I could see getting interested again in writing an > > AES module. At the moment I continue to see his python-dev post as > > quite discouraging. > > And, again, I consider this perfectly fine. This would be a volunteer > effort, and volunteers are free to work on whatever they please. Well, volunteers are more likely to work on modules that are mentioned as being welcome by the developers, than modules affected by explicit prior developers' public decisions that cast a chill over the hope of ever getting such a module accepted. > Furthermore, people who want an AES module for Python could get one from Come on, you're being deliberately obtuse, we've discussed this over and over. There are plenty of AES modules that people can get from somewhere. The topic is what it takes to have an AES module that people don't NEED to get from anywhere, because they already have it from having Python installed. Do I have to keep repeating "batteries included" until you understand what it means? > http://sourceforge.net/projects/cryptkit/ > > Maybe Bryan Mongeau will contribute this code to Python some day. Well, that code has been around for over a year, people are using it, etc. Are you saying you'll support its inclusion if Bryan offers to contribute it? I've examined that module, I wouldn't consider it ideal for the core (besides AES, it has some complicated additional functions that aren't useful to most people), but it would certainly take care of my AES needs (it's apparently missing DES though). > I did not say that. I said we don't normally invite people to work > on anything - I said not that we *should* not invite them. I would say that inviting people to work on a module for the stdlib means the developers have thought about whether such a module would be useful and worth including, and are indicating that they're favorable to the idea. However, you wrote: In Message-ID: <41f4324a$0$1547$9b622d9e at news.freenet.de> So if the module was primarily written to be included in the core, I would initially reject it for that very reason. After one year or so in its life, and a recognizable user base, inclusion can be considered. The context was new modules in general, not specifically an AES module. Since "considered" means "thought about", so you said inclusion shouldn't even be thought about until the module is already done. That's completely in conflict with the idea of inviting anyone to work on a new module, since inviting means that there's been some thought. > Now that you mention it, I find that there is an important exception > from my factual statement: I do regularly ask people reporting bugs > or requesting features to work fixing the bugs or implementing the > features. It is perfectly fine if they say "no" then. If they say > yes, there is an implied promise that I'll review their code when > they are done. I would say there's an implied promise of something more than a code review. There's an implied statement that you agree that the proposed new functionality is useful, which means the patch has a good chance of being accepted to the stdlib if it's not too messy or cumbersome. That's a heck of a lot different from saying "why don't you write that patch and distribute it independently for a year on a purely speculative basis, and then I'll think about whether it's worthwhile to include it or not". > As it appears to be clear that you are not going to implement an AES > module in the foreseeable future, The reason for that is as far as I can tell, even if I follow 100% of your prescription of writing the module, releasing it independently and supporting it for a year, and then offering to contribute it complete with favorable user reviews and a promise of two years of further support, the probability of it being accepted and included is still close to zero. In more recent messages you've suggested that my reading of that probability is wrong and that it's actually higher than zero. So let me just ask you one final question: suppose I do all that stuff. The question: in your personal opinion, based on the best information you have, what is the your own subjective estimate of the probability? I won't say I'd immediately replace my estimate with yours, but if you name a reasonably high number and tell me that you really believe that number, then I could get interested again. > and as it also seems to be clear that you cannot talk me into > changing my views on how Python should be developed, I think further > discussing this entire thing is pointless. Well, you can have whatever views you want, but one I've thing I've realized from this thread is that many of the frustrations I often encounter with Python are a direct result of a development process that's successful in some ways but dysfunctional in others. From itsme at yahoo.com Thu Jan 6 20:58:51 2005 From: itsme at yahoo.com (It's me) Date: Fri, 07 Jan 2005 01:58:51 GMT Subject: Another PythonWin Excel question References: <41ddb59e$0$8338$afc38c87@news.optusnet.com.au> Message-ID: Yes, Mike, Others pointed that out as well. The difficulty is that they are all in VBAs. Most of them can be translated to Python fairly easily, and some I can get from looking at the recorded macro - but some requires quite a bit of head scratching. For instance, I wanted to figure out how create a new window. So, I went through the record macro process and looked at the VBA code, it says: ActiveWindow.NewWindow Okay. Now what??? And for switching window, it says: Windows("Book1:1").Activate Okay. ??? So, I look through the online information on msdn and viola! No mentioning of that anwhere.... Would be nice if there's a Python specific of it....but just dreaming... Back to reading MSDN..... Thanks, "Mike Thompson" wrote in message news:41ddb59e$0$8338$afc38c87 at news.optusnet.com.au... > It's me wrote: > > I followed the example in > > http://stompstompstomp.com/weblog/technical/2004-05-20 and learned that to > > add a new worksheet to an Excel workbook, you would use the > > workbook.Worksheets.Add() method. That works. However, the new worksheet > > got added *in front* of the last worksheet I was at. How can I get it to > > add *after*? > > > > Thanks, > > > > -- > > Me > > > > > > Does this help? > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/html/wrtskhowtomoveworksheetswithinworkbooks.asp > > -- > Mike From kbk at shore.net Sun Jan 23 15:15:45 2005 From: kbk at shore.net (Kurt B. Kaiser) Date: Sun, 23 Jan 2005 15:15:45 -0500 (EST) Subject: Weekly Python Patch/Bug Summary Message-ID: <200501232015.j0NKFjhi001559@bayview.thirdcreek.com> Patch / Bug Summary ___________________ Patches : 273 open ( +1) / 2746 closed ( +9) / 3019 total (+10) Bugs : 797 open ( +4) / 4789 closed (+12) / 5586 total (+16) RFE : 166 open ( +1) / 141 closed ( +0) / 307 total ( +1) New / Reopened Patches ______________________ fix distutils.install.dump_dirs() with negated options (2005-01-17) CLOSED http://python.org/sf/1103844 opened by Wummel Add O_SHLOCK/O_EXLOCK to posix (2005-01-17) http://python.org/sf/1103951 opened by Skip Montanaro setup.py --help and --help-commands altered. (2005-01-17) http://python.org/sf/1104111 opened by Titus Brown new-style exceptions (2005-01-18) http://python.org/sf/1104669 opened by Michael Hudson misc doc typos (2005-01-18) CLOSED http://python.org/sf/1104868 opened by DSM chr, ord, unichr documentation updates (2004-10-31) http://python.org/sf/1057588 reopened by mike_j_brown Faster commonprefix in macpath, ntpath, etc. (2005-01-19) http://python.org/sf/1105730 opened by Jimmy Retzlaff get rid of unbound methods (mostly) (2005-01-17) CLOSED http://python.org/sf/1103689 opened by Guido van Rossum Updated "Working on Cygwin" section (2005-01-22) http://python.org/sf/1107221 opened by Alan Green Add Thread.isActive() (2005-01-23) http://python.org/sf/1107656 opened by Alan Green Speed up function calls/can add more introspection info (2005-01-23) http://python.org/sf/1107887 opened by Neal Norwitz Patches Closed ______________ fix distutils.install.dump_dirs() with negated options (2005-01-17) http://python.org/sf/1103844 closed by theller ast-branch: fix for coredump from new import grammar (2005-01-11) http://python.org/sf/1100563 closed by kbk Shadow Password Support Module (2002-07-10) http://python.org/sf/579435 closed by loewis misc doc typos (2005-01-18) http://python.org/sf/1104868 closed by fdrake extending readline functionality (2003-02-11) http://python.org/sf/684500 closed by fdrake self.button.pack() in tkinter.tex example (2005-01-03) http://python.org/sf/1094815 closed by fdrake Clean up discussion of new C thread idiom (2004-09-20) http://python.org/sf/1031233 closed by fdrake Description of args to IMAP4.store() in imaplib (2004-12-12) http://python.org/sf/1084092 closed by fdrake get rid of unbound methods (mostly) (2005-01-17) http://python.org/sf/1103689 closed by gvanrossum New / Reopened Bugs ___________________ email.base64MIME.header_encode vs RFC 1522 (2005-01-17) http://python.org/sf/1103926 opened by Ucho wishlist: os.feed_urandom(input) (2005-01-17) http://python.org/sf/1104021 opened by Zooko O'Whielacronx configure doesn't set up CFLAGS properly (2005-01-17) http://python.org/sf/1104249 opened by Bryan O'Sullivan Bugs in _csv module - lineterminator (2004-11-24) http://python.org/sf/1072404 reopened by fresh Wrong expression with \w+? (2005-01-18) CLOSED http://python.org/sf/1104608 opened by rengel Bug in String rstrip method (2005-01-18) CLOSED http://python.org/sf/1104923 opened by Rick Coupland Undocumented implicit strip() in split(None) string method (2005-01-19) http://python.org/sf/1105286 opened by YoHell Warnings in Python.h with gcc 4.0.0 (2005-01-19) http://python.org/sf/1105699 opened by Bob Ippolito incorrect constant names in curses window objects page (2005-01-19) http://python.org/sf/1105706 opened by dcrosta null source chars handled oddly (2005-01-19) http://python.org/sf/1105770 opened by Reginald B. Charney bug with idle's stdout when executing load_source (2005-01-20) http://python.org/sf/1105950 opened by imperialfists os.stat int/float oddity (2005-01-20) CLOSED http://python.org/sf/1105998 opened by George Yoshida README of 2.4 source download says 2.4a3 (2005-01-20) http://python.org/sf/1106057 opened by Roger Erens semaphore errors from Python 2.3.x on AIX 5.2 (2005-01-20) http://python.org/sf/1106262 opened by The Written Word slightly easier way to debug from the exception handler (2005-01-20) http://python.org/sf/1106316 opened by Leonardo Rochael Almeida os.makedirs() ignores mode parameter (2005-01-21) http://python.org/sf/1106572 opened by Andreas Jung split() takes no keyword arguments (2005-01-21) http://python.org/sf/1106694 opened by Vinz os.pathsep is wrong on Mac OS X (2005-01-22) CLOSED http://python.org/sf/1107258 opened by Mac-arena the Bored Zo Bugs Closed ___________ --without-cxx flag of configure isn't documented. (2003-03-12) http://python.org/sf/702147 closed by bcannon presentation typo in lib: 6.21.4.2 How callbacks are called (2004-12-22) http://python.org/sf/1090139 closed by gward rfc822 Deprecated since release 2.3? (2005-01-15) http://python.org/sf/1102469 closed by anthonybaxter codecs.open and iterators (2003-03-20) http://python.org/sf/706595 closed by doerwalter Wrong expression with \w+? (2005-01-18) http://python.org/sf/1104608 closed by niemeyer Wrong expression with \w+? (2005-01-18) http://python.org/sf/1104608 closed by effbot Bug in String rstrip method (2005-01-18) http://python.org/sf/1104923 closed by tim_one No documentation for zipimport module (2003-12-03) http://python.org/sf/853800 closed by fdrake distutils/tests not installed (2004-12-30) http://python.org/sf/1093173 closed by fdrake urllib2 doesn't handle urls without a scheme (2005-01-07) http://python.org/sf/1097834 closed by fdrake vertical bar typeset horizontal in docs (2004-08-13) http://python.org/sf/1008998 closed by fdrake write failure ignored in Py_Finalize() (2004-11-27) http://python.org/sf/1074011 closed by loewis os.stat int/float oddity (2005-01-20) http://python.org/sf/1105998 closed by loewis os.pathsep is wrong on Mac OS X (2005-01-22) http://python.org/sf/1107258 closed by bcannon From wyojustin at hotmail.com Sun Jan 30 21:41:53 2005 From: wyojustin at hotmail.com (Justin Shaw) Date: Sun, 30 Jan 2005 21:41:53 -0500 Subject: tkSnack pitch() for frequency estimation Message-ID: <4MOdnfuccsdhB2DcRVn-jg@comcast.com> I am using the tkSnack library to estimate the frequency from a sound file. The pitch seems to drop down an octave at 400 Hertz. For example A~440 Hertz comes out at 220 Hertz. When I use the maxpitch and minpitch options to limit the response to say 380 - 460 the result is all zeros. Any ideas on how I can estimate the pitch of a sound up to 880 Hertz (with tkSnack or not)? Thanks Justin Shaw From sp1d3rx at gmail.com Tue Jan 25 15:50:10 2005 From: sp1d3rx at gmail.com (sp1d3rx at gmail.com) Date: 25 Jan 2005 12:50:10 -0800 Subject: Question Regarding SocketServer In-Reply-To: <1106684900.771730.218060@f14g2000cwb.googlegroups.com> References: <1106684900.771730.218060@f14g2000cwb.googlegroups.com> Message-ID: <1106686210.372444.314020@f14g2000cwb.googlegroups.com> you are missing quotes in "socketserver.py". Make sure the comments at the top are quoted out. In "IDLE" they should be green. From daniel at bowettsolutions.com Wed Jan 26 13:42:14 2005 From: daniel at bowettsolutions.com (Daniel Bowett) Date: Wed, 26 Jan 2005 18:42:14 +0000 Subject: MySQLdb executemany Message-ID: I seem to have found a bug/limitation of executemany in MySQLdb. I am inserting 3100 records into a database. It works fine and adds them in about 1 second. I went back to the program today and realised i'd missed a field so added it to the insert statement. This seems to break it if I try to add all the records in one go. Through trial and error I have realised the limit is 2786 records in one go. Any more than that I get two different errors on the executemany statement: "MySQL server has gone away" - This occurs if I try to add all 3100 records in one go. "Lost Connection to MySQL server during query" - This happens if I am near the 2786 threshold. Is there a known limit with this function??? From fuzzyman at gmail.com Wed Jan 5 07:06:31 2005 From: fuzzyman at gmail.com (Fuzzyman) Date: 5 Jan 2005 04:06:31 -0800 Subject: Cookbook 2nd ed Credits In-Reply-To: <1gpvtjk.3jf7dc1cch7yfN%aleaxit@yahoo.com> References: <1104425916.615972.97530@z14g2000cwz.googlegroups.com> <7xmzvu1ycn.fsf@ruckus.brouhaha.com> <7xd5wqd14y.fsf@ruckus.brouhaha.com> <7xacrs230c.fsf@ruckus.brouhaha.com> <33q4plF410bo2U1@individual.net> <1gpsbep.13iiova6cvkayN%aleaxit@yahoo.com> <1104836129.741586.179510@c13g2000cwb.googlegroups.com> <1gpvif1.1r2osm66cmd3vN%aleaxit@yahoo.com> <1gpvtjk.3jf7dc1cch7yfN%aleaxit@yahoo.com> Message-ID: <1104926791.222640.183770@z14g2000cwz.googlegroups.com> Hmm... I'd love to see a list... just to know if I'm on it. Permission was sought for several of my recipes, but I don't know if any were actually used. I'm very curious... Regards, Fuzzy http://www.voidspace.org.uk/python/index.shtml From rbt at athop1.ath.vt.edu Wed Jan 26 17:32:47 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Wed, 26 Jan 2005 17:32:47 -0500 Subject: exclude binary files from os.walk In-Reply-To: <41f8167b$0$8648$a1866201@visi.com> References: <41f8167b$0$8648$a1866201@visi.com> Message-ID: Grant Edwards wrote: > On 2005-01-26, rbt wrote: > > >>Is there an easy way to exclude binary files (I'm working on >>Windows XP) from the file list returned by os.walk()? > > > Sure, assuming you can provide a rigorous definition of 'binary > files'. :) non-ascii From grahamd at dscpl.com.au Wed Jan 5 17:25:28 2005 From: grahamd at dscpl.com.au (grahamd at dscpl.com.au) Date: 5 Jan 2005 14:25:28 -0800 Subject: modpython, apache and windows References: <41DB3F0A.2010706@tiscali.co.uk> Message-ID: <1104963928.944830.39170@c13g2000cwb.googlegroups.com> Bob Van Zant wrote: > Fortunately most of the Python-for-the-web implementations do not follow > closely to the PHP paradigm of web-based programming. There are some, > like PSP, that more closely model what PHP does. > > It is not uncommon to have something like index.py which does hardly > anything except fire up a framework that takes care of parsing the rest > of the URI and passing control over to the proper script. Using some > relatively cryptic features of Apache you can hide the fact that > everything goes through index.py (mod_rewrite). I have never really liked how all these different mod_python extensions insist on using their own special file extensions, eg., .psp, .mps etc. All it does is to expose what you are using to implement a site and makes it hard for you to convert to a different implementation mechanism as all your URLs then need to change. As you point out, the only way around it is to use mod_rewrite rules. Overall, from what I have seen all it does is make configuration files harder to understand and spawn lots of newbie questions as to why they can't get anything to work. To me it is more sensible to use REST principles and not use file type extensions at all, or use an extension which reflects the type of content being delivered up and not the mechanism used to generate it. FWIW, the Vampire package tries to address this problem in mod_python by providing a simple mechanism as an extension to mod_python which gives one greater control over the file extension used in a URL and what handler that then maps to. To set it up, one has a single directive in your httpd.conf or htaccess file of the form: PythonHandler vampire You can then place in your directory any number of content handler .py files. Eg. you might have index.py, about.py, report.py etc. In the first instance, no matter what the file type extension on the URL, if the basename in the URL request matches the basename of the content handler file, then it is that file which is the target of the request. Thus, if you used the following URLs, they would map as shown: index.html --> index.py about.html --> about.py report.pdf --> report.py report.csv --> report.py feedback --> feedback.py Now normally the content handler would be called "handler()". Using vampire though, you extend the name with the file type, thus: index.html --> will call handler_html() in index.py about.html --> will call handler_html() in about.py report.pdf --> will call handler_pdf() in report.py report.csv --> will call handler_csv() in report.py feedback --> will call handler() in feedback.py Thus, you can use a more sensible file type in the URL without having to resort to mod_rewrite rules. Further, where a specific resource can be represented in multiple formats which are both generated on the fly, you can have a handler for each in the same content handler .py file, eg., as in .pdf and .csv case. You can also follow REST princinples and have no extension at all. You aren't restricted to just having content handlers in a directory though. You can still have other files such .html and .jpg files. If Vampire determines that there is no content handler corresponding to a request, it will decline to service it and pass it back to Apache which will then serve up the raw .html or .jpg file directly. I should point out that Vampire is not a framework in the sense that it doesn't dictate how your pages are rendered. That handler function which is called is basically the same as a stock standard mod_python handler method. Inside that function you still need to provide the code which creates the response, although there is no reason why you can't on a per resource case trigger off a different system such as PSP, mpservlets or HTMLTemplate to generate the HTML. More could be said, but best to check out: http://www.dscpl.com.au/projects/vampire -- Graham Dumpleton From sxanth at ceid.upatras.gr Fri Jan 7 13:25:16 2005 From: sxanth at ceid.upatras.gr (Stelios Xanthakis) Date: Fri, 07 Jan 2005 10:25:16 -0800 Subject: python-dev Summary for 2004-11-16 through 2004-11-30 In-Reply-To: <1105002357.261642.292880@f14g2000cwb.googlegroups.com> References: <1105002357.261642.292880@f14g2000cwb.googlegroups.com> Message-ID: <41DED40C.3030000@ceid.upatras.gr> michele.simionato at gmail.com wrote: >>Would you like the source with your function? > > > Yes, since I asked for this feature something like two years ago ;-) Well, the main objection seemed to be that we can get the source of a function one way or another. For functions with a file (1) with "inspect" , for functions defined dynamically with "exec"(2), by "knowing what we pass to exec and storing it", and for functions defined in the interactive prompt (3), by using a higher level IDE/shell that is not the pure raw_input, but does sophisticated analysis of code fed to it and which will be responsible for storing functions (!!). Still I believe it's the job of the core python parser to get this info and attach it to function objects. The other problem was whether the source attribute should be saved to pyc files (or more generally marhsaled together with the function object). Logically it should. OTOH, for the application I had using this, I didn't need marshalling source because it stored all the code (initial functions + functions defined while the application was running) in python source form. So, I think that in practice one will use either bytecode or the __source__ feature and not both, but I can't prove it. 8) There's a PEP and an --ugly- patch for 2.3.4 +10 ? Stelios From skip at pobox.com Fri Jan 28 16:03:34 2005 From: skip at pobox.com (Skip Montanaro) Date: Fri, 28 Jan 2005 15:03:34 -0600 Subject: debugging os.spawn*() calls In-Reply-To: References: <16890.22749.899414.324589@montanaro.dyndns.org> Message-ID: <16890.43174.16771.956147@montanaro.dyndns.org> Nick> If using 2.4 the subprocess module is a good solution too. It Nick> lets you catch stdout/stderr easily. Yeah, thought of that already. Currently not an option though. Thx, Skip From alan.gauld at btinternet.com Sun Jan 2 03:47:52 2005 From: alan.gauld at btinternet.com (Alan Gauld) Date: Sun, 2 Jan 2005 08:47:52 +0000 (UTC) Subject: Frameworks for "Non-Content Oriented Web Apps" References: <1104641466.776338.71700@z14g2000cwz.googlegroups.com> Message-ID: <36dft0h1v561ejq8u9gnp37063ljjna3rc@4ax.com> On 1 Jan 2005 20:51:06 -0800, mirnazim at gmail.com wrote: > Is there something that can ease the development of application that > are not content oriented(I call them "NON CONTENT-ORIENTED WEB > APPLICATIONS" because I don't know what else to call them). I mean the > applications like, accounting, high volume data entry apps, where > normally GUI clients have ruled. I know very high quality ERP I don;t know of any such frameworks. The Siebel CRM system may be the kind of thing you mean I think, but it uses standard technology. IT just puts up a form then uses client side Javascript to detect changes and send the data requests to/from the data server... No special frameworks as such... HTH, Alan G. Author of the Learn to Program website http://www.freenetpages.co.uk/hp/alan.gauld From elephantum at dezcom.mephi.ru Sun Jan 9 06:10:04 2005 From: elephantum at dezcom.mephi.ru (Andrey Tatarinov) Date: Sun, 09 Jan 2005 14:10:04 +0300 Subject: python3: 'where' keyword In-Reply-To: <7x3bxbe97m.fsf@ruckus.brouhaha.com> References: <3480qqF46jprlU1@individual.net> <1105228549.608275.148740@c13g2000cwb.googlegroups.com> <7xk6qnzd3d.fsf@ruckus.brouhaha.com> <1105230350.861683.265970@c13g2000cwb.googlegroups.com> <7x3bxbe97m.fsf@ruckus.brouhaha.com> Message-ID: <34choeF48qugdU1@individual.net> Paul Rubin wrote: >>What would be the advantage of that over this? >> >>. x = sqrt(a) + sqrt(b) where: >>. a = 2.0 >>. b = 3.0 > The idea of "where" is to allow re-using variable names instead of > having to keep track of which ones are in use. I just tried to give a > very simple example of how you might do that more than once in a > statement. then I'd write something like this: x = a + b where: a = sqrt(n) where: n = 2. b = sqrt(n) where: n = 3. From jelle.feringa at ezct.net Tue Jan 11 12:18:18 2005 From: jelle.feringa at ezct.net (Jelle Feringa // EZCT / Paris) Date: Tue, 11 Jan 2005 18:18:18 +0100 Subject: os.spawn & stdOUT trouble Message-ID: <20050111171736.D43EC1C0025D@mwinf0101.wanadoo.fr> Yikes, how painful, I meant stdOUT > trouble instead of stdin... Awefully sorry Cheers, Jelle ##thanks for pointing that out Denis! From ssaeed1973 at yahoo.com Sun Jan 30 02:49:00 2005 From: ssaeed1973 at yahoo.com (ssaeed1973 at yahoo.com) Date: 29 Jan 2005 23:49:00 -0800 Subject: Need programming tip Message-ID: <1107071340.486489.146580@f14g2000cwb.googlegroups.com> I am trying to write a program in python (brand new to Python) that would create a database of posts made to binary groups so the user can search for a certain file and have a nzb file returned. I am planning on using the XOVER command to get the list of posts and then dump those into a database. The part I am stuck at now is that some file posts consist of multiple parts as below (abbreviated XOVER reply) 1511156 As Requested 2000 adv server -2000AdvSrv.vol001+02.PAR2 (1/4) - 21/27 1511157 As Requested 2000 adv server -2000AdvSrv.vol001+02.PAR2 (2/4) - 21/27 1511158 As Requested 2000 adv server -2000AdvSrv.vol001+02.PAR2 (3/4) - 21/27 1511159 As Requested 2000 adv server -2000AdvSrv.vol001+02.PAR2 (4/4) - 21/27 I am trying to detect how many segments make up this post. One solution would be to look for (1/ in the subject string then find the denominator and loop thru as many times as the denominator to create the part of the nzb file. Is this the best way or is there an easier method? Also what would be the best way to search for the (1/ using string searches or RegExp? If REgExp could someone provide me with the RegExp for searching for this string? Thanks Salman From lee at example.com Sun Jan 2 10:32:58 2005 From: lee at example.com (Lee Harr) Date: Sun, 02 Jan 2005 15:32:58 GMT Subject: What can I do with Python ?? References: <1ssrl3pa3wawq.l1h3dq25szp9$.dlg@40tude.net> <1gpqhbl.125l3evz09uefN%aleaxit@yahoo.com> Message-ID: On 2005-01-02, Brian Beck wrote: > Alex Martelli wrote: >> You _gotta_ be kidding, right...? The Beginner's Guide link takes you >> right to the BeginnersGuide page which starts with the reassurance that >> Python is easy to learn even if you're new to programming and continues >> with a zillion useful links. The Python Books link takes you to a huge > > While I agree that there is much useful content on the official Python > site, I particularly hate the BeginnersGuide and much of the resulting > introduction pages. Often when I happily refer Python to someone who > wants to learn a simple language, I go to the Python site and imagine > where I would start if I were them. Once I get to the BeginnersGuide I > don't see anything immediately useful, and when I look for it I get > frustrated. > I think it looks pretty good. The only problem I see is section 5 where it says: 5. Did we miss your concern? Please add a comment to this page. but the page is immutable. From tjreedy at udel.edu Thu Jan 6 19:16:06 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 6 Jan 2005 19:16:06 -0500 Subject: The Industry choice References: <25mlt05vtce42ohljk32qish66oj9bq049@4ax.com><7xvfach813.fsf@ruckus.brouhaha.com><344l83F45rstqU1@individual.net> Message-ID: "Bulba!" wrote in message news:nocrt0119cncjco13l63l9d5nfeimk5820 at 4ax.com... > Which I find again wrong: suppose this developer used GPL-ed > library A, developed patches B and C. He provided you with > the source code of publicly available library A and a patch > C, but he doesn't want to release patch B. Then he does not have to. As I understand the GPL, as long as he does not release (distribute) the patch in any form (in particular, binary), then the GPL has no effect. What strikes me as funny about GPL sniping is that many programmers, including I am sure some of the snipers, sign Terms of Employment contracts far more restrictive of their freedom than one could possibly accuse the GPL of being. But I have seen little or no discussion of this (at least on clp). In fact, I wonder if the GPL might be a substitute target. Terry J. Reedy From irmen at -nospam-remove-this-xs4all.nl Sun Jan 16 17:29:05 2005 From: irmen at -nospam-remove-this-xs4all.nl (Irmen de Jong) Date: Sun, 16 Jan 2005 23:29:05 +0100 Subject: threading and sockets ? In-Reply-To: References: Message-ID: <41eaeaae$0$6203$e4fe514c@news.xs4all.nl> ionel wrote: > how to make a efficient server.. please point me to some good and clear examples I nominate SocketServer.ThreadingTCPServer from the standard library. --Irmen From P at draigBrady.com Thu Jan 6 08:56:04 2005 From: P at draigBrady.com (P at draigBrady.com) Date: Thu, 06 Jan 2005 13:56:04 +0000 Subject: get the IP address of a host In-Reply-To: References: Message-ID: J Berends wrote: > def getipaddr(hostname='default'): [snip] > > It returns the IP address with which it connects to the world (not lo), > might be a pvt LAN address or an internet routed IP. Depend on where the > host is. > > I hate the google trick actually, so any suggestions to something better > is always welcome. Yes your IP is determined really by what you connect to. So I did essentially the same as you. For reference see getMyIPAddress() at the following: http://www.pixelbeat.org/libs/PadSocket.c P?draig From hcslmf at texlife.com Mon Jan 10 12:49:12 2005 From: hcslmf at texlife.com (brolewis) Date: 10 Jan 2005 09:49:12 -0800 Subject: Importing Problem on Windows Message-ID: <1105379352.302141.264580@f14g2000cwb.googlegroups.com> I have a directory that has two files in it: parse.py parser.py parse.py imports a function from parser.py and uses it to parse out the needed information. On Linux, the following code works without a problem: parse.py, line 1: from parser import regexsearch However, when I run the same command in Windows, I get the following error: ImportError: cannot import name regexsearch Any suggestions on why this would work on Linux but not on Windows? From beliavsky at aol.com Sun Jan 30 17:40:32 2005 From: beliavsky at aol.com (beliavsky at aol.com) Date: 30 Jan 2005 14:40:32 -0800 Subject: Fortran pros and cons (was Re: Coding style article with interesting section on white space) References: <1107010389.441457.51350@z14g2000cwz.googlegroups.com> <1107053300.326925.183080@z14g2000cwz.googlegroups.com> <1107059169.510996.262480@z14g2000cwz.googlegroups.com> <1107105022.827941.114510@c13g2000cwb.googlegroups.com> Message-ID: <1107124832.327010.181490@f14g2000cwb.googlegroups.com> Michael Tobis wrote: > > Fortran programmers are generally happy with the portability of the > > language. > > Until they try to port something...? Honestly, I can't imagine where > anyone would get this impression. >From the fact that Fortran has been used on hundreds of platforms and that many portable libraries like LAPACK exist. Fortran 90+ allows one to write even more portable code using the KIND mechanism and the selected_int_kind and selected_real_kind functions, which let you specify the ranges of basic data types. > Now, about the terseness and expressiveness? Fortran 90/95 is more expressive than Fortran 77 in many ways, as described in (for example) pages 7-8 of the essay "Numerical Recipes: Does This Paradigm Have a Future?", available at http://www.nr.com/CiP97.pdf . Quoting that paper: "This, for us, was the revelation of parallel programming in Fortran 90. The use of parallel and higher-level constructions -- wholly independently of whether they are executed on tomorrow's parallel machines or today's ordinary workstations -- expresses more science per line of code and per programming workday. Based on our own experience, we think that productivity, or achievable complexity of project, is increased a factor of 2 or 3 in going from Fortran 77 to Fortran 90 -- if one makes the investment of mastering Fortran 90's higher level constructs." > > For scientific computation, consider the case of Numeric > > and Numarray. > > I'm not happy with these, because they either make temporary arrays > with wild abandon Some early Fortran 90 compilers did this but have improved significantly in this respect. > or enforce an unnatural style of expression. I wonder what this means. > I do not suggest that Python is currently competitive with C++ or > Fortran. I simply agree with > http://www.fortranstatement.com that something new ought to be > designed, that a backward compatible Fortran2003 cannot possibly be it, > and that attention to fortran diverts resources from [the sort] of > genuine progress that ought to be possible. You have not given specifics about what "genuine progress" in a scientific programming language would be. > Performance portability has nothing to do with what I'm talking about. > > The answer belies the attitude that programmers are there to put in > time and expend effort, because the only resource worth considering is > production cycles on a big machine. Nonsense. Fortran was originally created to make PROGRAMMERS more efficient by letting them code algebraic expressions instead of machine code. > This attitude explains why working with Fortran is so unpleasant an > experience for anyone who has been exposed to other languages. "Anyone"? Since I have been exposed to Python and C++ and still find Fortran 90+ enjoyable, your statement is demonstrably false. Have you ever used a version of Fortran past F77? The free Fortran 95 compiler called g95 http://www.g95.org is available. > Getting a python package working usually amounts to an install command > to the OS and an import command to the interpreter. Then you can get > down to work. Getting a Fortran package working involves not only an > endless dance with obscure compiler flags and library links, but then a > set of workarounds for codes that produce expected results on one > compiler and compile failures or even different results on another. If one writes standard-conforming code it does not. At least with Fortran one has multiple independent implementations of an ISO standardized language, about 10 each on Intel Windows or Linux, and 4 for Mac OS X. Links are at http://dmoz.org/Computers/Programming/Languages/Fortran/Compilers/ . If one Fortran compiler leaks memory when multiplying matrices, one can use another. If Python Numarray does, the only alternative I know of is Numeric, which is no longer supported according to http://www.pfdubois.com/numpy/ . I have found it extremely useful to work with multiple compilers and compiler options. A good compiler such as Lahey/Fujitsu has debugging options that aid programmer productivity by finding bugs, both at compile and run time, at some cost in speed. I gave a few examples in a previous thread. The existence of such compilers refutes your assertion that Fortran programmers think only machine time is important. From fperez.net at gmail.com Thu Jan 27 19:23:24 2005 From: fperez.net at gmail.com (Fernando Perez) Date: Thu, 27 Jan 2005 17:23:24 -0700 Subject: gnuplot on Canvas widget References: <1106852695.371569.234820@f14g2000cwb.googlegroups.com> <1106865871.537454.128830@c13g2000cwb.googlegroups.com> Message-ID: Jonathan Ellis wrote: > Blues wrote: >> I have used two great models - Tkinter and Gnuplot.py - for a while. > I >> can display an image on a Canvas widget using Tkinter and I can also >> generate a gnuplot from Python on the fly in a separate window. Does >> anyone know how to display such a gnuplot on the Canvas widget with > an >> image in it? Thanks. > >>From my experience, the Gnuplot module isn't designed to be used in > "headless" mode -- it can save to the usual formats, but you have to > render everything in an x11 window interactively first. > It might not be hard to modify this, though. That's not correct. I have tons of Gnuplot.py based scripts which write directly to EPS output, without ever opening a gui window. Note that Gnuplot still tries to initialize the X11 terminal at startup, so they would require modifications to run over ssh without X forwarding. The default plot() command in Gnuplot.py doesn't make it too convenient to do this, but it's possible. The Gnuplot support in ipython (http://ipython.scipy.org) extends the syntax of the plot() command to make it trivial to render to EPS without a terminal. It shouldn't be hard to modify this to render to other formats, while avoiding opening an X11 window. Best, f From gsakkis at rutgers.edu Mon Jan 24 17:42:55 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Mon, 24 Jan 2005 17:42:55 -0500 Subject: Tuple slices References: <35kn4mF4o44ufU1@individual.net> <35l5d9F4licj2U1@individual.net> Message-ID: <35lbvdF4k3ss4U1@individual.net> "Peter Hansen" wrote in message news:A9OdnRotCdqJ-2jcRVn-jA at powergate.ca... > George Sakkis wrote: > > Fair enough. So perhaps the question is whether such cases are more regular than something like: > > a = give_me_a_huge_tuple() > > slices = [a[i:j] for i in xrange(len(a)) for j in xrange(i+1, len(a)+1)] > > I believe the general usage of tuples tends to mean that > "give_me_a_huge_tuple()" just doesn't happen except with > those who insist on using tuples as though they were nothing > other than read-only lists. > > If you use a tuple the way it was apparently intended, you > are extraordinarily unlikely to find yourself with a > huge one requiring slicing in such a way that you care > whether it is a "view" or a new object. > > -Peter Actually my initial motivation was not a huge tuple I had to slice many times. It was something much less extraordinarily unlikely, a recursive function with a sequence parameter: def foo(sequence): # base_case # do_stuff() combine(foo(sequence[:n]), foo(sequence[n:])) Having each slice be a view of the original sequence instead of a fresh copy would be a Good Thing (tm). George From ncoghlan at iinet.net.au Tue Jan 18 07:42:21 2005 From: ncoghlan at iinet.net.au (Nick Coghlan) Date: Tue, 18 Jan 2005 22:42:21 +1000 Subject: lambda In-Reply-To: References: <1105633239.316956.262140@f14g2000cwb.googlegroups.com> <41EBA021.5060903@holdenweb.com> Message-ID: <41ED042D.2000004@iinet.net.au> Antoon Pardon wrote: > More specific the Decimal class is mutable and usable as dict key. It's *meant* to be immutable though. The fact that we used __slots__ instead of __setattr__ to implement the immutability, so you *can* overwrite the slot variables if you really want to is merely an artifact of the current Python implementation. The limited mutability bug will disappear in Python 2.5, so it's not a good example of a 'mutable' dict key (especially given that the only way to mutate it is to modify private variables directly). And, as I've stated previously, if the issue of sane mutable keys in dictionaries and sets really bugs you so much - implement identity_dict and identity_set in C and lobby for their inclusion in the collections module. On the more general point of "don't use mutable objects with non-identity based comparisons as dictionary keys", try teaching students for a while (or listen to those who have): When stating useful general principles, it is never, ever worth it to get into the quibbly little details about exceptions to the principle. If students ask, admit that they exist, but point out that the exceptions are rare, and not worth worrying about at that point in their learning. Only when one is aware of the reasons for a principle, can one be aware of good reasons not to follow it :) Cheers, Nick. -- Nick Coghlan | ncoghlan at email.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.skystorm.net From jepler at unpythonic.net Sat Jan 29 23:00:51 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Sat, 29 Jan 2005 22:00:51 -0600 Subject: [Tkinter] problem In-Reply-To: References: Message-ID: <20050130040049.GB20609@unpythonic.net> These lines > if __name__ == '__main__': > OptionsWindow() mean "if this source code is the main program (not an imported module), call OptionsWindow()". So the behavior should be different when the source code is the main program ('python opt_newlogin.py') and when it's imported ('python -c "import opt_newlogin"') Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From tom at dtsam.com Wed Jan 26 10:39:31 2005 From: tom at dtsam.com (Thomas Bartkus) Date: Wed, 26 Jan 2005 09:39:31 -0600 Subject: python without OO References: <1106689788.676121.48490@c13g2000cwb.googlegroups.com> Message-ID: "Davor" wrote in message news:ct6kvm$edg$1 at rumours.uwaterloo.ca... > > On the other hand, this does beggar for a reason to bother with Python at > > all. It seems you could be happy doing BASH scripts for Linux or DOS batch > > files for Windows. Both are "nice&simple" scripting languages free of > > object oriented contamination. > > not really, what I need that Python has and bash&dos don't is: > > 1. portability (interpreter runs quite a bit architectures) > 2. good basic library (already there) > 3. modules for structuring the application (objects unnecessary) > 4. high-level data structures (dictionaries & lists) > 5. no strong static type checking > 6. very nice syntax > > so initially I was hoping this is all what Python is about, ... The irony here is that the OO approach woven into the warp and woof of Python is what make 1-6 possible. > but when I > started looking into it it has a huge amount of additional (mainly OO) > stuff which makes it in my view quite bloated now... Again, there is nothing "additional" about the OO in Python. It is the very foundation upon which it is built. > ... anyhow, I guess > I'll have to constrain what can be included in the code through > different policies rather than language limitations... It would be reasonable to decide that Python is not what you are looking for. I'm not sure that castrating it in this manner would be quite so reasonable. Thomas Bartkus From philippecmartin at sbcglobal.net Fri Jan 7 07:16:49 2005 From: philippecmartin at sbcglobal.net (Philippe C. Martin) Date: Fri, 07 Jan 2005 13:16:49 +0100 Subject: Tkinter: passing parameters to menu commands Message-ID: <1105100209.6909.6.camel@localhost> Hi, I have he following need and do not find an easy way out: I have many menu items and would like them all to call the same method -However, I need the method called to react differently depending on the menu item selected. Since the menu command functions do not seem to receive any type of event style object, is there some type of Tkinter call that would let my method know the menu id selected ? Philippe -- *************************** Philippe C. Martin SnakeCard LLC www.snakecard.com *************************** From snacktime at gmail.com Sun Jan 23 18:50:50 2005 From: snacktime at gmail.com (snacktime) Date: Sun, 23 Jan 2005 15:50:50 -0800 Subject: Set parity of a string In-Reply-To: References: <1f060c4c050123140310e6f887@mail.gmail.com> Message-ID: <1f060c4c05012315506a2c9cb4@mail.gmail.com> On Sun, 23 Jan 2005 23:52:29 +0100, Fredrik Lundh wrote: > "snacktime" wrote: > > > Is there a module that sets the parity of a string? I have an > > application that needs to communicate with a host using even parity > > So what I need is before sending the message, convert it from space to > > even parity. And when I get the response I need to convert that from > > even to space parity. > > umm. shouldn't the communication library do this for you? > The communication is an https post, but the host needs the data in even parity before sending it into their internal systems (this is a large bank network) and it's up to the client to do the transformation. Chris From rkern at ucsd.edu Sat Jan 15 15:12:26 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sat, 15 Jan 2005 12:12:26 -0800 Subject: hash patent by AltNet; Python is prior art? In-Reply-To: <41e96949$0$44082$5fc3050@dreader2.news.tiscali.nl> References: <41e96949$0$44082$5fc3050@dreader2.news.tiscali.nl> Message-ID: GerritM wrote: > ZDnet features an article about the had patent at AltNet > http://news.zdnet.com/2100-9588_22-5534087.html . Apparantly this issue > plays already for some time, now the p2p companies are threatened, becuase > they use hashing to recognize files. > > As far as I know hasing is a very old technique used to quickly look up > information. The use of hashing always requires an idnetity check, because > the lookup is not unique (mapping a very big amount of possibilities on a > limited amount of entries). This is a fast and robust way of finding > information, if the right hashing function is used. I don't know the details, but I'm willing to bet that the kind of hashes being disputed here are cryptographic hashes, not the kind that Python uses for dictionaries. I'm also willing to bet that the patent won't hold up in court because there's quite a lot of prior art with respect to cryptographic hashes, too. -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From sjmachin at lexicon.net Tue Jan 11 17:16:07 2005 From: sjmachin at lexicon.net (John Machin) Date: 11 Jan 2005 14:16:07 -0800 Subject: Octal notation: severe deprecation References: Message-ID: <1105481767.711530.116290@z14g2000cwz.googlegroups.com> Some poster wrote (in connexion with another topic): > ... unicode("\347", "iso-8859-1") ... Well, I haven't had a good rant for quite a while, so here goes: I'm a bit of a retro specimen, being able (inter alia) to recall octal opcodes from the ICT 1900 series (070=call, 072=exit, 074=branch, ...) but nowadays I regard continued usage of octal as a pox and a pestilence. 1. Octal notation is of use to systems programmers on computers where the number of bits in a word is a multiple of 3. Are there any still in production use? AFAIK word sizes were 12, 24, 36, 48, and 60 bits -- all multiples of 4, so hexadecimal could be used. 2. Consider the effect on the newbie who's never even heard of "octal": >>> import datetime >>> datetime.date(2005,01,01) datetime.date(2005, 1, 1) >>> datetime.date(2005,09,09) File "", line 1 datetime.date(2005,09,09) ^ SyntaxError: invalid token [straight out of the "BOFH Manual of Po-faced Error Messages"] 3. Consider this extract from the docs for the re module: """ \number Matches the contents of the group of the same number. Groups are numbered starting from 1. For example, (.+) \1 matches 'the the' or '55 55', but not 'the end' (note the space after the group). This special sequence can only be used to match one of the first 99 groups. If the first digit of number is 0, or number is 3 octal digits long, it will not be interpreted as a group match, but as the character with octal value number. Inside the "[" and "]" of a character class, all numeric escapes are treated as characters. """ I helped to straighten out this description a few years ago, but I fear it's still not 100% accurate. Worse, take a peek at the code necessary to implement this. === We (un-Pythonically) implicitly take a leading zero (or even just \[0-7]) as meaning octal, instead of requiring something explicit as with hexadecimal. The variable length idea in strings doesn't help: "\18", "\128" and "\1238" are all strings of length 2. I don't see any mention of octal in GvR's "Python Regrets" or AMK's "PEP 3000". Why not? Is it not regretted? From rmemmons at member.fsf.org Thu Jan 13 20:59:57 2005 From: rmemmons at member.fsf.org (Rob Emmons) Date: Thu, 13 Jan 2005 19:59:57 -0600 Subject: Newbie: module structure and import question References: <8fb821f9.0501120706.499dd04c@posting.google.com> Message-ID: > hi all, > i have question on how to design a module structure. > for example, i have 3 files. > [somewhere]/main.py > [somewhere]/myLib/Base/BaseA.py > [somewhere]/myLib/ClassA.py > .... > ..... > It's fine when i run main.py. > however when i run ClassA.py individually, it would fail in import > statment since the import path is incorrect. > I would like to know is something wrong in my design, or something i > missed. I think your issue is your module search path. Take a look at the doc for sys.path in the library reference. These are the directories that python searchies for modules. Usually the "." directory is included in this which makes python search the current working directory. Your example fails because your working directories are probably different when you ran the two modules. In any case always consider how you've setup sys.path and your libraries and modules. > Also, in practical usage, is that one class in one py file? I'm not exactly clear what your asking -- but I think yor asking if you'd normally only put one class in one py file. My answer is no -- generally you'd put many functions and classes in each py file. Modules are high level and should be used to create libraries essentailly -- this means many fucntions and classes per module. Rob From iseestars at gate.net Thu Jan 27 21:14:07 2005 From: iseestars at gate.net (inhahe) Date: Thu, 27 Jan 2005 21:14:07 -0500 Subject: Why do look-ahead and look-behind have to be fixed-width patterns? Message-ID: Hi i'm a newbie at this and probably always will be, so don't be surprised if I don't know what i'm talking about. but I don't understand why regex look-behinds (and look-aheads) have to be fixed-width patterns. i'm getting the impression that it's supposed to make searching exponentially slower otherwise but i just don't see how. say i have the expression (?<=.*?:.*?:).* all the engine has to do is search for .*?:.*?:.*, and then in each result, find .*?:.*?: and return the string starting at the point just after the length of the match. no exponential time there, and even that is probably more inefficient than it has to be. From shalabh at cafepy.com Sun Jan 23 17:39:08 2005 From: shalabh at cafepy.com (Shalabh Chaturvedi) Date: Sun, 23 Jan 2005 14:39:08 -0800 Subject: Solutions for data storage? In-Reply-To: <356c7tF4g3f64U1@individual.net> References: <356c7tF4g3f64U1@individual.net> Message-ID: <41F4278C.8000206@cafepy.com> Leif K-Brooks wrote: > I'm writing a relatively simple multi-user public Web application with > Python. It's a rewrite of a similar application which used PHP+MySQL > (not particularly clean code, either). My opinions on various Web > frameworks tends to vary with the phase of the moon, but currently, I'm > planning to use Quixote. Good choice, IMO! And while you're using Quixote, you might want to look at QLime [1] for all your data storage needs :) > I've looked at SQLObject, and it's very nice, but it doesn't provide > certain features I really want, like the ability to store lists of > strings or integers directly in the database (using commas in a varchar > column or something). In any mapper that lets you set attributes for storing columns (such as QLime), this should be fairly simple using properties. > My ideal solution would be an object database (or object-relational > mapper, I guess) which provided total transparency in all but a few > places, built-in indexing, built-in features for handling schema > changes, the ability to create attributes which are required to be > unique among other instances, and built-in querying with pretty syntax. Briefly, QLime uses RDBMS indexing, automatically handles schema changes (in fact you don't define the schema in Python at all, you just create the table). For uniqueness you'd have to set the constraint on the table. To look at the query syntax avaialable, (and OR mapping features) see http://www.qlime.org/0.5.1/qlime_or_mapping.html. Cheers, Shalabh [1] http://www.qlime.org/ From devries at idolstarastronomer.com Mon Jan 3 20:52:40 2005 From: devries at idolstarastronomer.com (Christopher De Vries) Date: 3 Jan 2005 17:52:40 -0800 Subject: How do I make Windows Application with Python ? In-Reply-To: <1104802115.543884.96150@z14g2000cwz.googlegroups.com> References: <6zmwoasy10u4$.f3k91xbegrcz.dlg@40tude.net> <1uus5gx5sfemv.1xp4xtmzz9u66.dlg@40tude.net> <1104802115.543884.96150@z14g2000cwz.googlegroups.com> Message-ID: <1104803560.244274.251150@c13g2000cwb.googlegroups.com> I should learn to type faster. You beat me to the response. Chris From http Sun Jan 30 06:43:26 2005 From: http (Paul Rubin) Date: 30 Jan 2005 03:43:26 -0800 Subject: What's so funny? WAS Re: rotor replacement References: <41f4324a$0$1547$9b622d9e@news.freenet.de> <41f589f9$0$3357$9b622d9e@news.freenet.de> <41f6a8ef$0$27790$9b622d9e@news.freenet.de> <41f7efc2$0$11596$9b622d9e@news.freenet.de> <41f97630$0$11586$9b622d9e@news.freenet.de> <7xu0p2dvsa.fsf@ruckus.brouhaha.com> <41f9f5e6$0$25927$9b622d9e@news.freenet.de> <7x4qh13o0o.fsf@ruckus.brouhaha.com> <41FACD1C.6000301@v.loewis.de> <7xacqt56ga.fsf@ruckus.brouhaha.com> <41fb646a$0$31784$9b622d9e@news.freenet.de> <7xacqsbfk2.fsf@ruckus.brouhaha.com> <41fbcb11$0$12030$9b622d9e@news.freenet.de> <7xsm4j1wbe.fsf@ruckus.brouhaha.com> Message-ID: <7xpszngn1d.fsf@ruckus.brouhaha.com> Nick Craig-Wood writes: > There is a PEP about this... > > API for Block Encryption Algorithms v1.0 > http://www.python.org/peps/pep-0272.html Yes, I know about that and have been in contact with its author. He and I are in agreement (or at least were in agreement some time ago) that the proposed API of the new module is an improvement, at least for a generic module. PEP 272 seems to document the interface of something that had been implemented for some particular application. From zuerich at hebeler.net Thu Jan 27 11:20:21 2005 From: zuerich at hebeler.net (Felix Hebeler) Date: Thu, 27 Jan 2005 17:20:21 +0100 Subject: how to pass attribute name via sys.argv In-Reply-To: References: <41f8e31a$1@idnews.unizh.ch> Message-ID: <41f914c3$1@idnews.unizh.ch> Wolfram Kraus wrote: > Felix Hebeler wrote: > >> >> I need to call an object attribute: >> >> value = object.attrName[0] >> > > Use getattr: > value = getattr(object, attrName)[0] > > > > HTH, > Wolfram Thanks so much! Had I known earlier. Looks so easy... Now, why did I not find this in the online tutorial, the reference manual, or google? Not that I didn't try... I mean, I would find 'getattr' if I searched, but if you don't know what you're looking for.. I find the reference manual extremely (== too) compact to look things up. A couple of colleages and me agreed that it is much more difficult to find solutions and _useful_ tips for Python than e.g. for Java (where there's Javadoc for example). The syntax doc in the reference manual to me looks like computer linguists might understand, but unfortunately not me. And Python code IS really easy to read, I agree, but what if I can't find out how to write it? I'd appreciate any link to online resources or recommendations for books (english/german)! Chances are I'm a silly/lazy/deprived/stupid bugger, but I try to think there's still hope! again, thank you so much for your quick response (thanks Gilles Lenfant too!), I really DO like the Python community ;-) Cheers Felix From jerf at jerf.org Sat Jan 15 18:13:04 2005 From: jerf at jerf.org (Jeremy Bowers) Date: Sat, 15 Jan 2005 18:13:04 -0500 Subject: threading and sockets ? References: Message-ID: On Sun, 16 Jan 2005 05:30:37 +0200, ionel wrote: > how to make a efficient server.. please point me to some good and clear examples Your question is too broad. There is no such thing as "a server", the server must *do* something and it is generally named for what it does.. Please read http://www.catb.org/~esr/faqs/smart-questions.html and try again. That said, Twisted is a likely good first stop. http://twistedmatrix.com/ But I have no way of knowing that, only a guess. From steven.bethard at gmail.com Thu Jan 27 13:06:18 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 27 Jan 2005 11:06:18 -0700 Subject: Help With Python In-Reply-To: References: <87ekg8c4d0.fsf@localhost.localdomain.i-did-not-set--mail-host-address--so-tickle-me> Message-ID: Nick Craig-Wood wrote: > Steven Bethard wrote: >> py> orders = [Viking().order()] * 7 >> py> ', '.join(orders) >> 'Spam, Spam, Spam, Spam, Spam, Spam, Spam' > > Thats still one Viking making 7 orders surely? > > So you want this... > >>>>orders = [ Viking().order() for _ in range(7) ] Right, right. Thanks for the correction! This is why I never use the * operator on lists. ;) Steve From phil at riverbankcomputing.co.uk Mon Jan 10 07:30:04 2005 From: phil at riverbankcomputing.co.uk (Phil Thompson) Date: Mon, 10 Jan 2005 12:30:04 -0000 (GMT) Subject: Command line and GUI tools : need a single threading solution In-Reply-To: <41e26e79@duster.adelaide.on.net> References: <41e26e79@duster.adelaide.on.net> Message-ID: <7461.82.68.80.137.1105360204.squirrel@82.68.80.137> > I have a collection of multi-threaded command line tools which I want wrap > a > PyQt gui around. I'm using queues to route messages from the command line > tools to the PyQt gui. The command line tools use python threads to do > their work. The gui uses a QThread object to read incoming messages. > > This does not work consistently - and I've since read that mixing python > threads and QThreads is a bad idea. The command line tools work well > using > python threads. How well mixing the two threading APIs works depends on version numbers. A PyQt generated with SIP v4.x (rather than SIP v3.x) with Python v2.4 should be Ok. > I don't want to maintain two copies of the tools - one for command line > and > another for the PyQt version. > > I'm thinking it may be possible to modify the command line tools to use qt > threads instead of native python threads. Is this the way to go? Are > there other options? Using QThreads only should work - just tell the QApplication ctor that you have a console application. Phil From asda at sdarta.com Sat Jan 8 21:22:54 2005 From: asda at sdarta.com (worzel) Date: Sun, 9 Jan 2005 10:22:54 +0800 Subject: The best way to do web apps with Python? References: <41dfdc15$0$29387$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <41e0957d$0$21086$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Holy Moly - there's quite a few choices out there! I like the look of Karrigel for my immediate needs. Looking forward to the day there is a more 'j2ee' like standard in place for Python - looks like this is in the works. Thanks for all the feedback guys. "worzel" wrote in message news:41dfdc15$0$29387$5a62ac22 at per-qv1-newsreader-01.iinet.net.au... What is the best way to web developemnt with Python? Is there anything close to PHP style in-page script placement that can create and use other Python objects? I am not really interested in Zope (I believe that is more a CMS than anything else?) I am also looking for something a little more structured than a series of CGI Scripts. While on the topic - what is the expectataion of Python for this kind of stuff? Would one use Python for certain other things but turn to PHP for web apps - or would one use their Python skills in place of PHP? TIA From steve at holdenweb.com Thu Jan 6 08:45:21 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 06 Jan 2005 08:45:21 -0500 Subject: Other notes In-Reply-To: References: <86r7l7sczp.fsf@guru.mired.org> <1104972047.050366.211670@f14g2000cwb.googlegroups.com> Message-ID: <41DD40F1.5030301@holdenweb.com> Timo Virkkala wrote: > bearophileHUGS at lycos.com wrote: > >> Andrew Dalke: >> >>> (BTW, it needs to be 1 .. 12 not 1..12 because 1. will be interpreted >>> as the floating point value "1.0".)< >> >> Uhm, I have to fix my ignorance about parsers. >> Cannot a second "." after the first tell that the first "." isn't in >> the middle of a floating point number? > > > Python uses an LL(1) parser. From Wikipedia: > """ LL(1) grammars, although fairly restrictive, are very popular > because the corresponding LL parsers only need to look at the next token > to make their parsing decisions.""" > Indeed, but if ".." is defined as an acceptable token then there's nothing to stop a strict LL(1) parser from disambiguating the cases in question. "Token" is not the same thing as "character". >>>> This may allow: assert 5 interval 9 == interval(5,9) >>> >>> Maybe you could give an example of when you need this in real life?< >> >> Every time you have a function with 2 parameters, you can choose to use >> it infix. > > > But why would you want to? What advantage does this give over the > standard syntax? Remember, in Python philosophy, there should be one > obvious way to do it, and preferably only one. Adding a whole another > way of calling functions complicates things without adding much > advantage. Especially so because you suggest it is only used for binary, > i.e. two-parameter functions. This part of your comments I completely agree with. However, we are used to people coming along and suggesting changes to Python on comp.lang.python. Ironically it's often those with less experience of Python who suggest it should be changed to be more like some other language. One of the things I like best about c.l.py is its (almost) unfailing politeness to such posters, often despite long stream-of-consciousness posts suggesting fatuous changes (not necessarily the case here, by the way). The level of debate is so high, and so rational, that the change requesters are often educated as to why their suggested changes wouldn't be helpful or acceptable, and having come to jeer they remain to whitewash, to use an analogy from "Tom Sawyer" [1]. All in all a very pleasant change from "F*&% off and die, noob". regards Steve [1]: http://www.cliffsnotes.com/WileyCDA/LitNote/id-2,pageNum-10.html -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 From fumanchu at amor.org Mon Jan 10 13:14:24 2005 From: fumanchu at amor.org (Robert Brewer) Date: Mon, 10 Jan 2005 10:14:24 -0800 Subject: Writing huge Sets() to disk Message-ID: <3A81C87DC164034AA4E2DDFE11D258E339814F@exchange.hqamor.amorhq.net> Martin MOKREJ? wrote: > Robert Brewer wrote: > > Martin MOKREJ? wrote: > > > >> I have sets.Set() objects having up to 20E20 items, > >>each is composed of up to 20 characters. Keeping > >>them in memory on !GB machine put's me quickly into swap. > >>I don't want to use dictionary approach, as I don't see a sense > >>to store None as a value. The items in a set are unique. > >> > >> How can I write them efficiently to disk? > > > > > > got shelve*? > > I know about shelve, but doesn't it work like a dictionary? > Why should I use shelve for this? Then it's faster to use > bsddb directly and use string as a key and None as a value, I'd guess. If you're using Python 2.3, then a sets.Set *is* implemented with a dictionary, with None values. It simply has some extra methods to make it behave like a set. In addition, the Set class already has builtin methods for pickling and unpickling. So it's probably faster to use bsddb directly, but why not find out by trying 2 lines of code that uses shelve? The time-consuming part of your quest is writing the timed test suite that will indicate which route will be fastest, which you'll have to do regardless. Robert Brewer MIS Amor Ministries fumanchu at amor.org From danperl at rogers.com Fri Jan 28 08:54:28 2005 From: danperl at rogers.com (Dan Perl) Date: Fri, 28 Jan 2005 08:54:28 -0500 Subject: How to test that an exception is raised ? References: <41fa0da9$0$2018$6c56d894@feed0.news.be.easynet.net> <41fa400b$0$2029$6c56d894@feed0.news.be.easynet.net> Message-ID: "StepH" wrote in message news:41fa400b$0$2029$6c56d894 at feed0.news.be.easynet.net... > > Do you say that it's not possible to test (using unittest) if an exception > is well raised if the tested code catch it ? > How to solve this paradoxe ? How to automaticaly test such code ? Then you need a side-effect in catching the exception. A return code would be such a side-effect. Setting a state variable that can be checked by the invoking code would be another such side-effect. > 1./ Cheking error-return value if not a good idea for me, cause this make > the code less clear. I don't want a code where i've to test each function > return value... > 2./ If I re-raise the exception, then how to not show the traceback. My > user will became crazy if they view such error msg. But then how will the user know if the call did what it is supposed to do? And if the user mis-used the function and used it for a file that does not exist, how is he/she supposed to know what the problem was and why nothing is coming out of calling your function? > It seems that there is 2 school here. I've read a lot on python, and > somed > 'guru' Python say that it's maybe better to use exception even for case > you > can "predict", no ? Or i'm completly wrong ? The IOError is an exception that you can predict and I was saying that you should catch it, but with a "except IOError:" statement instead of the "except:" statement that you used. From jjl at pobox.com Tue Jan 25 18:19:00 2005 From: jjl at pobox.com (John J. Lee) Date: 25 Jan 2005 23:19:00 +0000 Subject: rotor replacement References: <7x1xcidnp1.fsf@ruckus.brouhaha.com> <41EE24F7.7030303@jessikat.fsnet.co.uk> <41EEF691.20706@jessikat.fsnet.co.uk> <7xacr4ewjk.fsf@ruckus.brouhaha.com> <41ef4a7a.1323588509@news.oz.net> <7xwtu8vb17.fsf@ruckus.brouhaha.com> <41EF72DE.5030305@jessikat.fsnet.co.uk> <7xwtu8pgr4.fsf@ruckus.brouhaha.com> <7x7jm5m613.fsf@ruckus.brouhaha.com> Message-ID: <87d5vthzbv.fsf@pobox.com> Paul Rubin writes: > jjl at pobox.com (John J. Lee) writes: > > > Building larger ones seems to > > > have complexity exponential in the number of bits, which is not too > > > > Why? > > The way I understand it, that 7-qubit computer was based on embedding > the qubits on atoms in a large molecule, then running the computation Oh, you mean that particular kind, OK. Doesn't apply to QC in general. > > > It's not even known in theory whether quantum computing is > > > possible on a significant scale. > > > > Discuss. > > The problem is maintaining enough coherence through the whole > calculation that the results aren't turned into garbage. In any > physically realizeable experiment, a certain amount of decoherence > will creep in at every step. So you need to add additional qubits for > error correction, but then those qubits complicate the calculation and > add more decoherence, so you need even more error correcting qubits. Yes, that's much more interesting, dunno what the current state of play is. [...] > I'm not any kind of expert in this stuff but have had some > conversations with people who are into it, and the above is what they > told me, as of a few years ago. I probably have it all somewhat garbled. Me too :-) John From martin at v.loewis.de Mon Jan 24 18:51:24 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 25 Jan 2005 00:51:24 +0100 Subject: What's so funny? WAS Re: rotor replacement In-Reply-To: References: <7x1xcidnp1.fsf@ruckus.brouhaha.com> <41EE24F7.7030303@jessikat.fsnet.co.uk> <7x1xchlpqv.fsf@ruckus.brouhaha.com> <41efeb82$0$27807$9b622d9e@news.freenet.de> <41f1a70b$0$25959$9b622d9e@news.freenet.de> <7xbrbiqdhk.fsf@ruckus.brouhaha.com> <7xllalljah.fsf@ruckus.brouhaha.com> <7xekgdmpll.fsf@ruckus.brouhaha.com> <7xpszxcnfa.fsf@ruckus.brouhaha.com> <7xllalcmqc.fsf@ruckus.brouhaha.com> <7xbrbhosh7.fsf@ruckus.brouhaha.com> <7xzmz0lw6h.fsf@ruckus.brouhaha.com> <41f4324a$0$1547$9b622d9e@news.freenet.de> Message-ID: <41f589f9$0$3357$9b622d9e@news.freenet.de> phr at localhost.localdomain wrote: > Maybe we're not thinking about the same problems. Say I'm an app > writer and I want to use one of your modules. My development > environment is GNU/Linux, and I want to ship a self-contained app that > anyone can run without having to download additional components. That > includes people wanting to run my app on Windows, Macintosh, Amiga, > and various other Python target platforms that I don't have compilers > for. How do I do it? This is not possible - whether the module is included in Python or not. People *will* have to download something besides your application, namely Python - and in the version your require, too. If they cannot compile Python themselves, they will have to find somebody who did that for them. This is very easy if you are using Windows, Debian, or Mac OS X. It is very difficult if you are using an Amiga, or any of the other Python target platforms that you don't have compilers for. HP-UX users of your application will have a hard time to get it running even if the module was available as a built-in. This does not change much if the module is available separately, and it does not change much whether the separate module is written in Python or in C: Windows, Debian, and OS X users will still find precompiled binaries for the module, and all others will still have to build it themselves. This is very easy, since all they have to do is to use distutils. > So, if your modules are generally useful, I hope you > will try to get them into the core. Right - the critical condition is "if the modules are generally useful". I cannot possibly know whether they are generally useful until a general public has commented that they are. > I can't speak for the authors but I'd personally say that none of > those old modules are really suitable for the core on technical > grounds. That is my impression, too. > The module I'm discussing would simply implement the FIPS standard > block ciphers (AES and DES) and the FIPS operating modes. These are > the basic building blocks that I feel are missing from the core. They > should be enough to fill the crypto needs of most applications. Hmm. Most applications don't have any crypto needs. Those that do typically need TLS, or secure password hashing (crypt(3) specifically). So I somehow doubt that an AES module would be generally useful. >>So if the module was primarily written to be included in the core, I >>would initially reject it for that very reason. After one year or so >>in its life, and a recognizable user base, inclusion can be >>considered. > > > That makes no sense; improving the core is a perfectly valid reason to > write something. If someone wrote a straightforward patch that made > the Python interpreter 3x faster, would you still want to wait a year > before thinking about including it? I would have to apply the "generally useful" test. For an 3x speed improvement, about 100% of the Python users would find that useful. For an AES module with an interface nobody has ever used but yourself, it would be very difficult to argue that the module is generally useful. If the module does not serve a need that people have, in general, I don't see why it should be included (and yes, I wish a few of the modules that were included recently wouldn't have been added so quickly). > I certainly believe that every > contribution needs code review and user testing before entering wide > release, but that doesn't seem to be what you're getting at. I'm primarily looking for the user testing. I require that this happens *outside* the Python distribution. Make a distutils package, and report the user feedback. Then propose inclusion into the core. > I release this "app" and presto, every Python user on every OS > platform can run it with no fuss. That includes CGI authors who > aren't allowed to install C modules at all, without getting their > hosting service to do it. How do I do the same thing if there's no > built-in sha module and all I have is sha.c? It very much depends on the details of the target system. Yes, it is a bit more tricky to install the additional library - but that is the case with any additional library, whether it is C or not. For the CGI user who is not allowed to install binaries into /usr/local, she can still install the module in her home directory, no? > To me, the whole Python notion of "batteries included" expresses > precisely the idea that I'm trying to describe. Commonly-used > functions belong in the core, because making people download or > install them separately is a pain in the neck. See, this is the critical point: "commonly-used functions", not "functions I believe would be commonly used". You must have *existing* users for a function to be commonly-used. Regards, Martin From paul.kooistra at leaseplan.nl Tue Jan 25 09:23:29 2005 From: paul.kooistra at leaseplan.nl (Paul Kooistra) Date: 25 Jan 2005 06:23:29 -0800 Subject: Browsing text ; Python the right tool? Message-ID: I need a tool to browse text files with a size of 10-20 Mb. These files have a fixed record length of 800 bytes (CR/LF), and containt records used to create printed pages by an external company. Each line (record) contains an 2-character identifier, like 'A0' or 'C1'. The identifier identifies the record format for the line, thereby allowing different record formats to be used in a textfile. For example: An A0 record may consist of: recordnumber [1:4] name [5:25] filler [26:800] while a C1 record consists of: recordnumber [1:4] phonenumber [5:15] zipcode [16:20] filler [21:800] As you see, all records have a fixed column format. I would like to build a utility which allows me (in a windows environment) to open a textfile and browse through the records (ideally with a search option), where each recordtype is displayed according to its recordformat ('Attributename: Value' format). This would mean that browsing from a A0 to C1 record results in a different list of attributes + values on the screen, allowing me to analyze the data generated a lot easier then I do now, browsing in a text editor with a stack of printed record formats at hand. This is of course quite a common way of encoding data in textfiles. I've tried to find a generic text-based browser which allows me to do just this, but cannot find anything. Enter Python; I know the language by name, I know it handles text just fine, but I am not really interested in learning Python just now, I just need a tool to do what I want. What I would REALLY like is way to define standard record formats in a separate definition, like: - defining a common record length; - defining the different record formats (attributes, position of the line); - and defining when a specific record format is to be used, dependent on 1 or more identifiers in the record. I CAN probably build something from scratch, but if I can (re)use something that already exists it would be so much better and faster... And a utility to do what I just described would be REALLY usefull in LOTS of environments. This means I have the following questions: 1. Does anybody now of a generic tool (not necessarily Python based) that does the job I've outlined? 2. If not, is there some framework or widget in Python I can adapt to do what I want? 3. If not, should I consider building all this just from scratch in Python - which would probably mean not only learning Python, but some other GUI related modules? 4. Or should I forget about Python and build someting in another environment? Any help would be appreciated. From bokr at oz.net Wed Jan 12 21:45:03 2005 From: bokr at oz.net (Bengt Richter) Date: Thu, 13 Jan 2005 02:45:03 GMT Subject: counting items References: Message-ID: <41e5ddc8.705938866@news.oz.net> On Wed, 12 Jan 2005 18:07:47 GMT, "Andrew Koenig" wrote: >"It's me" wrote in message >news:ukdFd.10645$5R.2000 at newssvr21.news.prodigy.com... > >> What's the best way to count number of items in a list? >> >> For instance, >> >> a=[[1,2,4],4,5,[2,3]] >> >> I want to know how many items are there in a (answer should be 7 - I don't >> want it to be 4) > >How about this? > > def totallen(x): > if isinstance(x, (list, tuple, dict)): > return sum(map(totallen, x)) > return 1 Since the requirement is to _count_, not flatten, ISTM your solution is best so far ;-) Regards, Bengt Richter From peter at engcorp.com Sat Jan 8 13:20:23 2005 From: peter at engcorp.com (Peter Hansen) Date: Sat, 08 Jan 2005 13:20:23 -0500 Subject: windows mem leak In-Reply-To: References: Message-ID: Bob Smith wrote: > Does the Win32 port of Python have a memory leak? I have some code that > runs flawlessly on Linux, but bombs after a few hours on Windows. It's > threaded and uses a lot of memory. Let's see what you're missing: 1. platform specifics 2. versions of things involved 3. any sort of detail about the code 4. how you're noticing/measuring the problem 5. what "bombs" means 6. any mention that you've checked Sourceforge to see whether a similar problem has been reported There have been memory leaks in various past versions of Python, and could easily be in the current version, but they're generally rather specific in terms of the code that can trigger it. Once it was doing some particular work with a socket, once it was trying to append (or extend?) to an empty list, and so on. There are also a few ways you could have written your application to cause memory to leak as a result of your own code, not as a result of Python's. And it's even possible that this would happen only on one platform (though I'm trying hard to think of an example and can't... maybe it's very unlikely.) -Peter From jack at performancedrivers.com Wed Jan 19 16:01:04 2005 From: jack at performancedrivers.com (Jack Diederich) Date: Wed, 19 Jan 2005 16:01:04 -0500 Subject: RuntimeError: dictionary changed size during iteration In-Reply-To: References: Message-ID: <20050119210104.GJ26167@performancedrivers.com> On Wed, Jan 19, 2005 at 11:45:15PM +0300, Roman Suzi wrote: > > I think, the behaviour below is misfeature: > > >>> [e for e in vars()] > Traceback (most recent call last): > File "", line 1, in ? > RuntimeError: dictionary changed size during iteration > >>> e = None > >>> [e for e in vars()] > ['e', '__builtins__', 'rlcompleter', '__file__', '_[1]', 'atexit', '__name__', > 'readline', '__doc__'] > Chalk it up as a lesson in the slightly different behavior of genexps Python 2.4 (#2, Jan 8 2005, 20:18:03) [GCC 3.3.5 (Debian 1:3.3.5-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> list(e for e in vars()) ['__builtins__', '__name__', '__doc__'] >>> [e for e in vars()] Traceback (most recent call last): File "", line 1, in ? RuntimeError: dictionary changed size during iteration -Jack From rschroev_nospam_ml at fastmail.fm Fri Jan 14 13:33:05 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Fri, 14 Jan 2005 18:33:05 GMT Subject: python and macros (again) [Was: python3: 'where' keyword] In-Reply-To: References: <1105437966.129342.304400@f14g2000cwb.googlegroups.com> <7xmzvfn096.fsf@ruckus.brouhaha.com> <1CSFd.30772$Qv5.2842746@phobos.telenet-ops.be> Message-ID: Antoon Pardon wrote: > Op 2005-01-14, Roel Schroeven schreef : > >>Antoon Pardon wrote: >> >>>IMO we have a: dogs are mamals kind of relationship in Python. >> >>I see what you mean, but I don't think it's true. >> >> >>>Every expression can be used where a statement is expected. >>>(And this can be worded as: every expression is a statement.) >> >>Not really. An expression statement is a statement that looks like an >>expression, but actually it's more than that: not only does it calculate >>the value of the expression, it also prints the value. > > > 1) Only in an interactive environment. True, I wanted to add that but forgot it. Doesn't change what I'm saying though. > 2) That the semantics differ according to where the expression is > used doesn't make a difference. That an expression decides which > branch of an if statement is executed or what object is pass > as an argument in a call are also semantic difference, yet > we still have an expression in both cases. In both cases we have an expression, in both cases we have a statement, in both cases the expression is a part of the statement. In one case the expression is the only statement, in the other case the statement has other parts too. > >>Note that it would be perfectly possible to modify the syntax into >> >>expression_stmt ::= "exprstmt" expression_list >>... > > If you change the syntax, of course you will change the strings > that will be accepted. I could change the syntax to: > > if_stmt ::= "if" "ifexpr" expression ... > > Have I now proved that expressions after an if are not normal > expressions? No, you still have a statement with one or more parts, one of which is an expression. In OOP terms: I think that an expression statement 'has an' expression (I agree that is a very thin wrapper though), not that an expression statement 'is an' expression. >>>Not every statement can be used where an expression is expected. >> >>AFAIK *no* statement can be used where an expression is expected. > > > But that was not the implication of what Guido supposedly had said. > So that this is not the case doesn't counter what I said. Whether statements can be used in the place of expressions is indeed not relevant to the discussion. Regarding what Guido apparently said: Op 2005-01-12, Steve Holden schreef : >> Given that Guido is on record as saying that expressions aren't >> statements because he wants those things to be separate Antoon Pardon wrote: > Well, it seems that Guido is wrong then. The documentation clearly > states that an expression is a statement. I don't think it says that at all. > More specifically, everywhere you can use a statement, you can > simply use an expression according to the python syntax. If you use an expression where a statement is expected, you really write an expression statement that contains the expression (and nothing else, but that doesn't matter). -- "Codito ergo sum" Roel Schroeven From bac at OCF.Berkeley.EDU Sun Jan 23 14:49:06 2005 From: bac at OCF.Berkeley.EDU (Brett C.) Date: Sun, 23 Jan 2005 11:49:06 -0800 Subject: python-dev Summary for 2004-12-01 through 2004-12-15 Message-ID: <41F3FFB2.5070607@ocf.berkeley.edu> This is a summary of traffic on the `python-dev mailing list`_ from December 01, 2004 through December 15, 2004. It is intended to inform the wider Python community of on-going developments on the list. To comment on anything mentioned here, just post to `comp.lang.python`_ (or email python-list at python.org which is a gateway to the newsgroup) with a subject line mentioning what you are discussing. All python-dev members are interested in seeing ideas discussed by the community, so don't hesitate to take a stance on something. And if all of this really interests you then get involved and join `python-dev`_! This is the fifty-fourth summary written by Brett Cannon (amazed no one has complained about the lateness of these summaries!). To contact me, please send email to brett at python.org ; I do not have the time to keep up on comp.lang.python and thus do not always catch follow-ups posted there. All summaries are archived at http://www.python.org/dev/summary/ . Please note that this summary is written using reStructuredText_ which can be found at http://docutils.sf.net/rst.html . Any unfamiliar punctuation is probably markup for reST_ (otherwise it is probably regular expression syntax or a typo =); you can safely ignore it, although I suggest learning reST; it's simple and is accepted for `PEP markup`_ and gives some perks for the HTML output. Also, because of the wonders of programs that like to reformat text, I cannot guarantee you will be able to run the text version of this summary through Docutils_ as-is unless it is from the `original text file`_. .. _PEP Markup: http://www.python.org/peps/pep-0012.html The in-development version of the documentation for Python can be found at http://www.python.org/dev/doc/devel/ and should be used when looking up any documentation on new code; otherwise use the current documentation as found at http://docs.python.org/ . PEPs (Python Enhancement Proposals) are located at http://www.python.org/peps/ . To view files in the Python CVS online, go to http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/ . Reported bugs and suggested patches can be found at the SourceForge_ project page. The `Python Software Foundation`_ is the non-profit organization that holds the intellectual property for Python. It also tries to forward the development and use of Python. But the PSF_ cannot do this without donations. You can make a donation at http://python.org/psf/donations.html . Every penny helps so even a small donation (you can donate through PayPal or by check) helps. .. _python-dev: http://www.python.org/dev/ .. _SourceForge: http://sourceforge.net/tracker/?group_id=5470 .. _python-dev mailing list: http://mail.python.org/mailman/listinfo/python-dev .. _comp.lang.python: http://groups.google.com/groups?q=comp.lang.python .. _Docutils: http://docutils.sf.net/ .. _reST: .. _reStructuredText: http://docutils.sf.net/rst.html .. _PSF: .. _Python Software Foundation: http://python.org/psf/ .. contents:: .. _last summary: http://www.python.org/dev/summary/2004-11-16_2004-11-30.html .. _original text file: http://www.python.org/dev/summary/2004-12-01_2004-12-15.ht ===================== Summary Announcements ===================== PyCon_ 2005 planning is well underway. The schedule has been posted at http://www.python.org/pycon/2005/schedule.html and looks great with a quite the varied topics. And there is still time for the early-bird registration price of $175 ($125 students) before it expires on January 28th. Some day I will be all caught up with the Summaries... .. _PyCon: http://www.pycon.org ========= Summaries ========= ---------------------------------- PEPS: those existing and gestating ---------------------------------- [for emails on PEP updates, subscribe to python-checkins_ and choose the 'PEP' topic] A proto-PEP covering the __source__ proposal from the `last summary`_ has been posted to python-dev. `PEP 338`_ proposes how to modify the '-m' modifier so as to be able to execute modules contained within packages. .. _python-checkins: http://mail.python.org/mailman/listinfo/python-checkins .. _PEP 338: http://www.python.org/peps/pep-0338.html Contributing threads: - `PEP: __source__ proposal `__ - `PEP 338: Executing modules inside packages with '-m' `__ ------------------- Deprecating modules ------------------- The xmllib module was deprecated but not listed in `PEP 4`_. What does one do? Well, this led to a long discussion on how to handle module deprecation. With the 'warning' module now in existence, PEP 4 seemed to be less important. It was generally agreed that listing modules in PEP 4 was no longer needed. It was also agreed that deleting deprecated modules was not needed; it breaks code and disk space is cheap. It seems that no longer listing documentation and adding a deprecation warning is what is needed to properly deprecate a module. By no longer listing documentation new programmers will not use the code since they won't know about it. And adding the warning will let old users know that they should be using something else. .. _PEP 4: http://www.python.org/peps/pep-0004.html Contributing threads: - `Deprecated xmllib module `__ - `Rewriting PEP4 `__ ------------------------------------------ PR to fight the idea that Python is "slow" ------------------------------------------ An article_ in ACM TechNews that covered 2.4 had several mentions that Python was "slow" while justifying the slowness (whether it be flexibility or being fast enough). Guido (rightfully) didn't love all of the "slow" mentions which I am sure we have all heard at some point or another. The suggestions started to pour in on how to combat this. The initial one was to have a native compiler. The thinking was that if we compiled to a native executable that people psychologically would stop the association of Python being interpreted which is supposed to be slow. Some people didn't love this idea since a native compiler is not an easy thing. Others suggested including Pyrex with CPython, but didn't catch on (maintenance issue plus one might say Pyrex is not the most Pythonic solution). This didn't get anywhere in the end beyond the idea of a SIG about the various bundling tools (py2app, py2exe, etc.). The other idea was to just stop worrying about speed and move on stomping out bugs and making Python functionally more useful. With modules in the stdlib being rewritten in C for performance reasons it was suggested we are putting out the perception that performance is important to us. Several other people also suggested that we just not mention speed as a big deal in release notes and such. This also tied into the idea that managers don't worry too much about speed as much as being able to hire a bunch of Python programmers. This led to the suggestion of also emphasizing that Python is very easy to learn and thus is a moot point. There are a good number of Python programmers, though; Stephan Deibel had some rough calculations that put the number at about 750K Python developers worldwide (give or take; rough middle point of two different calculations). .. _article: http://gcn.com/vol1_no1/daily-updates/28026-1.html Contributing threads: - `2.4 news reaches interesting places `__ =============== Skipped Threads =============== - MS VC compiler versions - Any reason why CPPFLAGS not used in compiling? Extension modules now compile with directories specified in the LDFLAGS and CPPFLAGS env vars - adding key argument to min and max min and max now have a 'key' argument like list.sort - Unicode in doctests - SRE bug and notifications - PyInt_FromLong returning NULL - PyOS_InputHook enhancement proposal - The other Py2.4 issue - MinGW And The other Py2.4 issue - Supporting Third Party Modules - Python in education From jurgenex at hotmail.com Tue Jan 18 09:35:57 2005 From: jurgenex at hotmail.com (Jürgen Exner) Date: Tue, 18 Jan 2005 14:35:57 GMT Subject: [perl-python] 20050118 keyed list References: <1106027360.920787.321590@z14g2000cwz.googlegroups.com> Message-ID: Xah Lee wrote: > ? # in perl, keyed-list is done like this: Just FYI: those thingies are called hashes. The legacy name would be associative array. > ? %a = ('john',3, 'mary', 4, 'jane', 5, 'vicky',7); > ? use Data::Dumper qw(Dumper); > ? print Dumper \%a; Wow, my compliments. The very first time that using Data::Dumper actually may do something useful (formats the data more nicely). Still, why you are passing a reference is beyond me. > ? # the syntax of keyed list in Perl is too complex > ? # to be covered in a short message. Excuse me? If (using the same examples as for your Python section) print "Mary is $a{mary}"; delete $a{vicky}; print %a; print keys(%a); exists $a{mary}; is too complex for your to cover, then I strongly suggest you stop posting your "explanations". > ? # see "perldoc perldata" for an unix-styled course. Excuse me? Do you mind explaining where exactly perldata is "Unix-styled"? jue From Mark.English at liffe.com Fri Jan 21 12:41:11 2005 From: Mark.English at liffe.com (Mark English) Date: Fri, 21 Jan 2005 17:41:11 -0000 Subject: Class introspection and dynamically determining function arguments Message-ID: <40E605146701DE428FAF21286A97D309174511@wphexa02.corp.lh.int> Diez B. Roggisch wrote: > According to this > http://www-106.ibm.com/developerworks/library/l-pyint.html > > not really - and there are no special moduls neccessary, as > everything is at your hands using __dict__ and so on. Thanks for the link. I'd read that article but found it was too introductory (what is help, what is sys, etc.). It didn't even deal with inspect. As such, I didn't think it was definitive about Python's existing introspection code. This was much more the level of sophistication I was looking for, albeit aimed at (static) declared function syntax, rather than (dynamic) instance or class attributes: http://www.sff.net/people/neelk/open-source/Signature.py Also, I know the class __dict__ (which is actually a proxy object) may have class attributes currently, but that seems implementation dependent. At the moment it lists the attributes defined by *this* type, regardless of attributes defined in base types. Again, this happens to be what I want but I don't know that this behaviour is defined anywhere, and therefore it may be subject to change. It would be nice if I could ask a class if there are any attributes defined for it in "tp_getset", although that's just a small step along the path of attribute discovery... (Apologies for interchangeable use of the words type/class) Nick Coghlan wrote > Perhaps the simplest way is to require all such classes to have a "getExample" > class method that produces a fully populated example instance Thanks Nick. This was the kind of approach I've ended up going with (sorta). Still hunting for ideas... ----------------------------------------------------------------------- The information contained in this e-mail is confidential and solely for the intended addressee(s). Unauthorised reproduction, disclosure, modification, and/or distribution of this email may be unlawful. If you have received this email in error, please notify the sender immediately and delete it from your system. The views expressed in this message do not necessarily reflect those of LIFFE Holdings Plc or any of its subsidiary companies. ----------------------------------------------------------------------- From asda at sdarta.com Sat Jan 8 10:03:44 2005 From: asda at sdarta.com (worzel) Date: Sat, 8 Jan 2005 23:03:44 +0800 Subject: tuples vs lists References: <41dfd96b$0$29393$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <41dff650$0$29357$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Cheers - thanks for the feedback guys - pretty much answers the question for me. 'Two-Pull' it is then, thanks. "Steve Horsley" wrote in message news:croqtg$qo0$1 at news.freedom2surf.net... > worzel wrote: >> I get what the difference is between a tuple and a list, but why would I >> ever care about the tuple's immuutability? > > Mainly for security and speed. Many library functions return info by > returning > a reference to an internally held tuple, and could be damaged / > compromised > / corrupted if that internal data was modified by malicious code. If > tuples > were mutable (lists) then it would be necessary to return a copy instead. > >> Also, do you say 'too-ple' or 'chu-ple' - if you get my drift. (tomato or >> tomato kind of thing) > > Try 'Two-pull'. > > Steve From benji at zope.com Mon Jan 31 23:19:39 2005 From: benji at zope.com (Benji York) Date: Mon, 31 Jan 2005 23:19:39 -0500 Subject: barchart for webpage needed In-Reply-To: References: Message-ID: <41FF035B.3050900@zope.com> dimitri pater wrote: > I am looking for a Python tool to create graphs and charts on a > webpage. Chartdirector is too expensive for me. A simple script for > creating a barchart should be sufficient as a starting point. If all you want are bar charts, you can get by with simple HTML. Here's one technique: http://www.siteexperts.com/tips/contents/ts13/page1.asp. -- Benji York Sr. Software Engineer Zope Corporation From steve at holdenweb.com Thu Jan 6 09:06:05 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 06 Jan 2005 09:06:05 -0500 Subject: navigating/changing directories In-Reply-To: References: Message-ID: <8FbDd.68968$Jk5.48112@lakeread01> skip wrote: > A simple script like the one below lets me jump through a directory > structure. However, if I run it from /this/directory and within it to go to > /a/totally/different/directory... I'm still actually going to be in > /this/directory when I exit the script. Is it possible to have a script > that can drop me off into a different directory than where I initiated it > from? > > import os > process = 1 > while (process): > # Display directories > for i in os.listdir(os.getcwd()): > if (os.path.isdir(os.path.join(os.getcwd(),i))): > print i > > # Change directory > goto_dir = raw_input(": ") > if (goto_dir in os.listdir(os.getcwd())): > os.chdir(os.path.join(os.getcwd(),goto_dir)) > else: > process = 0 # Exit > > As has already been reported, under Linux a change to the current working directory won't affect the environment of the parent process. You may find that under some Windows command line interpreters that the change to the working directory made by a program persists into the interactive session that triggered the program. One way to achieve your desired goal, of course, is to call your program using a shell expansion sequence (assuming Unix-like shell environments), as in: cd `myprogram.py` and then if your program outputs the path to a directory your shell's current working directory will be chaged as you require. there's-always-a-way-ly y'rs - steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 From aleaxit at yahoo.com Mon Jan 24 04:28:25 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 24 Jan 2005 10:28:25 +0100 Subject: best way to do a series of regexp checks with groups References: <1gqvzm0.htfjsq10h8nruN%aleaxit@yahoo.com> Message-ID: <1gqw1sv.18zhgeqcb46t3N%aleaxit@yahoo.com> Steven Bethard wrote: > I get a bit uneasy from the repeated calls to m.group... If I was going > to build a class around the re, I think I might lean towards something like: > > class ReWithMemory(object): > def search(self, are, aline): > self.mo = re.search(are, aline) > return self.mo > def groups(self, *indices): > return [self.mo.group(i) for i in indices] > > m = ReWithMemory() > > if m.search(r'add (\d+) (\d+)', line): > do_add(*m.groups(1, 2)) > elif m.search(r'mult (\d+) (\d+)', line): > do_mult(*m.groups(1, 2)) > elif m.search(r'help (\w+)', line): > show_help(*m.groups(1)) > > Of course, this is even less general-purpose than yours... I'm not sure what advantage it's supposed to give. Would you have any problems writing, say, somecall(X[1], X[2]) ...? Python normally relies on indexing one thing at a time, and I see calling m.group(1) etc as just the same kind of approach. > (And if I saw myself using this much regex code, I'd probably reconsider > my strategy anyway.) ;) Surely joining all the regexp's into one big one with | would be faster and more compact, but, with variable numbers of groups per sub-regexp, determining which regexp matched can perhaps be tricky (issues with matching mo.lastindex to the correct sub-regexp). So, I can understand the desire to do it sequentially, regexp by regexp. Alex From ncoghlan at iinet.net.au Wed Jan 12 05:32:25 2005 From: ncoghlan at iinet.net.au (Nick Coghlan) Date: Wed, 12 Jan 2005 20:32:25 +1000 Subject: else condition in list comprehension In-Reply-To: <1105302040.286420.313240@c13g2000cwb.googlegroups.com> References: <1105302040.286420.313240@c13g2000cwb.googlegroups.com> Message-ID: <41E4FCB9.4030200@iinet.net.au> Luis M. Gonzalez wrote: > Hi there, > > I'd like to know if there is a way to add and else condition into a > list comprehension. I'm sure that I read somewhere an easy way to do > it, but I forgot it and now I can't find it... > > for example: > z=[i+2 for i in range(10) if i%2==0] > what if I want i to be "i-2" if i%2 is not equal to 0? > Hmm: z = [newval(i) for i in range(10)] using: def newval(x): if x % 2: return x - 2 else: return x + 2 Just some more mental twiddling relating to the thread on statement local namespaces. Cheers, Nick. -- Nick Coghlan | ncoghlan at email.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.skystorm.net From ncoghlan at iinet.net.au Tue Jan 25 09:09:10 2005 From: ncoghlan at iinet.net.au (Nick Coghlan) Date: Wed, 26 Jan 2005 00:09:10 +1000 Subject: Instances of class object not modifiable? In-Reply-To: References: Message-ID: <41F65306.4030008@iinet.net.au> Steven Bethard wrote: > Open Issues > =========== > What should the type be named? Some suggestions include 'Bunch', > 'Record' and 'Struct'. Add 'namespace' to the list of name suggestions :) Cheers, Nick. The name came up in some thread a few weeks back. . . -- Nick Coghlan | ncoghlan at email.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.skystorm.net From chris.peressotti at utoronto.ca Fri Jan 28 11:13:45 2005 From: chris.peressotti at utoronto.ca (Chris P.) Date: 28 Jan 2005 08:13:45 -0800 Subject: PythonWin (build 203) for Python 2.3 causes Windows 2000 to grind to a halt? References: <3f233389.0501271147.43572416@posting.google.com> <41f9e4a9$1_1@127.0.0.1> Message-ID: <3f233389.0501280813.6be97b74@posting.google.com> AWESOME - my life just got THAT much better. The bug you suggested is exactly the problem that I was having... I had looked through the bugs being tracked, but the title of that one didn't jump out at me as something that would help. Thanks! - Chris P.S. For anyone reading this group who wants to know exactly what I did: 1) Uninstall Pywin32 2) Open the registry editor ('regedit' at the command prompt) 3) Go to HKEY_CURRENT_USER\Software\Python[version]\Python for Win32 You will likely find many many many keys that have the format "ToolbarDefault-Bar#". These keys filling up your registry cause Windows 2000 to become extremely slow/unstable when Python is running (especially if your debugger is running.) 4) Delete the keys... I just deleted it at the "Python[version]" root 5) Reinstall Pywin32 "Roger Upole" wrote in message news:<41f9e4a9$1_1 at 127.0.0.1>... > These look like symptoms of sf bug #1017504 > http://sourceforge.net/tracker/index.php?func=detail&aid=1017504&group_id=78018&atid=551954 > > What version of Pywin32 are you running ? > There's a (semi) fix for this in the latest build. > hth > Roger From aurora00 at gmail.com Mon Jan 31 19:07:41 2005 From: aurora00 at gmail.com (aurora) Date: Mon, 31 Jan 2005 16:07:41 -0800 Subject: Go visit Xah Lee's home page Message-ID: Let's stop discussing about the perl-python non-sense. It is so boring. For a break, just visit Mr Xah Lee's personal page (http://xahlee.org/PageTwo_dir/Personal_dir/xah.html). You'll find lot of funny information and quotes from this queer personality. Thankfully no perl-python stuff there. Don't miss Mr. Xah Lee's recent pictures at http://xahlee.org/PageTwo_dir/Personal_dir/mi_pixra.html My favor is the last picture. Long haired Xah Lee sitting contemplatively in the living room. The caption says "my beautiful hair, fails to resolve the problems of humanity. And, it is falling apart by age." From storchaka at ksf.kiev.ua Tue Jan 11 13:14:01 2005 From: storchaka at ksf.kiev.ua (Serhiy Storchaka1659322541) Date: Tue, 11 Jan 2005 20:14:01 +0200 Subject: else condition in list comprehension In-Reply-To: References: <1105302040.286420.313240@c13g2000cwb.googlegroups.com> <1105305000.052714.188980@c13g2000cwb.googlegroups.com> Message-ID: Nick Coghlan wrote: > Dan Bishop wrote: > >> Luis M. Gonzalez wrote: >> >>> Hi there, >>> >>> I'd like to know if there is a way to add and else condition into a >>> list comprehension. I'm sure that I read somewhere an easy way to do >>> it, but I forgot it and now I can't find it... >>> >>> for example: >>> z=[i+2 for i in range(10) if i%2==0] >>> what if I want i [sic] to be "i-2" if i%2 is not equal to 0? >> >> >> >> z = [i + (2, -2)[i % 2] for i in range(10)] > > > For the specific case of +/- a number, (-1) ** x works, too: > > z = [i + 2 * ((-1) ** i) for i in range(10)] > > Not that I'm claiming it's particularly readable or anything. . . just > that it works :) Yet another variant: z = [i + ( (i % 2) and -2 or 2 ) for i in range(10)] -- Serhiy Storchaka From tim.peters at gmail.com Wed Jan 26 20:59:11 2005 From: tim.peters at gmail.com (Tim Peters) Date: Wed, 26 Jan 2005 20:59:11 -0500 Subject: python memory blow out In-Reply-To: <3e8ca5c8050126174444967112@mail.gmail.com> References: <4e4a11f805012617082ebd9b80@mail.gmail.com> <3e8ca5c8050126174444967112@mail.gmail.com> Message-ID: <1f7befae050126175916958afd@mail.gmail.com> [Simon Wittber] >> According to the above post: >> a) If the allocation is > 256 bytes, call the system malloc. >> b) If the allocation is < 256, use its own malloc implementation, which >> allocates memory in 256 kB chunks and never releases it. >> >> I imagine this means that large memory allocations are eventually >> released back to the operating system. However, in my case, this >> appears to be not happening. Large chunks are returned to the platform C when they become unreferenced. More below. [Stephen Thorne] > There was a recent patch posted to python-dev list which allows python > to release memory back to the operating system once the 256kb chunk is > no longer used. Nope, the patch may return such a 256KB chunk to the platform C library's free() function. That's never what someone actually means by the vague "released back to the operating system", and whether the latter might happen is another platform-dependent (OS + C library + specific versions of each) can of worms. > I'm not saying running a bleeding edge CVS HEAD python plus untested > development patches is going to be a solution for you in the short > term, but I just wanted to mention it because I'm excited about this > limitation disappearing in python :). It's a necessary first step, anyway. Alas, there's no way to take a second step without messy platform-specific code (when does your favorite platform C free() "release memory back" to your favorite operating system? to "do something about that", exact knowledge of platform details is necessary). From removethis.kartic.krishnamurthy at gmail.com Sun Jan 30 20:28:59 2005 From: removethis.kartic.krishnamurthy at gmail.com (Kartic) Date: Mon, 31 Jan 2005 01:28:59 GMT Subject: Problem with loading textfiles into dictionaries. In-Reply-To: References: <1107132206.446722.21720@f14g2000cwb.googlegroups.com> Message-ID: Kartic said the following on 1/30/2005 8:21 PM: > mercuryprey at gmail.com said the following on 1/30/2005 7:43 PM: > Hi - It looks like your code encountered a blank line when you got this > error. > > You should move "if len(siteline) == 0" part right after your readline. > The way you have done it really does not help. > > def do_load(self, arg): > sitefile = file('sitelist', 'r+', 1) > while True: > siteline = sitefile.readline() > if len(siteline) == 0: > break > site_rawlist = siteline.split() > sitelist[site_rawlist[0]] = site_rawlist[1:] Sorry...siteline = sitefile.readline().strip() From jgrahn-nntq at algonet.se Mon Jan 24 16:51:35 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 24 Jan 2005 21:51:35 GMT Subject: how to ncurses on win32 platform References: <3nkds3kzc9mp.18yfed1y3vo9d$.dlg@40tude.net> Message-ID: On Mon, 24 Jan 2005 20:26:28 +0000 (UTC), Alan Gauld wrote: > On Mon, 24 Jan 2005 17:06:52 +0100, Brane wrote: >> please advice > > You can use ncurses via cygwin. > There are DOS ports too but I couldn't get any of them to > work on my XP box, YMMV... Or, as Alex Martelli wrote in "Python in a nutshell": "The curses package works only on Unix-like platforms (there are persis- tent rumors of Windows ports of it, but I've never found a working one)." /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From tom at livelogix.com Wed Jan 26 01:01:57 2005 From: tom at livelogix.com (Tom) Date: 25 Jan 2005 22:01:57 -0800 Subject: Python with no significant whitespace In-Reply-To: References: <35oh4gF4nvvfoU1@individual.net> Message-ID: <1106719317.609935.38430@f14g2000cwb.googlegroups.com> Just though I'd point out that Logix *does* use whitespace for delimiting blocks. Or rather, it can use whitespace, and the languages that come as standard do. With Logix you could quite easily make a version of Python with, e.g., braces instead of whitespace for delimiting blocks. That's probably what the Stephen was getting at. Tom. From martin at v.loewis.de Sun Jan 23 18:15:29 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 24 Jan 2005 00:15:29 +0100 Subject: rotor replacement In-Reply-To: <7xllalljah.fsf@ruckus.brouhaha.com> References: <7x1xcidnp1.fsf@ruckus.brouhaha.com> <41EE24F7.7030303@jessikat.fsnet.co.uk> <7x1xchlpqv.fsf@ruckus.brouhaha.com> <41efeb82$0$27807$9b622d9e@news.freenet.de> <41f1a70b$0$25959$9b622d9e@news.freenet.de> <7xbrbiqdhk.fsf@ruckus.brouhaha.com> <7xllalljah.fsf@ruckus.brouhaha.com> Message-ID: <41F43011.8020303@v.loewis.de> Paul Rubin wrote: > There's tons of such examples, but python-dev apparently reached > consensus that the Python maintainers were less willing than the > maintainers of those other packages to deal with those issues. As Andrew says, it is not apparent that there was consensus. > Martin, do you know more about this? I'm pretty certain that we (the PSF) sent a message to BXA, reporting the rotor module. While I can't find out exactly when this happened right now, the board meeting on 2002-04-09 decided that this should happen, see http://python.org/psf/records/board/minutes-2002-04-09.html Regards, Martin From elephantum at dezcom.mephi.ru Thu Jan 13 14:41:54 2005 From: elephantum at dezcom.mephi.ru (Andrey Tatarinov) Date: Thu, 13 Jan 2005 22:41:54 +0300 Subject: Statement local namespaces summary (was Re: python3: 'where' keyword) In-Reply-To: References: <3480qqF46jprlU1@individual.net> <41DF78EB.6040502@iinet.net.au> <41dfc018.305122743@news.oz.net> <34cieoF489ejfU1@individual.net> <41E12700.8000106@iinet.net.au> Message-ID: <34o183F4b3in3U1@individual.net> Nick Coghlan wrote: > Nick Coghlan wrote: > >> Semantics >> --------- >> The code:: >> >> with: >> >> >> translates to:: >> >> def unique_name(): >> >> >> unique_name() > I've come to the conclusion that these semantics aren't what I would > expect from the construct. Exactly what I would expect can't really be > expressed in current Python due to the way local name bindings work. The > main thing to consider is what one would expect the following to print: > > def f(): > a = 1 > b = 2 > print 1, locals() > print 3, locals() using: > a = 2 > c = 3 > print 2, locals() > print 4, locals() > > I think the least suprising result would be: > > 1 {'a': 1, 'b': 2} # Outer scope > 2 {'a': 2, 'c': 3} # Inner scope > 3 {'a': 2, 'b': 2, 'c': 3} # Bridging scope > 4 {'a': 1, 'b': 2} # Outer scope as for me, I would expect following: 1 {'a': 1, 'b': 2} 2 {'a': 2, 'b': 2, 'c': 3'} 3 {'a': 2, 'b': 2, 'c': 3'} 4 {'a': 1, 'b': 2} otherwise that would be impossible to do calculations based on scope variables and "using:" would be useless =), consider example of usage: current_position = 1 current_environment # = ... current_a_lot_of_other_parameters # = ... scores = [count_score(move) for move in aviable_moves] using: def count_score(move): #walking through current_environment return score From kosh at aesaeion.com Tue Jan 11 21:23:46 2005 From: kosh at aesaeion.com (kosh) Date: Tue, 11 Jan 2005 19:23:46 -0700 Subject: Python.org, Website of Satan In-Reply-To: <1105495569.479185.166340@z14g2000cwz.googlegroups.com> References: <1105495569.479185.166340@z14g2000cwz.googlegroups.com> Message-ID: <200501111923.46511.kosh@aesaeion.com> On Tuesday 11 January 2005 7:06 pm, humblythegreatest at usa.com wrote: > python.org = 194.109.137.226 > > 194 + 109 + 137 + 226 = 666 > > What is this website with such a demonic name and IP address? What > evils are the programmers who use this language up to? Geeze did you miss out on the demon summoning rituals last week? Wow that was a great thing you missed out on. I am sorry I can't tell you about the future events though. Only great wizards are allowed to come and they all know when the events are. :) From rbt at athop1.ath.vt.edu Mon Jan 17 10:30:38 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Mon, 17 Jan 2005 10:30:38 -0500 Subject: Install Python 2.4 on Fedora 3 Core In-Reply-To: <1105975262.047782.6010@z14g2000cwz.googlegroups.com> References: <1105975262.047782.6010@z14g2000cwz.googlegroups.com> Message-ID: Bill wrote: > I have less than a week experience on linux, so I am a new newbie. > Python 2.3 came preinstalled. I installed version 2.4. All seemed to > go well except it installed to usr/local? > > 1. Was it wrong to install when logged in as 'root'? Does it make a > difference? > > 2. I looked in the package editor and there was no way to uninstall > 2.3? Should I? If so, how can I? If not,what are the problems, if > any, of having both. > > Thank you for your help. > Bill, /usr/local is the path on Unix systems where add-on software is traditionally installed. RH used to use Python heavily for many aspects of their RHL distribution. I suspect they still do this with Fedora. This is probably why the version of Python that came with Fedore cannot be removed (at least not easily). It's OK to have the RH version and the latest Python.org version installed. You'll just have to specify the path to the version you wish to use when running your scripts like this: /usr/local/python There are some more advanced things you could do and I suspect others will give you better advice. But all in all, you're OK. Have fun. From alan.gauld at btinternet.com Thu Jan 6 17:36:00 2005 From: alan.gauld at btinternet.com (Alan Gauld) Date: Thu, 6 Jan 2005 22:36:00 +0000 (UTC) Subject: Securing a future for anonymous functions in Python References: Message-ID: On Thu, 30 Dec 2004 23:28:46 +1000, Nick Coghlan wrote: > GvR has commented that he want to get rid of the lambda keyword for Python 3.0. > Getting rid of lambda seems like a worthy goal, Can I ask what the objection to lambda is? 1) Is it the syntax? 2) Is it the limitation to a single expression? 3) Is it the word itself? I can sympathise with 1 and 2 but the 3rd seems strange since a lambda is a well defined name for an anonymous function used in several programming languages and originating in lambda calculus in math. Lambda therefore seems like a pefectly good name to choose. So why not retain the name lambda but extend or change the syntax to make it more capable rather than invent a wholly new syntax for lambdas? Slightly confused, but since I only have time to read these groups regularly when I'm at home I have probably missed the bulk of the discussion over the years. Alan G. Author of the Learn to Program website http://www.freenetpages.co.uk/hp/alan.gauld From deetsNOSPAM at web.de Fri Jan 28 08:15:36 2005 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Fri, 28 Jan 2005 14:15:36 +0100 Subject: Proccess termination References: <1106917700.730538.80320@f14g2000cwb.googlegroups.com> Message-ID: <35us3lF4rqg1oU1@individual.net> alexrait1 wrote: > I use popen.popen2 or popen.popen3 to start a new process and read from > it's stdout/ write to it's stdin. > But I need a way to know when a process terminates. If it closes it's > stdin/stdout, it doesn't mean it has really terminated... You can use the Popen-objects pid to see if a process still runs. > And if possible, I would like to see an exception thrown when that > happens.. Not possible - that exception would be asynchronous to your program flow. The only thing I can think of that would make this possible is to have a second thread waiting for process termination - and sending the own process a signal. If I'm not mistaken, that will be propagated to the main thread. All this is meant to be running on unix - not sure how thinks work out on windows. -- Regards, Diez B. Roggisch From bulba at bulba.com Sat Jan 8 23:01:58 2005 From: bulba at bulba.com (Bulba!) Date: Sun, 09 Jan 2005 05:01:58 +0100 Subject: The Industry choice References: <7xhdluxh4i.fsf@ruckus.brouhaha.com> Message-ID: On 6 Jan 2005 20:07:19 -0500, aahz at pythoncraft.com (Aahz) wrote: >>Nope. That is not what I'm arguing. Really, I think you have >>jumped to conclusion about that: I merely pointed out that >>I don't like what I perceive as end effect of what GPL license >>writers are attempting to achieve: vendor lock-in. >> >>I think I stated that clearly. > >And my counter-argument is that I believe your perception is wrong. If >I agreed with your focus on lock-in, I'd say that what the GPL is trying >to lock in is a specific legal philosophy by subverting the existing >system. If it finally turns out that I'm wrong on this and GPL does not have that kind of economic "vendor lock-in" _effect_ behind it (note: effect, not intent), I will be only happy to see that. Re subverting existing legal philosophy, I could not care less. Obviously the only reason that I argued that way is that given the info that I have it simply looks like that from my viewpoint. -- It's a man's life in a Python Programming Association. From donn at drizzle.com Sun Jan 2 01:26:39 2005 From: donn at drizzle.com (Donn Cave) Date: 2 Jan 2005 00:26:39 -0600 Subject: The Industry choice References: <1104425916.615972.97530@z14g2000cwz.googlegroups.com> <7xd5wqd14y.fsf@ruckus.brouhaha.com> <7xacrs230c.fsf@ruckus.brouhaha.com> <1104620491.542938.92100@z14g2000cwz.googlegroups.com> <7xsm5kfyse.fsf@ruckus.brouhaha.com> Message-ID: <41d7941f$1_3@127.0.0.1> Quoth Paul Rubin : | beliavsky at aol.com writes: |> Overall I agree with you and would like to have OPTIONAL static type |> declarations in Python, as has often been discussed. But without |> facilities for generic programming, such as templates in C++, static |> type declarations can force one to duplicate a LOT of code, with one |> sorting routine each for integer, floats, strings, etc. | | I don't see that big a problem. The current Python sorting routine | operates on instances of class "object" and calls the __cmp__ method | to do comparisons. Every class of sortable objects either defines a | __cmp__ method or inherits one from some superclass, and sort calls | those methods. Static type declarations would not require writing any | additional sorting routines. Yes, it would be really weird if Python went that way, and the sort of idle speculations we were reading recently from Guido sure sounded like he knows better. But it's not like there aren't some interesting issues farther on downstream there, in the compare function. cmp(), and str() and so forth, play a really big role in Python's dynamically typed polymorphism. It seems to me they are kind of at odds with static type analysis, especially if you want type inference -- kind of a type laundering system, where you can't tell what was supposed to be there by looking at the code. Some alternatives would be needed, I suppose. Donn Cave, donn at drizzle.com From jzgoda at gazeta.usun.pl Fri Jan 14 15:27:01 2005 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Fri, 14 Jan 2005 21:27:01 +0100 Subject: python to mssql In-Reply-To: <1lmwxbtst8x8x$.10hwcoinem3cs.dlg@40tude.net> References: <1lmwxbtst8x8x$.10hwcoinem3cs.dlg@40tude.net> Message-ID: Brane wrote: > can someone please give me some info regarding subject From Windows machine: http://adodbapi.sourceforge.net/ From elsewhere: FreeTDS + unixODBC + mxODBC is one of possible solutions. -- Jarek Zgoda http://jpa.berlios.de/ | http://www.zgodowie.org/ From ysharma at catprosystems.com Thu Jan 13 18:09:07 2005 From: ysharma at catprosystems.com (Yogesh Sharma) Date: Thu, 13 Jan 2005 15:09:07 -0800 Subject: Embedding Multiplr Python interpreter in C++ In-Reply-To: References: Message-ID: <41E6FF93.9060406@catprosystems.com> one more question to add: Is there a way to have 2 local copies of python interpreter ? Yogesh Sharma wrote: > Hi, > > I have following setup: > OS Linux Fedora Core 3 > Python 2.3.4 > > How can I embed two python interpreters in one C++ program ? > > Thanks From peter at engcorp.com Thu Jan 13 18:15:21 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 13 Jan 2005 18:15:21 -0500 Subject: newbie ?s In-Reply-To: <1105656971.768148@sj-nntpcache-5> References: <1105656971.768148@sj-nntpcache-5> Message-ID: Venkat B wrote: > Hi folks, > > I'm looking build a CGI-capable SSL-enabled web-server around Python 2.4 on > Linux. > It is to handle ~25 hits possibly arriving "at once". Content is non-static > and built by the execution of py cgi-scripts talking to a few backend > processes. Twisted? I'm not sure what, if anything, it has in the way of CGI support, but that could probably be hacked on pretty darn quick if you needed. At least Twisted has support for server-side SSL (i.e. it can deal with certificates). -Peter From rkern at ucsd.edu Sun Jan 9 11:46:22 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sun, 09 Jan 2005 08:46:22 -0800 Subject: Python3: on removing map, reduce, filter In-Reply-To: <34d3c9F477m01U1@individual.net> References: <34csn1F4a46hqU1@individual.net> <5CcEd.70344$Jk5.19962@lakeread01> <34d3c9F477m01U1@individual.net> Message-ID: Andrey Tatarinov wrote: > Steve Holden wrote: > >> Andrey Tatarinov wrote: >> >>> Hi. >>> >>> How does GvR suggestions on removing map(), reduce(), filter() >>> correlate with the following that he wrote himself (afaik): >>> >>> http://www.python.org/doc/essays/list2str.html > > > > >> And note that the summary in the conclusiogn BEGINS with "Rule number >> one: only optimize when there is a proven speed bottleneck", which >> seems to adequately imply that straightforward code is to be preferred >> unless speed requirements override that. > > > My main question was: "how could be this advices applied, when map, > reduce and filter would be removed?" Since Python 3.0 is currently mythical and will involve a complete rewrite of the language and interpreter, I don't think that you should expect any optimization advice to carry over. -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From fredrik at pythonware.com Sat Jan 15 04:31:37 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 15 Jan 2005 10:31:37 +0100 Subject: How to del item of a list in loop? References: Message-ID: "skull" wrote: > Hi everybody, it is my first post in this newsgroup. > I am a newbie for python though I have several years development experience in c++. > recently, I was stumped when I tried to del item of a list when iteration. > > here is the wrong way I did: > > lst = [1, 2, 3] > for i in lst: > print i > if i == 2: > lst.remove(i) > > the result is: > > 1 > 2 >>>> > > as you would see, '3' is missing. this problem is caused by 'lst.remove(i)'. the internal loop counter is incremented whether you remove stuff or not, so when you're moving things around by removing items in the middle, the loop will skip over items. this is basic for-in usage, and any decent tutorial should explain this. to fix this, you can build a new output list, loop backwards, or loop over a copy. the last is easiest to implement: lst = [1, 2, 3] for i in lst[:]: print i if i == 2: lst.remove(i) but the others may have advantages in certain use cases. if you want more details, see the language reference: http://docs.python.org/ref/for.html (note the warning) From aurora00 at gmail.com Fri Jan 28 11:25:29 2005 From: aurora00 at gmail.com (aurora) Date: Fri, 28 Jan 2005 08:25:29 -0800 Subject: Transparent (redirecting) proxy with BaseHTTPServer References: <35sfdaF4hka1hU1@individual.net> <35t9huF4rt829U1@individual.net> Message-ID: It should be very safe to count on the host header. Maybe some really really old browser would not support that. But they probably won't work in today's WWW anyway. Majority of today's web site is likely to be virtually hosted. One Apache maybe hosting for 50 web addresses. If a client strip the host name and not sending the host header either the web server wouldn't what address it is really looking for. If you caught some request that doesn't have host header it is a good idea to redirect them to a browser upgrade page. > > Thanks, aurora ;), > > aurora wrote: >> If you actually want the IP, resolve the host header would give you >> that. > I' m only interested in the hostname. > >> The second form of HTTP request without the host part is for >> compatability of pre-HTTP/1.1 standard. All modern web browser should >> send the Host header. > How safe is the assumtion that the Host header will be there? Is it part > of the HTTP/1.1 spec? And does it mean all "pre 1.1" clients will fail? > Hmm, maybe I should look on the wire whats really happening... > > thanks again > Paul From cdieterich at geosci.uchicago.edu Thu Jan 27 21:02:53 2005 From: cdieterich at geosci.uchicago.edu (Christian Dieterich) Date: Thu, 27 Jan 2005 20:02:53 -0600 Subject: inherit without calling parent class constructor? In-Reply-To: <10vj4ovqee29oc9@corp.supernews.com> Message-ID: On D?ardaoin, Ean 27, 2005, at 19:25 America/Chicago, Jeff Shannon wrote: > Okay, so size (and the B object) is effectively a class attribute, > rather than an instance attribute. You can do this explicitly -- Ah, now I'm getting there. That does the trick. > Probably not worth the trouble in this particular case, but maybe in > another case... :) Yeah, maybe not. But I'll remember it as a useful recipe. Cheers, Christian From peter at engcorp.com Thu Jan 6 10:36:28 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 06 Jan 2005 10:36:28 -0500 Subject: OT: spacing of code in Google Groups In-Reply-To: References: <1104516184.077462.283350@c13g2000cwb.googlegroups.com> <1104528447.005870.6530@z14g2000cwz.googlegroups.com> <41d5c606$0$26890$a1866201@visi.com> Message-ID: <5amdnbMsyqlhx0DcRVn-vw@powergate.ca> Jacek Generowicz wrote: > Peter Hansen writes: >>Why the heck would I ever have to do "rectangle operations" on a >>regular basis? ;-) > > Well, given that all editors are cat equivalent[*], you don't _have_ > to use any of their features :-) This "cat equivalent" thing is a red-herring. I can rarely type more than a line of code without making a typographical error. Sometimes I won't catch that error until a bit later. Using "cat" alone would provide me little opportunity to fix the error, so I would never be able to produce a working program longer than a few lines. You might call this simply "less productive" (though I'd argue it becomes a qualitative difference). But, okay, let's work from there... > But just like Python (particularly in the hands of a skilled Python > programmer) is more productive than a Turing Machine, any featureful > editor (in the hands of an experienced user) is far more productive > than "cat > file". I don't disagree. I do, however, claim that the set of features that are required to make *me* orders of magnitude more productive than "cat" (to use your quantitative comparison) is very, very small. And that I use less than 2% of the features most editors have. And that if a programmer with equal abilities managed to learn to use 98% of the features of such an editor, such that he could readily use whichever such feature was most effective at any given time, he would not be more than 10% more effective than I am. But the whole argument is fairly moot... I've needed a rectangle operation only once in the last ten years, and if I hadn't known at the time that my editor could do it (and spent about half an hour figuring out how it worked), I could have written a utility to do the job faster if I'd been using Python at the time... Cheers, -Peter From martin at v.loewis.de Mon Jan 31 18:20:01 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 01 Feb 2005 00:20:01 +0100 Subject: serializing data structures In-Reply-To: References: Message-ID: <41FEBD21.5030306@v.loewis.de> Philippe C. Martin wrote: > I once wrote something in C to do that, but since python usually has a > solution for me .... If you use arbitrary data structures, you could use pickle or xmlrpclib to marshal the data. If you know the data is restricted to a few well-known data types, you could use XDR (Demo/rpc/xdr.py) or CORBA (e.g. through fnorb.sf.net) to come up with a wire format. Otherwise, if you want to define your own proprietary data format, you can probably use the struct module to generate messages according to this format. However, in any case, you need to define the wire format. Once you made a choice, Python can help implement it - but Python cannot chose a wire format for you (although pickle comes really close, as does Dopy - http://www.mindhog.net/~mmuller/projects/dopy/) Regards, Martin From http Sun Jan 9 00:40:40 2005 From: http (Paul Rubin) Date: 08 Jan 2005 21:40:40 -0800 Subject: python3: 'where' keyword References: <3480qqF46jprlU1@individual.net> <1105228549.608275.148740@c13g2000cwb.googlegroups.com> <7xk6qnzd3d.fsf@ruckus.brouhaha.com> <1105230350.861683.265970@c13g2000cwb.googlegroups.com> <7x3bxbe97m.fsf@ruckus.brouhaha.com> Message-ID: <7xsm5b2m93.fsf@ruckus.brouhaha.com> Nick Coghlan writes: > I think having to keep the names unique within the statement you are > currently writing is a reasonable request :) Um, you could say the same thing about the function, the module, etc. ;) From sjmachin at lexicon.net Fri Jan 21 23:34:08 2005 From: sjmachin at lexicon.net (John Machin) Date: 21 Jan 2005 20:34:08 -0800 Subject: why am I getting a segmentation fault? References: <1106330476.419418.46920@f14g2000cwb.googlegroups.com> <1106351339.457714.214940@f14g2000cwb.googlegroups.com> <1106356789.748649.259090@f14g2000cwb.googlegroups.com> Message-ID: <1106368448.725365.37030@f14g2000cwb.googlegroups.com> Jay donnell wrote: > >### Have you looked in your database to see if the >script has > actually > >updated item.goodImage? Do you have a test plan? > > Thank you for the help. Sorry for the messy code. I was under time > constraints. I had class, and I was rushing to get this working before > class. I should waited a day and read over it before I asked. Sorry > again. Apologise to _yourself_ for the messy code. If 'query' had been safely tucked away as a local variable instead of a global, that problem (typing 'query' instead of 'self.q') would have caused an exception on the first time around. A few points: Yes, don't rush. I've-forgotten-whom wrote something like "Don't program standing up". Good advice. Build things a piece at a time. Build your tests at the same time or earlier. In this case, a stand-alone method or function that checked that one file was OK, would have been a reasonable place to start. Then add the code to query the db. Then add the threading stuff, gingerly. If you build and test incrementally, then a segfault or other disaster is highly likely to have been caused by the latest addition. AND SOME MORE CRUFT: def __init__(self, url, filename, id): self.t = time.time() <<<<<<<<<======= never used again threading.Thread.__init__(self) self.db = MySQLdb.connect(host="localhost", user="xxx", passwd="xxx", db="xxx") # create a cursor self.cursor = db.cursor() <<<=== should be self.db.cursor() #### picks up the *GLOBAL* 'db' self.url = url self.filename = filename self.id = id =========================== threadList = [] [snip] threadList.append(imageChecker) ===>>>> that doesn't achieve much! ============================ N.B. You still have two problems: (1) Your script as you said now "seems to work". That doesn't sound like you have a test plan. (2) You have shuffled your code around and the segfault went away; i.e. you waved a dead chicken and the volcano stopped erupting. Most of the changes suggested by others and myself were of a style/clarity nature. The self.q/query thing would have caused a select instead an update; hardly segfault territory. I wouldn't expect that busy-wait loop to cause a segfault. You still don't know what caused the segfault. That means you don't know how to avoid it in the future. You are still living in the shadow of the volcano. Will the chicken trick work next time? Looking forward to the next episode, John From jfine at pytex.org Fri Jan 7 16:57:48 2005 From: jfine at pytex.org (Jonathan Fine) Date: Fri, 07 Jan 2005 21:57:48 +0000 Subject: What could 'f(this:that=other):' mean? References: <41DC52CA.5070104@pytex.org> <10toomjdjcs5v21@corp.supernews.com> <41DCE28B.70806@pytex.org> <10tr8eo5skqo2a3@corp.supernews.com> Message-ID: <41DF05DC.9060004@pytex.org> Jeff Shannon wrote: > Jonathan Fine wrote: > The use of *args and **kwargs allows functions to take a variable number > of arguments. The addition of ***nsargs does not add significantly. I've posted usage examples elsewhere in this thread. I think they show that ***nsargs do provide a benefit. At least in these cases. How significant is another matter. And how often do they occur. > Now, though, we've lost the ability to specify *only* the argname and > not the namespace as well -- that is, you *cannot* call f4 with keywords > but not namespaces. From the caller's vantage point, this means that > they need to know the full namespace spec of the function, which makes > it no different than simply using longer (but unique) keyword names. This is a major point. From the caller's point of view: fn_1(x_aa=1, x_bb=2, y_aa=3) fn_2(x:aa=1, x:bb=2, y:aa=3) are very similar. Replace '_' by ':'. So you are saying, I think, 'what does this buy the caller'. Well, by using ':' the namespacing is explicit. fn_3(my_path, my_file, any_file) Is this an example of implicit namespacing? (Rhetorical question.) Explicit is better than implicit, I'm told (smile). > So, we can see that allowing namespaces and ***nsargs doesn't add any > utility from the caller's perspective. How much does the callee gain > from it? > > Well, the following functions would be equivalent: > > def g1(arg1, arg2, arg3, arg4): > ns1 = {'arg1':arg1, 'arg2':arg2, 'arg3':arg3, 'arg4':arg4} > return ns1 > def g2(ns1:arg1, ns1:arg2, ns1:arg3, ns1:arg4): > return ns1 > > You might say "Wow, look at all that repetetive typing I'm saving!" But > that *only* applies if you need to stuff all of your arguments into > dictionaries. This is a key point. But there's more to it. Namespace arguments are good if you have to divide the arguments into two or more dictionaries. Based on the namespace prefix. > I suspect that this is a rather small subset of > functions. In most cases, it will be more convenient to use your > arguments as local variables than as dictionary entries. This is a matter of usage. If the usage is very, very small, then what's the point. If the usage is very, very large, then the case is very strong. > def gcd1(a, b): > while a: > a, b = b%a, a > return b > > def gcd2(ns1:a, ns1:b): > while ns1['a']: > ns1['a'], ns1['b'] = ns1['b']%ns1['a'], ns1['a'] > return ns1['b'] > > Speaking of repetetive typing.... :P > > Besides, another function equivalent to the above two would be: > > def g3(arg1, arg2, arg3, arg4): > ns1 = locals() > return ns1 > > ....which is quite a bit less repetetive typing than the 'namespace' > version. These are not good examples for the use of namespacing. And the results are horrible. So this is an argument _in favour_ of namespacing. Namely, that it _passes_ "there should be one (and preferably only one) obvious way to do things" test (quoted from your earlier message). > So, you're looking at making the function-calling protocol significantly > more complex, both for caller and callee, for the rather marginal gain > of being able to get arguments prepackaged in a dictionary or two, when > there already exist easy ways of packaging function arguments into a > dict. Given the deliberate bias against adding lots of new features to > Python, one needs a *much* better cost/benefit ratio for a feature to be > considered worthwhile. I believe that we _agree_, that it is a matter of cost/benefit ratio. My opinion is that studying usage examples is a good way of evaluating this ratio. Which is why I have posted some favourable usage examples. > I'd note also that the usage you're drawing from, in XML/XSLT, isn't > really comparable to function parameters. It's a much closer parallel > to object attributes. Python *does* have this concept, but it's spelled > differently, using a '.' instead of a ':'. In other words, the XML > fragment you give, > > > > .... would be more appropriate to render in Python as > > e = Element() > e.this.that = 'other' > > It's quite reasonable to suppose that some object of type Element may > have a set of font attributes and a set of image attributes, and that > some of these may have the same name. Python would use font objects and > image objects instead of 'namespaces' -- > > e.font.size = '14pt' > e.image.size = (640, 480) > > So while these namespaces are probably a great thing for XML, XSLT, > they're not very useful in Python. Which, given the rather different > goals and design philosophies behind the languages, shouldn't really be > much of a surprise. It may be better, in some cases, to write fp = FontParams() fp.size = 14 fp.slope = 0.1 f(this=this, font_params=fp) But not, I think, if the definition of f is something like: def f(this, font_params): fpd = font_params.__dict__ font_function(**fpd) (Assuming that font_function has got it right.) Prompted by your post, the idea of writing f(this.that='other') instead of f(this:that='other') came to my mind. At first I did not like it, but now it is growing on me a little. However, that is a syntactic issue. Which falls if the costs do not justify the benefits. And here, I think, the key question is this: How often do you have to divide the arguments to a function into two or more dictionaries? Which can be answered by studying usage. -- Jonathan http://www.pytex.org From ncoghlan at iinet.net.au Tue Jan 25 09:56:39 2005 From: ncoghlan at iinet.net.au (Nick Coghlan) Date: Wed, 26 Jan 2005 00:56:39 +1000 Subject: Memory Usage In-Reply-To: References: Message-ID: <41F65E27.5010108@iinet.net.au> Stuart McGarrity wrote: > Do you have a page file? > > The Mem column should be RAM usage and not total working set. Some of it > could be swapped to the page file. A free tool like process explorer can > give you better informaton than the task manager. As Tim pointed out, "View->Select Columns" and activating "VM Size" is enough to find out how much memory that program actually has *mapped* (rather than currently loaded into RAM). Cheers, Nick. -- Nick Coghlan | ncoghlan at email.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.skystorm.net From saint_infidel at hotmail.com Thu Jan 20 11:59:57 2005 From: saint_infidel at hotmail.com (infidel) Date: 20 Jan 2005 08:59:57 -0800 Subject: delay and force in Python In-Reply-To: <1106164457.982053.214970@f14g2000cwb.googlegroups.com> References: <1106133430.957592.62750@f14g2000cwb.googlegroups.com> <1106164457.982053.214970@f14g2000cwb.googlegroups.com> Message-ID: <1106240397.513679.107680@z14g2000cwz.googlegroups.com> Of course I meant to put a break out of the loop after the print statement. Duh on me. From steve at holdenweb.com Fri Jan 7 07:23:23 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 07 Jan 2005 07:23:23 -0500 Subject: Securing a future for anonymous functions in Python In-Reply-To: <7xis6930ah.fsf@ruckus.brouhaha.com> References: <1105098890.358721.279550@f14g2000cwb.googlegroups.com> <7xis6930ah.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > "Anna" writes: > >>Having taken some calculus (derivatives, limits, some integrals) but >>never even heard of lambda calculus, to me, lambda means absolutely >>NOTHING. Less than nothing. > > > Lambda calculus is from mathematical logic, but more to the point > "lambda" has been the term used in Lisp for this operation since time > immemorial. Since the kinds of programmers who want to use anonymous > functions have probably been exposed to Lisp at one time or another, > "lambda" should not cause any confusion. That's probably not the most enthusiastic evangelical approach to functional programming I've ever heard :-) Perhaps what we really need is a good Lisp subsystem for Python? regards Steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 From duncan.booth at invalid.invalid Fri Jan 28 07:50:10 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 28 Jan 2005 12:50:10 GMT Subject: Who should security issues be reported to? References: <1106863164.745581.11920@f14g2000cwb.googlegroups.com> <1106911061.429966.303510@f14g2000cwb.googlegroups.com> <7x3bwlsqnj.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Duncan Booth writes: >> In other words, I'm intrigued how you managed to come up with >> something you consider to be a security issue with Python since >> Python offers no security. Perhaps, without revealing the actual >> issue in question, you could give an example of some other situation >> which, if it came up in Python you would consider to be a security >> issue? > > Until fairly recently, the pickle module was insufficiently documented > as being unsafe to use with hostile data, so people used it that way. > As a result, the Cookie module's default settings allowed remote > attackers to take over Python web apps. See SF bug 467384. SF doesn't seem to know about any such bug any more. Google finds me http://mail.python.org/pipermail/python-bugs-list/2001-October/007669.html which appears to be SF bug 467384, but it says nothing about security or the Cookie module, just that you wanted better documentation. I think its a bit borderline whether this really was a security bug in Python rather than just a problem with the way some people used Python. It was a standard library which if used in the wrong way opens a security hole on your machine, but there are plenty of ways to open security holes. The response seems to have been to document that there is a security concern here, but it is still just as possible to use python to expose your machine to attack as it was before. But thanks anyway, it does give me the sort of example I was asking for. From deetsNOSPAM at web.de Mon Jan 10 08:09:47 2005 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Mon, 10 Jan 2005 14:09:47 +0100 Subject: Command line and GUI tools : need a single threading solution References: <41e26e79@duster.adelaide.on.net> Message-ID: <34f9lfF4af717U1@individual.net> > I'm thinking it may be possible to modify the command line tools to use qt > threads instead of native python threads. Is this the way to go? Are > there other options? Why don't you use python threads in qt - I do so and so far it didn't make any troubles for me. And I would strongly advise against using qthreads with your commandline-tools, as these then would only run on machines where pyqt is installed - which opens a small part of "dependency hell" for your users. -- Regards, Diez B. Roggisch From aut_gbarros at uolinc.com Wed Jan 5 11:18:51 2005 From: aut_gbarros at uolinc.com (Gabriel Cosentino de Barros) Date: Wed, 5 Jan 2005 14:18:51 -0200 Subject: tk the python way Message-ID: <2814F26DA6908F41927A81C410C4991A02079C32@siamun.server.bl.corp.intranet> I'm strugling a little with TK, and the docs on the web aren't helping much. I've already rewritten about twelve times a basic class that was supposed to simply draw a window. It's not even close the final draft, but i tought "well, let's start with something easy that can be done in less than an hour"... silly me. But keep reading, it's not just to vent my frustations :) The main issue here is: How to use TK eficiently. I'm already planing another post about the pack/grid/place-power-trio but for now: what's the better, most scalable and less cumbersome way to use Tk? 1. Windows a) hide Tkroot in __main__ and call the class, whom willcreate it's own windows. b) let __main__ pass the root window and make the class always require a parent. c) what's the "industry standandard" for a single or dual window small app? (no, it's not java, wrong topic) 2. Buttons What's the nicer way to pass arguments directly in a button action? I don't know if this one is me just being dumb. but `Button(..., command=doit(1) )` doesn't work for me and i haven't seen it in any doc... I came to the point of writing: btnHd = Button(..., command=self.__fileBrowseH) btnCd = Button(..., command=self.__fileBrowseC) btnFd = Button(..., command=self.__fileBrowseF) and self.__fileBrowse/[CHF]/() being just a wraper for self.__fileBrowse('/[chf]/') ...And don't miss on this same channel: my indignation with Tk's positioning systems :P Thanks! Gabriel -------------- next part -------------- An HTML attachment was scrubbed... URL: From none at none.net Tue Jan 4 06:11:23 2005 From: none at none.net (Iwan van der Kleyn) Date: Tue, 04 Jan 2005 12:11:23 +0100 Subject: Python evolution: Unease In-Reply-To: <1gpv286.1kccndo1l4coseN%aleaxit@yahoo.com> References: <41da4a3f$0$17626$e4fe514c@dreader13.news.xs4all.nl> <1gpv286.1kccndo1l4coseN%aleaxit@yahoo.com> Message-ID: <41DA79DB.7020507@none.net> > Also, you keep talking about "the core python team" on the basis, it > would appear, of reading one document by Guido. Have you bothered doing > a MINIMUM of homework, such as, looking at > http://www.amk.ca/diary/archives/cat_python.html Well, you being a member of that core team (meaning nog an organisational unit, but the group of people doing the really hard job, getting Python to work. An excellent job at that :-) I can repect you if not branding me a lamer at least admonishing me for not coming up with a thorough factual statement. But like I stated: "ramblings", remember. I'm not completely unknown with the workings of our species myself, though. Especially when discourse and policy is dictated by a select group of people (meaning: the one who actually create python, no criticism there) with final abritary powers for one indidual (again, no criticism), mindset *is* just as important as stated fact. Mindset will dictate future discourse and action. And I do sense (reading planet python/this newsgroup) a mindset or at least a tendency by the people who really matter in these discussion to keep on adding features to the syntax; to add "structure" to Python. My personal preference would be to leave the language alone for a while and to improve its infrastructure. Regards, Iwan From lance-news at augustmail.com Tue Jan 25 17:51:16 2005 From: lance-news at augustmail.com (Lance Hoffmeyer) Date: Tue, 25 Jan 2005 16:51:16 -0600 Subject: script to search ebay? Message-ID: Hi all, Anyone know where I can find a python script to search ebay? I have been looking around but haven't found anything. I know there must be one somewhere so I am probably just looking in the wrong places. Optimally, I would like the script to search ebay and then send an email out with the results. Lance From fu.limin.tao at gmail.com Thu Jan 27 10:13:03 2005 From: fu.limin.tao at gmail.com (Limin Fu) Date: Thu, 27 Jan 2005 16:13:03 +0100 Subject: Tao Scripting Language 0.8.5 beta released! In-Reply-To: <35scaqF4sqpqnU1@individual.net> References: <35scaqF4sqpqnU1@individual.net> Message-ID: Dear Claudio, Thank you for your kind testing, suggestions and encourages. I'm glad that you like it. For that problem in the Lexer, it can be corrected without increasing the size. I will do it soon. Best regards, Limin On Thu, 27 Jan 2005 15:32:13 -0000, Claudio Grondi wrote: > Dear Limin, > > Tao Script with its 300 KByte of code is so small, > that one just must love it forgiving all its baby > troubles. > > After changes (see below) to the code in taoModule.cpp > necessary because my compiler claimed repeated definition > of 'ref' e.g. in the section: > if(TaoReference *ref2a=inNameSpace->findDataShared(name) ){ > myData[name]=ref2a; > outNameSpace->nsData[name]=ref2a; > }else{ > TaoShareRefer*ref2b=new TaoShareRefer(); > myData[name]=ref2b; > outNameSpace->nsDataShared[name]=ref2b; > outNameSpace->nsData[name]=ref2b; > } > I was able to compile the code with > Microsoft Visual C++ .NET 2003 on W2K > (create an empty .NET project, add all source > code files, compile and be happy :-) > > Trying the examples provided on the > homesite of Tao Script which run ok as they > are, I found, that print("### \n") failes due to > the way the Lexer works beeing not able to > proper handle string literals. > One just can't probably use any of "#'" "//" "/*" > in strings because the lexer strips the > comments before it analyses the source > to handle content of the string literals. > > Hope this comment helps you to continue > the well done work on it. > I had fun with it because of its size, so > from my point of view please try to > keep the project as small as possible, so > that it remains easy to check out the entire > code. > Maybe it is even a good idea to keep > the problem with the strings as a "feature" > in order to keep the Lexer as simple as > possible? > > Best regards > > Claudio > > "Limin Fu" schrieb im Newsbeitrag > news:mailman.1426.1106825698.22381.python-list at python.org... > > Dear all, > > > > I am glad to announce in this mailing list that the lastest version > > of a new scripting language has come out. > > > > Welcome to try it out. > > > > Comments are welcome. > > > > Suggestions are appreciated. > > > > ======================= > > Here are some details: > > ======================= > > > > Design Goals: > > 1. Simple and efficient. > > 2. Integrate nice features of other languages whenever possible. > > > > Implementation language: C++ with STL. > > > > Designer: Fu Limin > > Email: fu [dot] limin [dot] tao [at] gmail.com > > > > Key features have been supported: > > > > 1. Dynamic-typing variables, supporting complex data structures > > such as array/list, hash/dictionary and matrix etc. > > > > 2. Object-oriented programming ( multi-inheritance not supported > > yet ). > > > > 3. Basic string regular expression matching. > > > > 4. Automatic garbage collection capable of collecting cyclically > > referenced objects. > > > > 5. Numeric data types: complex number and matrix, and their basic > > operations. > > > > 6. Convenient namespacing and dynamic creation of subroutines and > > classes. > > > > 7. Dynamic loading of C/C++ modules ( not complete, but enough for > > playing with it ^_^ ). > > > > 8. An embedded tiny XML parser. > > > > ToBeDone: > > More string operations, multi-inheritance of classes, improvements > > on C/C++ module loading, more on regular expression matching and > > possible optimizations etc. > > > > Documentation: > > > > http://taoscript.sourceforge.net/brief_tao.php > > > > Sample scripts: > > > > http://taoscript.sourceforge.net/sample.php > > > > Download: > > http://taoscript.sourceforge.net/downloads.php > > > > Best regards, > > > > Limin > > > > -- > > Homepage for Tao Language: > > http://taoscript.sourceforge.net > > > > Tao Language project at sourceforge.net: > > http://sourceforge.net/projects/taoscript > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Homepage for Tao Language: http://taoscript.sourceforge.net Tao Language project at sourceforge.net: http://sourceforge.net/projects/taoscript From alanmk at hotmail.com Sun Jan 23 14:11:30 2005 From: alanmk at hotmail.com (Alan Kennedy) Date: Sun, 23 Jan 2005 19:11:30 +0000 Subject: Textual markup languages (was Re: What YAML engine do you use?) In-Reply-To: <7xmzv0gw80.fsf@ruckus.brouhaha.com> References: <35a6tpF4gmat2U1@individual.net> <7x1xcfwbab.fsf@ruckus.brouhaha.com> <35csm7F4l57inU1@individual.net> <7xmzv0gw80.fsf@ruckus.brouhaha.com> Message-ID: [Alan Kennedy] >>So, I'm hoping that the learned folks here might be able to give me >>some pointers to a markup language that has the following >>characteristics [Paul Rubin] > I'm a bit biased but I've been using Texinfo for a long time and have > been happy with it. It's reasonably lightweight to implement, fairly > intuitive to use, and doesn't get in the way too much when you're > writing. There are several implementations, none in Python at the > moment but that would be simple enough. It does all the content > semantics you're asking (footnotes etc). It doesn't have an explicit > object model, but is straightforward to convert into a number of > formats including high-quality printed docs (TeX); the original Info > hypertext browser that predates the web; and these days HTML. Thanks Paul, I took a look at texinfo, and it looks powerful and good ....... for programmers. Looks like a very steep learning curve for non-programmers though. It seems to require just a few hundred kilobytes too much documentation ...... regards, -- alan kennedy ------------------------------------------------------ email alan: http://xhaus.com/contact/alan From ncoghlan at iinet.net.au Fri Jan 14 02:46:35 2005 From: ncoghlan at iinet.net.au (Nick Coghlan) Date: Fri, 14 Jan 2005 17:46:35 +1000 Subject: python and macros (again) [Was: python3: 'where' keyword] In-Reply-To: <7xacrcdhzh.fsf@ruckus.brouhaha.com> References: <1105437966.129342.304400@f14g2000cwb.googlegroups.com> <7xmzvfn096.fsf@ruckus.brouhaha.com> <7xsm559heo.fsf@ruckus.brouhaha.com> <7xacrcdhzh.fsf@ruckus.brouhaha.com> Message-ID: <41E778DB.2050601@iinet.net.au> Paul Rubin wrote: > Come on, that is vacuous. The claim was "expressions are not > statements". But it turns out that expressions ARE statements. The > explanation is "well, that's because they're expression statements". > And there is no obvious case of an expression that can't be used as a > statement. So it's not inherently obvious that there needs to be any > kind of statement that can't be used as an expression. It's just an > artifact. Whether the artifact is a desirable one is a matter of > discussion. No, it's entirely to do with building a readable language that uses significant whitespace to delineate scope. Simple statements are not allowed to contain other statements, but they are allowed to contain expressions. In their most degenerate form, ALL they contain is a *single* expression (e.g. a function call). That expression itself is still not a statement, though. Think of it as the difference between value and [value]. Suites are sequences of statements. Compound statements are statements which incorporate a suite as part of their syntax. Python allows statements inside suites and suites inside compound statements. It also allows expressions inside statements and expressions inside expressions. The one thing it never ever does is allow a suite or a statement inside an expression, because doing so would utterly destroy the handling of significant white space. And that's why expressions are special in Python - they demarcate the boundary of the significance of whitespace. Within an expression, whitespace is insignificant. At the level of statements and suites, whitespace is extremely significant. So, precisely how should one go about cleanly embedding something that cares about whitespace into a context which doesn't care in the slightest? Cheers, Nick. -- Nick Coghlan | ncoghlan at email.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.skystorm.net From duncan.booth at invalid.invalid Thu Jan 27 06:57:18 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 Jan 2005 11:57:18 GMT Subject: how to comment out a block of code References: <1106767695.572974.98920@z14g2000cwz.googlegroups.com> Message-ID: Xah Lee wrote: > > is there a syntax to comment out a block of code? i.e. like html's > or perhaps put a marker so that all lines from there on are ignored? > thanks. > The simplest way is to select the block of code in your editor and use the 'comment-region' command. If this doesn't work, upgrade your editor. Most editors have a command to do this although obviously the name will vary slightly: Idle calls it 'Comment Out Region', SciTe calls it 'Block Comment', emacs calls it 'comment-region'. From aurora00 at gmail.com Fri Jan 21 23:02:38 2005 From: aurora00 at gmail.com (aurora) Date: Fri, 21 Jan 2005 20:02:38 -0800 Subject: list unpack trick? Message-ID: I find that I use some list unpacking construct very often: name, value = s.split('=',1) So that 'a=1' unpack as name='a' and value='1' and 'a=b=c' unpack as name='a' and value='b=c'. The only issue is when s does not contain the character '=', let's say it is 'xyz', the result list has a len of 1 and the unpacking would fail. Is there some really handy trick to pack the result list into len of 2 so that it unpack as name='xyz' and value=''? So more generally, is there an easy way to pad a list into length of n with filler items appended at the end? From reinhold-birkenfeld-nospam at wolke7.net Tue Jan 18 12:38:09 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Tue, 18 Jan 2005 18:38:09 +0100 Subject: [perl-python] 20050118 keyed list In-Reply-To: <41ed0f4d.39606090@news.erols.com> References: <1106027360.920787.321590@z14g2000cwz.googlegroups.com> <41ed0f4d.39606090@news.erols.com> Message-ID: <354vs2F3oehr2U1@individual.net> Jay Tilton wrote: >: # the syntax of keyed list in Perl is too complex >: # to be covered in a short message. JFTR: "keyed lists" are called dictionaries in Python. > > [1]Message-ID: <7fe97cc4.0401242131.22acf485 at posting.google.com> > This guy's wish-wash is starting to be funny, after all! Reinhold From cam.ac.uk at mh391.invalid Fri Jan 14 20:37:53 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Sat, 15 Jan 2005 01:37:53 +0000 Subject: query python env In-Reply-To: References: Message-ID: Steve Holden wrote: > I suspect rather that the OP is looking for os.environ, as in: He was using the examples of PYTHONHOME and PYTHONPATH which have specific meanings. Using sys.prefix is better than os.environ["PYTHONHOME"], which is unlikely to be set. -- Michael Hoffman From irmen at -nospam-remove-this-xs4all.nl Fri Jan 14 12:55:19 2005 From: irmen at -nospam-remove-this-xs4all.nl (Irmen de Jong) Date: Fri, 14 Jan 2005 18:55:19 +0100 Subject: Why 'r' mode anyway? (was: Re: Pickled text file causing ValueError (dos/unix issue)) In-Reply-To: References: <1105682410.406541.317590@c13g2000cwb.googlegroups.com> Message-ID: <41e80785$0$6203$e4fe514c@news.xs4all.nl> Tim Peters wrote: > Yes: regardless of platform, always open files used for pickles in > binary mode. That is, pass "rb" to open() when reading a pickle file, > and "wb" to open() when writing a pickle file. Then your pickle files > will work unchanged on all platforms. The same is true of files > containing binary data of any kind (and despite that pickle protocol 0 > was called "text mode" for years, it's still binary data). I've been wondering why there even is the choice between binary mode and text mode. Why can't we just do away with the 'text mode' ? What does it do, anyways? At least, if it does something, I'm sure that it isn't something that can be done in Python itself if really required to do so... --Irmen From francis.girard at free.fr Tue Jan 25 01:27:21 2005 From: francis.girard at free.fr (Francis Girard) Date: Tue, 25 Jan 2005 07:27:21 +0100 Subject: Classical FP problem in python : Hamming problem In-Reply-To: <1f7befae05012419297085cdf@mail.gmail.com> References: <63b5e209.0501210558.686f5c10@posting.google.com> <200501241409.25598.francis.girard@free.fr> <1f7befae05012419297085cdf@mail.gmail.com> Message-ID: <200501250727.22371.francis.girard@free.fr> Ok I'll submit the patch with the prose pretty soon. Thank you Francis Girard FRANCE Le mardi 25 Janvier 2005 04:29, Tim Peters a ?crit?: > [Francis Girard] > > > For all the algorithms that run after their tail in an FP way, like the > > Hamming problem, or the Fibonacci sequence, (but unlike Sieve of > > Eratosthene -- there's a subtle difference), i.e. all those algorithms > > that typically rely upon recursion to get the beginning of the generated > > elements in order to generate the next one ... > > > > ... so for this family of algorithms, we have, somehow, to abandon > > recursion, and to explicitely maintain one or many lists of what had been > > generated. > > > > One solution for this is suggested in "test_generators.py". But I think > > that this solution is evil as it looks like recursion is used but it is > > not and it depends heavily on how the m235 function (for example) is > > invoked. > > Well, yes -- "Heh. Here's one way to get a shared list, complete with > an excruciating namespace renaming trick" was intended to warn you in > advance that it wasn't pretty . > > > Furthermore, it is _NOT_ memory efficient as pretended : it leaks ! > > Yes. But there are two solutions to the problem in that file, and the > second one is in fact extremely memory-efficient compared to the first > one. "Efficiency" here was intended in a relative sense. > > > It internally maintains a lists of generated results that grows forever > > while it is useless to maintain results that had been "consumed". Just > > for a gross estimate, on my system, percentage of memory usage for this > > program grows rapidly, reaching 21.6 % after 5 minutes. CPU usage varies > > between 31%-36%. Ugly and inefficient. > > Try the first solution in the file for a better understanding of what > "inefficient" means . > > > The solution of Jeff Epler is far more elegant. The "itertools.tee" > > function does just what we want. It internally maintain a list of what > > had been generated and deletes the "consumed" elements as the algo > > unrolls. To follow with my gross estimate, memory usage grows from 1.2% > > to 1.9% after 5 minutes (probably only affected by the growing size of > > Huge Integer). CPU usage varies between 27%-29%. > > Beautiful and effecient. > > Yes, it is better. tee() didn't exist when generators (and > test_generators.py) were written, so of course nothing in the test > file uses them. > > > You might think that we shouldn't be that fussy about memory usage on > > generating 100 digits numbers but we're talking about a whole family of > > useful FP algorithms ; and the best way to implement them should be > > established. > > Possibly -- there really aren't many Pythonistas who care about this. > > > For this family of algorithms, itertools.tee is the way to go. > > > > I think that the semi-tutorial in "test_generators.py" should be updated > > to use "tee". Or, at least, a severe warning comment should be written. > > Please submit a patch. The purpose of that file is to test > generators, so you should add a third way of doing it, not replace the > two ways already there. It should also contain prose explaining why > the third way is better (just as there's prose now explaining why the > second way is better than the first). From bulba at bulba.com Sat Jan 15 11:40:17 2005 From: bulba at bulba.com (Bulba!) Date: Sat, 15 Jan 2005 17:40:17 +0100 Subject: What strategy for random accession of records in massive FASTA file? References: <1105569967.129284.85470@c13g2000cwb.googlegroups.com> <1105734450.961150.32980@z14g2000cwz.googlegroups.com> <7xfz13zrb2.fsf@ruckus.brouhaha.com> Message-ID: On 14 Jan 2005 12:30:57 -0800, Paul Rubin wrote: >Mmap lets you treat a disk file as an array, so you can randomly >access the bytes in the file without having to do seek operations Cool! >Just say a[234]='x' and you've changed byte 234 of the file to the >letter x. However.. however.. suppose this element located more or less in the middle of an array occupies more space after changing it, say 2 bytes instead of 1. Will flush() need to rewrite the half of mmaped file just to add that one byte? flush() definitely makes updating less of an issue, I'm just curious about the cost of writing small changes scattered all over the place back to the large file. -- I have come to kick ass, chew bubble gum and do the following: from __future__ import py3k And it doesn't work. From mefjr75 at hotmail.com Sun Jan 30 20:16:07 2005 From: mefjr75 at hotmail.com (M.E.Farmer) Date: 30 Jan 2005 17:16:07 -0800 Subject: Problem with loading textfiles into dictionaries. In-Reply-To: <1107132206.446722.21720@f14g2000cwb.googlegroups.com> References: <1107132206.446722.21720@f14g2000cwb.googlegroups.com> Message-ID: <1107134167.206620.286290@z14g2000cwz.googlegroups.com> mercuryp... at gmail.com wrote: > Hello, > I want to do the following: > > def do_load(self, arg): > sitefile = file('sitelist', 'r+', 1) > while True: > siteline = sitefile.readline() > site_rawlist = siteline.split() > sitelist[site_rawlist[0]] = site_rawlist[1:] > if len(siteline) == 0: > break > > I want to load a textfile into a dictionaries and use the first word on > a line as the key for the list, then take the remaining words of the > line and make them values of the key. This doesn't work: > > File "ftp.py", line 57, in do_load > sitelist[site_rawlist[0]] = site_rawlist[1:] > IndexError: list index out of range Hello again Munin, First i'll start with a spanking! Post your code like this:(or pick your favorite starter) Py> def do_load(self, arg): ... sitefile = file('sitelist', 'r+', 1) ... while True: ... siteline = sitefile.readline() ... site_rawlist = siteline.split() ... sitelist[site_rawlist[0]] = site_rawlist[1:] ... if len(siteline) == 0: ... break See how much nicer that is even if the newsfeed gets mangled it comes out ok(mostly). If I guess right it looks like you are trying disect a line that was empty or only had one element. If you check for line length first you might do better. Py> def do_load(self, arg): ... sitefile = file('sitelist', 'r+', 1) ... while True: ... if len(siteline) == 0: ... break ... siteline = sitefile.readline() ... site_rawlist = siteline.split() ... sitelist[site_rawlist[0]] = site_rawlist[1:] Ok next thing is this smells like you really are trying to reinvent a sort of pickle. If you don't know search for 'python pickle module'. examples abound but here it is anyway: Py> import pickle Py> # Pickle a dictionary Py> f = open('/tmp/mydata', 'wb') Py> f.write(pickle.dumps(yourdict) Py> f.close() Py> # and it is easy to get back as well Py> f = open('tmp/mydata', rb') Py> pdata = f.read() Py> f.close() Py> yourdict = pickle.load(pdata) hth, M.E.Farmer From wuwei23 at gmail.com Sun Jan 23 20:57:04 2005 From: wuwei23 at gmail.com (alex23) Date: 23 Jan 2005 17:57:04 -0800 Subject: how to write a tutorial In-Reply-To: <1106472508.591411.40140@c13g2000cwb.googlegroups.com> References: <1106305730.361540.21010@f14g2000cwb.googlegroups.com> <1106472508.591411.40140@c13g2000cwb.googlegroups.com> Message-ID: <1106531824.833549.28720@c13g2000cwb.googlegroups.com> > the first paragraph of 9.1 "A Word About Terminology" is > epitome of masturbation. I'm tempted to concede this point to you given the sheer overwhelming testament to onanism that is your website but this is just nonsense. Defining terms is *always* necessary, it ensures that participants in whatever dialogue are at least partially using the terms with the same intent > For 99% of readers, it is incomprehensible and irrelevant. You're not 99% of the readers, so I find that remark difficult to swallow. Having read your comments on women, the whole idea that you have a superior insight into would-be python coders is just obscenely ludicrous. - alex23 From just at xs4all.nl Mon Jan 3 04:08:46 2005 From: just at xs4all.nl (Just) Date: Mon, 03 Jan 2005 10:08:46 +0100 Subject: Rebinding stdout (was: Re: Python! Is! Truly! Amazing!) References: <1104657461.868175.252380@c13g2000cwb.googlegroups.com> Message-ID: In article , JanC wrote: > Something like this: > > py> import cStringIO > py> import sys > py> > py> def foo(): > ... print "test" > ... > py> f = cStringIO.StringIO() > py> sys.stdout = f > py> foo() > py> s = f.getvalue() > py> sys.stdout = sys.__stdout__ You should always save stdout instead of using __stdout__. It may not be the same! I don't think anyone should *ever* use __stdout__ except when debugging. See also: http://mail.python.org/pipermail/python-dev/2000-October/010144.html > py> f.close() > py> print s.capitalize() > Test Just From fredrik at pythonware.com Tue Jan 25 02:51:21 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 25 Jan 2005 08:51:21 +0100 Subject: What's so funny? WAS Re: rotor replacement References: <200501241906.39865.hancock@anansispaceworks.com> Message-ID: Terry Hancock wrote: > And, well, I'm sorry Mr. Lundh, but your PIL module actually is something > of a pain to install still. The OP is right about that. Usually worth it, but I don't > like the fact that that pain is being passed on to the end-user of my software. > > The fact that you got all snide and refused to work with me when I asked > for a copy of the autoconf sources to try to fix the problem didn't make me > too happy, either. ah, you're the guy who flamed me and called me names because PIL didn't fit some hypothetical GNU-inspired definition of "open source software." it's always sad when people have to attack those who don't share their religion, but it's not that much I can do about that. > So, naturally, I just dropped it. which means that you have no idea how easy or hard it is to install PIL today (hint: things have changed) From ncoghlan at iinet.net.au Tue Jan 11 08:04:50 2005 From: ncoghlan at iinet.net.au (Nick Coghlan) Date: Tue, 11 Jan 2005 23:04:50 +1000 Subject: else condition in list comprehension In-Reply-To: <1105305000.052714.188980@c13g2000cwb.googlegroups.com> References: <1105302040.286420.313240@c13g2000cwb.googlegroups.com> <1105305000.052714.188980@c13g2000cwb.googlegroups.com> Message-ID: <41E3CEF2.4070807@iinet.net.au> Dan Bishop wrote: > Luis M. Gonzalez wrote: > >>Hi there, >> >>I'd like to know if there is a way to add and else condition into a >>list comprehension. I'm sure that I read somewhere an easy way to do >>it, but I forgot it and now I can't find it... >> >>for example: >>z=[i+2 for i in range(10) if i%2==0] >>what if I want i [sic] to be "i-2" if i%2 is not equal to 0? > > > z = [i + (2, -2)[i % 2] for i in range(10)] For the specific case of +/- a number, (-1) ** x works, too: z = [i + 2 * ((-1) ** i) for i in range(10)] Not that I'm claiming it's particularly readable or anything. . . just that it works :) Cheers, Nick. -- Nick Coghlan | ncoghlan at email.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.skystorm.net From danperl at rogers.com Sun Jan 30 19:24:06 2005 From: danperl at rogers.com (Dan Perl) Date: Sun, 30 Jan 2005 19:24:06 -0500 Subject: Regarding exception handling References: <1107114438.710147.218010@z14g2000cwz.googlegroups.com> <1107114866.965331.158950@f14g2000cwb.googlegroups.com> <1107119504.793109.184450@c13g2000cwb.googlegroups.com> <1107127179.863445.55310@c13g2000cwb.googlegroups.com> Message-ID: "Aggelos I. Orfanakos" wrote in message news:1107127179.863445.55310 at c13g2000cwb.googlegroups.com... > Thanks. This should now be OK: > > #try: > # try: > # s = ... # socket opens > # > # # various code ... > # except socket.error, x: > # # exception handling > #finally: > # s.close() # socket closes > Why the nested try's? If I understand your intention correctly this should do the same thing: try: s = ... # socket opens # various code ... except socket.error, x: # exception handling s.close() # socket closes You would need the try-finally statement only if you expect it to handle other exceptions than socket.error or if the socket.error is re-raised in the "except" clause. Otherwise, the try-finally statement is redundant because no socket.error are getting out of the try-except statement. Dan From guettli at thomas-guettler.de Wed Jan 26 11:15:48 2005 From: guettli at thomas-guettler.de (Thomas Guettler) Date: Wed, 26 Jan 2005 17:15:48 +0100 Subject: Help With Python References: Message-ID: Am Wed, 26 Jan 2005 15:55:28 +0000 schrieb Judi Keplar: > > I am currently taking a course to learn Python and was looking for > some help. I need to write a Python statement to print a comma- > separated repetition of the word, "Spam", written 511 times ("Spam, > Spam, Spam"). > > Can anybody help me get started? I am completely new to programming! Hi, # This way, there is a comma after the last: import sys for i in range(511): sys.stdout.write("Spam, ") # No comma at the end: mylist=[] for i in range(511): mylist.append("Spam") print ", ".join(mylist) Thomas -- Thomas G?ttler, http://www.thomas-guettler.de/ From tomi.hasa at gmail.com Mon Jan 10 08:46:32 2005 From: tomi.hasa at gmail.com (=?iso-8859-1?B?VG9taSBI5HPk?=) Date: 10 Jan 2005 05:46:32 -0800 Subject: OT: google groups bug, or worse? In-Reply-To: <1105127965.616198.302710@z14g2000cwz.googlegroups.com> References: <1105127965.616198.302710@z14g2000cwz.googlegroups.com> Message-ID: <1105364792.404039.65190@c13g2000cwb.googlegroups.com> aaronwmail-usenet at yahoo.com wrote: > I'm concerned that google groups is not correctly reflecting > the python lists. > [...] > Is it a google bug? Yes, Google Groups Beta is missing messages: http://groups-beta.google.com/group/google-labs-groups2/browse_thread/thread/c4108ad41c189d34?tvc=2 http://tinyurl.com/6vybw http://groups-beta.google.com/group/google-labs-groups2/msg/dc745c7784c81890 http://tinyurl.com/4keqh http://groups-beta.google.com/group/google-labs-groups2/msg/b54c12517c75eb24 From tjreedy at udel.edu Thu Jan 20 13:40:12 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 20 Jan 2005 13:40:12 -0500 Subject: RuntimeError: dictionary changed size during iteration References: Message-ID: RE: RuntimeError: dictionary changed size during iteration "Batista, Facundo" wrote [Robert Brewer] #- But not unexpected, since vars() returns a dictionary, and #- binding 'e' #- changes that dictionary while you are iterating over it. >For me, the point is: vars() returns the local variables > as a list or is a generator? As the OP said, it returns a *dictionary*. In particular: >>> help(vars) Help on built-in function vars: vars(...) vars([object]) -> dictionary Without arguments, equivalent to locals(). With an argument, equivalent to object.__dict__. >In the docs don't say nothing about this. You must be having a bad day ;-). From Lib Ref 2.1 Built-in Functions: vars( [object]) Without arguments, return a dictionary corresponding to the current local symbol table. With a module, class or class instance object as argument (or anything else that has a __dict__ attribute), returns a dictionary corresponding to the object's symbol table. The returned dictionary should not be modified: the effects on the corresponding symbol table are undefined Terry J. Reedy From drewc at rift.com Fri Jan 21 08:23:08 2005 From: drewc at rift.com (drewc) Date: Fri, 21 Jan 2005 13:23:08 GMT Subject: how to write a tutorial In-Reply-To: <1106305730.361540.21010@f14g2000cwb.googlegroups.com> References: <1106305730.361540.21010@f14g2000cwb.googlegroups.com> Message-ID: <0n7Id.135415$Xk.80179@pd7tw3no> You should not be giving such advice! (and the crosspost ... WTF?). I've been trying to follow along with your perl/python yahoo group, but your posts are terrible. Perhaps you should provide the output of the code you post. Then i'd actually know what i'm trying to achieve. As it is i have to cut/paste your code into an interpreter just to figure out what it does. What does this have to do with Lisp? (i'm in c.l.l). drewc Xah Lee wrote: > i've started to read python tutorial recently. > http://python.org/doc/2.3.4/tut/tut.html > > Here are some quick critique: > > quick example: > If the input string is too long, they don't truncate it, but return it > unchanged; this will mess up your column lay-out but that's usually > better than the alternative, which would be lying about a value. (If > you really want truncation you can always add a slice operation, as in > "x.ljust( n)[:n]". > > better: > If the input string is too long, they don't truncate it, but return it > unchanged; > ----------------- > delete: Reverse quotes (``) are equivalent to repr(), but their use is > discouraged. > ----------------- > similarly, many places mentioning uncritical info such as warning or > reference to other languages should be deleted. > > the tutorial should be simple, concise, to the point, stand along. > Perhaps 1/5th length of the tutorial should be deleted for better. > Follow the above principles. > > at places often a whole paragraph on some so called computer science > jargons should be deleted. They are there more to showcase inane > technicality than do help the reader. (related, many passages with > jargons should be rewritten sans inane jargon. e.g. mutable object.) > > one easy way to understand these principles is to compare perl's > documentation or unix man pages to Python's. The formers are often > irrelevant, rambling on, not stand-along (it is written such that it > unnecessarily requires the reader to be knowledgable of lots of other > things). Python docs are much better, but like many computer language > manuals, also suffers from verbiage of tech jargons. (these jargons or > passages about them are usually there to please the authors > themselves). > > A exemplary writing in this direction is the Mathematica manual by > Stephen Wolfram. Any intelligent layman sans computer science degree > can read it straightforwardly, and learn unhindered a language that is > tantamount to features of lisp languages. Such documentation is not > difficult to write at all. (contrary to the lot of "computer > scientists" or IT pundits morons.) All it take is some simple > principles outlined above. > Xah > xah at xahlee.org > http://xahlee.org/PageTwo_dir/more.html > From frans.englich at telia.com Mon Jan 17 13:45:46 2005 From: frans.englich at telia.com (Frans Englich) Date: Mon, 17 Jan 2005 18:45:46 +0000 Subject: Assigning to self Message-ID: <200501171845.46766.frans.englich@telia.com> Hello, I am having trouble with throwing class instances around. Perhaps I'm approaching my goals with the wrong solution, but here's nevertheless a stripped down example which demonstrates my scenario: #------------------------------------------------------------------------------------------ class foo: tests = {} def __init__( self, id ): try: me = self.__class__.tests[ id ] except KeyError: print "Did not exist, initializing myself.." self.attr = "exists" self.__class__.tests[ id ] = self else: print "Already exists! Re-using existing instance" self = me print "Me", self.attr + "!" # line 18 def yo(self): return self.attr # line 21 def main(): a = foo( "test" ) print "ATTR:", a.yo() b = foo( "test" ) print "ATTR:", b.yo() if __name__ == "__main__": main() #------------------------------------------------------------------------------------------ This is the output: Did not exist, initializing myself.. Me exists! ATTR: exists Already exists! Re-using existing instance Me exists! ATTR: Traceback (most recent call last): File "cpClass.py", line 32, in ? main() File "cpClass.py", line 29, in main print "ATTR:", b.yo() File "cpClass.py", line 21, in yo return self.attr # line 21 AttributeError: foo instance has no attribute 'attr' #------------------------------------------------------------------------------------------ What the code attempts to do is implementing a, to the API user, transparent memory-saver by ensuring that no more than one instance of the class foo exists for a particular id. E.g, the user can simply "create" an instance and if one not already exists, it is created. First of all; am I approaching the goal with the right solution? The way I do fails, obviously. The line 'self = me'(scary..) doesn't really work for the attribute attr; the attribute exists on line 21, but it fails when yo() tries to access it. What have failed? Is it a namespace scope issue? Do 'self = me' do what I think it should? Cheers, Frans From allen at cis.ohio-state.edu Tue Jan 4 17:37:20 2005 From: allen at cis.ohio-state.edu (Nick Allen) Date: Tue, 04 Jan 2005 17:37:20 -0500 Subject: Restore a unified diff Message-ID: After using ndiff from difflib, the function restore would return the sequence that generated the delta. Unfortunately, restore does not do the same for unified_diff. I do not see any similar function that is intended for unified_diff. Does anyone know how to "restore" from a unified diff generated delta? Thanks for all your help in advance. Best Regards, Nick Nick Allen From francis.girard at free.fr Wed Jan 26 18:19:39 2005 From: francis.girard at free.fr (Francis Girard) Date: Thu, 27 Jan 2005 00:19:39 +0100 Subject: Classical FP problem in python : Hamming problem In-Reply-To: <6PKdnVpD-4f3CGvcRVn-gQ@comcast.com> References: <63b5e209.0501210558.686f5c10@posting.google.com> <6PKdnVpD-4f3CGvcRVn-gQ@comcast.com> Message-ID: <200501270019.39611.francis.girard@free.fr> Le mardi 25 Janvier 2005 19:52, Steven Bethard a ?crit?: Thank you Nick and Steven for the idea of a more generic imerge. To work with the Hamming problem, the imerge function _must_not_ allow duplicates and we can assume all of the specified iteratables are of the same size, i.e. infinite ! Therefore, Nick's solution fulfills the need. But it is admittedly confusing to call the function "imerge" when it doesn't merge everything (including duplicates). Anyway both solution sheds new light and brings us a bit farther. That's the beauty of many brains from all over the world collabarating. Really, it makes me emotive thinking about it. For the imerge function, what we really need to make the formulation clear is a way to look at the next element of an iteratable without consuming it. Or else, a way to put back "consumed" elements in the front an iteration flow, much like the list constructors in FP languages like Haskell. It is simple to encapsulate an iterator inside another iterator class that would do just that. Here's one. The additional "fst" method returns the next element to consume without consuming it and the "isBottom" checks if there is something left to consume from the iteration flow, without actually consuming anything. I named the class "IteratorDeiterator" for lack of imagination : -- BEGIN SNAP class IteratorDeiterator: def __init__(self, iterator): self._iterator = iterator.__iter__() self._firstVal = None ## Avoid consuming if not requested from outside ## Works only if iterator itself can't return None def __iter__(self): return self def next(self): valReturn = self._firstVal if valReturn is None: valReturn = self._iterator.next() self._firstVal = None return valReturn def fst(self): if self._firstVal is None: self._firstVal = self._iterator.next() return self._firstVal def isBottom(self): if self._firstVal is None: try: self._firstVal = self._iterator.next() except StopIteration: return True return False -- END SNAP Now the imerge_infinite which merges infinite lists, while allowing duplicates, is quite straightforward : -- BEGIN SNAP def imerge_infinite(*iterators): vItTopable = [IteratorDeiterator(it) for it in iterators] while vItTopable: yield reduce(lambda itSmallest, it: itSmallest.fst() > it.fst() and it or itSmallest, vItTopable).next() -- END SNAP To merge finite lists of possibly different lengths is a bit more work as you have to eliminate iterators that reached the bottom before the others. This is quite easily done by simply filtering them out. The imerge_finite function below merges "lists" of possibly different sizes. -- BEGIN SNAP def imerge_finite(*iterators): vItDeit = [IteratorDeiterator(it) for it in iterators] vItDeit = filter(lambda it: not it.isBottom(), vItDeit) while vItDeit: yield reduce(lambda itSmallest, it: itSmallest.fst() > it.fst() and it or itSmallest, vItDeit).next() vItDeit = filter(lambda it: not it.isBottom(), vItDeit) -- END SNAP Now, we want versions of these two merge functions that do not allow duplicates. Building upon what we've already done in a semi FP way, we just filter out the duplicates from the iteration streams returned by the above functions. The job is the same for the infinite and finite versions, hence the imerge_nodup generic function. -- BEGIN SNAP def imerge_nodup(fImerge, *iterators): it = fImerge(*iterators) el = it.next() yield el while True: el = dropwhile(lambda _next: _next == el, it).next() yield el imerge_inf_nodup = \ lambda *iterators: imerge_nodup(imerge_infinite, *iterators) imerge_finite_nodup = \ lambda *iterators: imerge_nodup(imerge_finite, *iterators) -- END SNAP I used the lambda notation for imerge_inf_nodup and imerge_finite_nodup to avoid another useless for-yield loop. Here the notation really just express function equivalence with a bounded argument (it would be great to have a notation for this in Python, i.e. binding a function argument to yield a new function). The merge function to use with hamming() is imerge_inf_nodup. Regards, Francis Girard FRANCE > Nick Craig-Wood wrote: > > Steven Bethard wrote: > >> Nick Craig-Wood wrote: > >>>Thinking about this some more leads me to believe a general purpose > >>>imerge taking any number of arguments will look neater, eg > >>> > >>>def imerge(*generators): > >>> values = [ g.next() for g in generators ] > >>> while True: > >>> x = min(values) > >>> yield x > >>> for i in range(len(values)): > >>> if values[i] == x: > >>> values[i] = generators[i].next() > >> > >> This kinda looks like it dies after the first generator is exhausted, > >> but I'm not certain. > > > > Yes it will stop iterating then (rather like zip() on lists of unequal > > size). Not sure what the specification should be! It works for the > > hamming problem though. > > Actually, it stops iterating on lists of equal size too: > > py> def imerge(*iterators): > ... iterators = [iter(i) for i in iterators] > ... values = [i.next() for i in iterators] > ... while True: > ... x = min(values) > ... yield x > ... for i, val in enumerate(values): > ... if val == x: > ... values[i] = iterators[i].next() > ... > py> list(imerge([1, 4, 7], [2, 5, 8], [3, 6, 9])) > [1, 2, 3, 4, 5, 6, 7] > > Note that 8 and 9 are not in the list. > > Steve From gsakkis at rutgers.edu Mon Jan 24 15:50:52 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Mon, 24 Jan 2005 15:50:52 -0500 Subject: Tuple slices References: <35kn4mF4o44ufU1@individual.net> Message-ID: <35l5d9F4licj2U1@individual.net> "Fredrik Lundh" wrote in message news:mailman.1214.1106591959.22381.python-list at python.org... > Steven Bethard wrote: > > >>>>>a = 1, 2, 3 > >>>>>b = a[:] > >>>>>a is b > >> True > > > > My impression was that full tuple copies didn't actually copy, but that slicing a subset of a > > tuple might. Not exactly sure how to test this, but: > > > > py> a = 1, 2, 3 > > py> a[:2] is a[:2] > > False > > yup. and to figure out why things are done this way, consider this case: > > >>> a = give_me_a_huge_tuple() > >>> len(a) > (a rather large number) > >>> b = a[:2] > >>> del a > > (IIRC, I proposed to add "substrings" when I implemented the Unicode string > type, but that idea was rejected, for the very same "and how do you get rid of > the original object" reason) > > Fair enough. So perhaps the question is whether such cases are more regular than something like: a = give_me_a_huge_tuple() slices = [a[i:j] for i in xrange(len(a)) for j in xrange(i+1, len(a)+1)] George From tmohr at s.netic.de Wed Jan 12 16:40:13 2005 From: tmohr at s.netic.de (Torsten Mohr) Date: Wed, 12 Jan 2005 22:40:13 +0100 Subject: reference or pointer to some object? References: Message-ID: Hi, thank you all for your explanations. I still wonder why a concept like "references" was not implemented in Python. I think it is (even if small) an overhead to wrap an object in a list or a dictionary. Isn't it possible to extend Python in a way to use real references? Or isn't that regarded as necessary? Thanks for any hints, Torsten. From ionel.mc at gmail.com Thu Jan 20 22:14:31 2005 From: ionel.mc at gmail.com (ionel) Date: Fri, 21 Jan 2005 05:14:31 +0200 Subject: What's the best python web-developer's editor In-Reply-To: <41EFFCD9.7060302@wild-flower.co.uk> References: <41EFFCD9.7060302@wild-flower.co.uk> Message-ID: how about editplus ? imho it's excelent On Thu, 20 Jan 2005 18:47:53 +0000, andy wrote: > Anybody like to comment on which editor they use for python web app > development - for both discrete and mixed python and html code, and why? > > I'm comfortable with IDLE (used it for years) but of course it lacks ftp > or webDAV abilities, obviously because it's not intended for that type > of use. > > I've had a look at Screem - and that seems to do python syntax > highlighting, but it dosn't seem to be python syntax aware (unless > there's a hidden option somewhere). Although I can live without auto > indent, I'd rather not... > > I'm sure emacs, xemacs, vi, elvis and so on can do the same, but I have > no experience with them for heavy python or html coding, nor the time > to trip off down a blind-alley to find out! I know Enough Vi To Get > By(tm) but it's by no means my favourite editor. Emacs is a complete > mystery to me. > > I guess I *could* use IDLE and Screem together, but that's a clunky > solution! > > all opinions greatfully received, > -andyj > -- > http://mail.python.org/mailman/listinfo/python-list > -- ionel. From ark at acm.org Sat Jan 22 12:33:49 2005 From: ark at acm.org (Andrew Koenig) Date: Sat, 22 Jan 2005 17:33:49 GMT Subject: Zen of Python References: <972ec5bd050119111359e358f5@mail.gmail.com> <1106177050.630141.33090@c13g2000cwb.googlegroups.com> <972ec5bd0501191641166972b0@mail.gmail.com> <7xis5szpdj.fsf@ruckus.brouhaha.com> <7xekggbrns.fsf@ruckus.brouhaha.com> <7x651rwbib.fsf@ruckus.brouhaha.com> <7xfz0uqe1d.fsf@ruckus.brouhaha.com> <7xu0p9lk4h.fsf@ruckus.brouhaha.com> <7x8y6l8k6l.fsf@ruckus.brouhaha.com> Message-ID: <18wId.68007$w62.25250@bgtnsc05-news.ops.worldnet.att.net> "Paul Rubin" wrote in message news:7x8y6l8k6l.fsf at ruckus.brouhaha.com... > It's not obvious to me how the compiler can tell. Consider: > > x = 3 > if frob(): > frobbed = True > squares = [x*x for x in range(9)] > if blob(): > z = x > > Should the compiler issue a warning saying the program should be taken > out and shot? With lexical comprehensions, the program is perfectly > valid and sets z to 3 if blob() is true. The whole point of lexical > comprhensions is to make Python safe for such programs. > > Without lexical comprehensions, the program still doesn't depend on > the listcomp leakage if frob() and blob() aren't simultaneously true > (envision "assert not frobbed" before the "z = x"). So "should be > taken out and shot" is maybe a little bit extreme. Actually, I don't think so. If you intend for it to be impossible for "z = x" to refer to the x in the list comprehension, you shouldn't mind putting in "from __future__ import lexical_comprehensions." If you don't intend for it to be impossible, then the program *should* be taken out and shot. From spam-trap-095 at at-andros.demon.co.uk Sun Jan 23 19:45:34 2005 From: spam-trap-095 at at-andros.demon.co.uk (Andrew McLean) Date: Mon, 24 Jan 2005 00:45:34 +0000 Subject: Fuzzy matching of postal addresses [1/1] References: <96B2w2E$HF7BFwSq@at-andros.demon.co.uk> <1106517571.768306.23430@f14g2000cwb.googlegroups.com> Message-ID: <5jDnWqluUE9BFwTg@at-andros.demon.co.uk> In article <1106517571.768306.23430 at f14g2000cwb.googlegroups.com>, John Machin writes >Andrew McLean wrote: >> In case anyone is interested, here is the latest. > >> def insCost(tokenList, indx, pos): >> """The cost of inserting a specific token at a specific >normalised position along the sequence.""" >> if containsNumber(tokenList[indx]): >> return INSERT_TOKEN_WITH_NUMBER + POSITION_WEIGHT * (1 - pos) >> elif indx > 0 and containsNumber(tokenList[indx-1]): >> return INSERT_TOKEN_AFTER_NUMBER + POSITION_WEIGHT * (1 - >pos) >> elif tokenList[indx][0] in minorTokenList: >> return INSERT_MINOR_TOKEN >> else: >> return INSERT_TOKEN + POSITION_WEIGHT * (1 - pos) >> >> def delCost(tokenList, indx, pos): >> """The cost of deleting a specific token at a specific normalised >position along the sequence. >> This is exactly the same cost as inserting a token.""" >> return insCost(tokenList, indx, pos) > >Functions are first-class citizens of Pythonia -- so just do this: > >delCost = insCost > Actually, the code used to look like that. I think I changed it so that it would look clearer. But perhaps that was a bad idea. >Re speed generally: (1) How many addresses in each list and how long is >it taking? On what sort of configuration? (2) Have you considered using >pysco -- if not running on x86 architecture, consider exporting your >files to a grunty PC and doing the match there. (3) Have you considered >some relatively fast filter to pre-qualify pairs of addresses before >you pass the pair to your relatively slow routine? There are approx. 50,000 addresses in each list. At the moment the processing assumes all the postcodes are correct, and only compares addresses with matching postcodes. This makes it a lot faster. But may miss some cases of mismatched postcodes. Also it does two passes. One looking for exact matches of token sequences. This deals with about half the cases. Only then do I employ the, more expensive, edit distance technique. Overall, the program runs in less than half an hour. Specifically it takes about 60s per thousand addresses, which requires an average of about 8 calls to editDistance per address. Psyco.full() reduced the 60s to 45s. I'll only try optimisation if I need to use it much more. >Soundex?? To put it bluntly, the _only_ problem to which soundex is the >preferred solution is genealogy searching in the US census records, and >even then one needs to know what varieties of the algorithm were in use >at what times. I thought you said your addresses came from >authoritative sources. You have phonetic errors? Can you give some >examples of pairs of tokens that illustrate the problem you are trying >to overcome with soundex? I'm sure that in retrospect Soundex might not be a good choice. The misspellings tend to be minor, e.g. Kitwhistle and KITTWHISTLE Tythe and TITHE I was tempted by an edit distance technique on the tokens, but would prefer a hash based method for efficiency reasons. >Back to speed again: When you look carefully at the dynamic programming >algorithm for edit distance, you will note that it is _not_ necessary >to instantiate the whole NxM matrix -- it only ever refers to the >current row and the previous row. What does space saving have to do >with speed, you ask? Well, Python is not FORTRAN; it takes considerable >effort to evaluate d[i][j]. A relatively simple trick is to keep 2 rows >and swap (the pointers to) them each time around the outer loop. At the >expense of a little more complexity, one can reduce this to one row and >3 variables (north, northwest, and west) corresponding to d[i-1][j], >d[i-1][j-1], and d[i][j-1] -- but I'd suggest the simple way first. >Hope some of this helps, Thanks for that. The first edit distance algorithm I looked at did it that way. But I based my code on a version of the algorithm I could actually follow ;-). Getting the concatenation bit right was non-trivial and it was useful to store all of "d" for debugging purposes. As to Python not being Fortran. You've found me out. The three languages I am most comfortable with are Fortran, Matlab and Python. It did occur to me that numarray might be a more efficient way of dealing with a 4-dimensional array, but the arrays aren't very big, so the overhead in setting them up might be significant. The simplest optimisation would be to replace the two indices used to deal with concatenation by four explicit variables. And then, as you said, I could just store the three last rows, and avoid any multiple indexing. As with all these potential optimisations, you don't know until you try them. -- Andrew McLean From whereU at now.com Tue Jan 11 00:54:33 2005 From: whereU at now.com (Eric Pederson) Date: Mon, 10 Jan 2005 21:54:33 -0800 Subject: OT: MoinMoin and Mediawiki? In-Reply-To: <7x6524d6pv.fsf@ruckus.brouhaha.com> References: <7x6524d6pv.fsf@ruckus.brouhaha.com> Message-ID: <20050110215433.792683707.whereU@now.com> Paul Rubin wrote: > What I'm getting at is I might like to install MoinMoin now and > migrate to Mediawiki sometime later. Anyone have any thoughts about > whether that's a crazy plan? Disclaimer, I am neither using Moinmoin nor Mediawiki, and don't really have your answer. >From what I read, Mediawiki stores each page as "wikitext" in a MySQL database; wikitext "is a mixture of content, markup, and metadata." It seems essentially what you'd need for migration is a mapping function and I do not know how complex the mapping between the systems would be. I could imagine migrating from Moinmoin to Mediawiki via a script looping through the Moinmoin files in a directory, modifying a copy of each, and storing them in MySQL. I suspect it's less painful to just start with the wiki you want to end up with, but if you're going to migrate between the two, won't Python come in handy! ;-) Eric Pederson http://www.songzilla.blogspot.com ::::::::::::::::::::::::::::::::::: domainNot="@something.com" domainIs=domainNot.replace("s","z") ePrefix="".join([chr(ord(x)+1) for x in "do"]) mailMeAt=ePrefix+domainIs ::::::::::::::::::::::::::::::::::: From xah at xahlee.org Mon Jan 31 14:02:17 2005 From: xah at xahlee.org (Xah Lee) Date: 31 Jan 2005 11:02:17 -0800 Subject: Q: quoting string without escapes Message-ID: <1107198137.141990.246880@c13g2000cwb.googlegroups.com> in Python, is there a way to quote a string as to avoid escaping ' or " inside the string? i.e. like Perl's q or qq. thanks. Xah xah at xahlee.org http://xahlee.org/PageTwo_dir/more.html From g.brandl-2005-01 at gmx.net Sun Jan 23 15:11:32 2005 From: g.brandl-2005-01 at gmx.net (Georg Brandl) Date: Sun, 23 Jan 2005 21:11:32 +0100 Subject: Help on project, anyone? Message-ID: <35ienhF4lu88lU1@individual.net> Hello, to train my Python skills I am looking for some project I can contribute to. I learned Python about one year ago, and had already some programming background behind (I contributed to SharpDevelop for instance), so I'm not the complete newbie. About myself: I'm a 20 year old German with strong interests in programming and, of course, especially in Python (I love it...). Does anyone run, or participate in, a project looking for fellow programmers? I don't have a special area of interest, well, perhaps web programming... Thanks, Georg From ed at leafe.com Thu Jan 13 08:05:54 2005 From: ed at leafe.com (Ed Leafe) Date: Thu, 13 Jan 2005 08:05:54 -0500 Subject: wxPython and CheckListBox In-Reply-To: <1105613647.610479.13280@z14g2000cwz.googlegroups.com> References: <1105613647.610479.13280@z14g2000cwz.googlegroups.com> Message-ID: On Jan 13, 2005, at 5:54 AM, ncookson at networkusa.net wrote: > I am trying to add a caption or title to the box drawn around a > checklistbox and having no luck. Is there a way to do this? > I am using python 2.3.4 and wxPython 2.5 on a windows platform. I don't think you can do it directly. What you might want to try is to create a StaticBoxSizer with the label you want, and add the checkbox to that sizer. Then add the StaticBoxSizer to the panel's layout instead of the checkbox. ___/ / __/ / ____/ Ed Leafe http://leafe.com/ http://dabodev.com/ From http Wed Jan 19 04:42:00 2005 From: http (Paul Rubin) Date: 19 Jan 2005 01:42:00 -0800 Subject: rotor replacement References: <7x1xcidnp1.fsf@ruckus.brouhaha.com> <41EE24F7.7030303@jessikat.fsnet.co.uk> Message-ID: <7x1xchlpqv.fsf@ruckus.brouhaha.com> Robin Becker writes: > What exactly are/were the political reasons for rotor removal? Some countries have laws about cryptography software (against some combination of export, import, or use). The Python maintainers didn't want to deal with imagined legal hassles that might develop from including good crypto functions in the distribution. Then it became obvious that the same imagined hassles could also befall the rotor module, so that was removed. > I might add that the source for rotormodule is still easily obtainable > and can be compiled trivially as an extension for Python-2.4. Does the > Python community take a position on the sources of removed modules? Those are still free to distribute, but I'd advise against doing so with the rotor module unless you absolutely need it for some interoperability purpose. Otherwise, it's insecure and should not be used. The routine I posted was intended as a straightforward replacement for the rotor module that doesn't depend on C compilers and is reasonably secure. If you don't mind using C extensions, there's various AES modules available, plus fancier packages like mxCrypto. From philippe at philippecmartin.com Mon Jan 24 17:30:38 2005 From: philippe at philippecmartin.com (Philippe C. Martin) Date: Mon, 24 Jan 2005 22:30:38 GMT Subject: Why I use private variables (WAS: RE:"private" variables a.k.a. name mangling?) References: Message-ID: I used double underscore because I thought it was the correct way to name private variables/methods - I will have to change those to single underscore since that it the current methodology. A private variable to me: 1) is internal to the processing of a class and needs not be accessed by external or derivated objects. (I won't get into the potential need of "protected" variables/methods - Python creators have not made those distinctions for reasons that they believe are good and I'm not the one to discuss them) 2) Must not be documented to library users as they're using it would go againts 'law' 1). 3) I wish I had one, but there is only one Isaac Asimov after all :-) Regards, Philippe On Mon, 24 Jan 2005 11:45:34 -0500, Jeremy Bowers wrote: > On Mon, 24 Jan 2005 15:35:11 -0600, Philippe C. Martin wrote: > >> The real reason behind my using private variables is so they do not appear >> in the epydoc generated documentation and confuse my users. > > You mean single or double underscores? I just checked and at least epydoc > 2.1 doesn't include single-underscore values, but those aren't "private" > in sense we're talking in this thread (some form of compiler enforcement). From invalidemail at aerojockey.com Fri Jan 14 06:22:23 2005 From: invalidemail at aerojockey.com (Carl Banks) Date: 14 Jan 2005 03:22:23 -0800 Subject: python and macros (again) [Was: python3: 'where' keyword] In-Reply-To: References: <1105437966.129342.304400@f14g2000cwb.googlegroups.com> <7xmzvfn096.fsf@ruckus.brouhaha.com> <7xsm559heo.fsf@ruckus.brouhaha.com> <7xacrcdhzh.fsf@ruckus.brouhaha.com> Message-ID: <1105701743.706951.257970@c13g2000cwb.googlegroups.com> Skip Montanaro wrote: > Fredrik> no, expressions CAN BE USED as statements. that doesn't mean > Fredrik> that they ARE statements, unless you're applying belgian logic. > > Hmmm... I'd never heard the term "belgian logic" before. Googling provided > a few uses, but no formal definition (maybe it's a European phrase so > searching for it in English is futile). The closest thing I found was > > Or is it another case of Belgian logic, where you believe it because > theres no evidence or motive whatsoever? Maybe it's Belgain logic, as opposed to Dutch logic. -- CARL BANKS From maxm at mxm.dk Mon Jan 17 10:01:23 2005 From: maxm at mxm.dk (Max M) Date: Mon, 17 Jan 2005 16:01:23 +0100 Subject: [ANN] iCalendar package 0.9 Message-ID: <41ebd292$0$253$edfadb0f@dread12.news.tele.dk> I have written a package that can parse and generate files according to RFC 2445 (iCalender). That should be any file ending with .ics :-) It is not quite polished yet, but fully functional, and choke full of doctest. It does support the full spec and all datatypes and parameter values. The Api is pretty stable, and will probably not change much. I would like anybody interrested to give it a test drive before I finish it off and make it a 1.0. http://www.mxm.dk/products/public/ical/ Any feedback would be welcome. -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science From reinhold-birkenfeld-nospam at wolke7.net Fri Jan 14 17:06:43 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Fri, 14 Jan 2005 23:06:43 +0100 Subject: Why would I get a TypeEror? In-Reply-To: References: <34ql1vF4dqd9pU1@individual.net> Message-ID: <34qu3jF4br3iqU2@individual.net> Steven Bethard wrote: > It's me wrote: >> Say again??? > > Please stop top-posting -- it makes it hard to reply in context. > >> "Reinhold Birkenfeld" wrote... >>>It's me wrote: >>>>If this is true, I would run into trouble real quick if I do a: >>>> >>>>(1/x,1.0e99)[x==0] >>> >>>Lazy evaluation: use the (x==0 and 1e99 or 1/x) form! > > If you want short-circuting behavior, where only one of the two branches > gets executed, you should use Python's short-circuiting boolean > operators. For example, > > (x == 0 and 1.0e99 or 1/x) > > says something like: > > Check if x == 0. > If so, check if 1.0e99 is non-zero. It is, so return it. > If x != 0, see if 1/x is non-zero. It is, so return it. > > Note that if you're not comfortable with short-circuiting behavior, you > can also code this using lazy evaluation: > > (lambda: 1/x, lambda: 1.0e99)[x==0]() Or even (x==0 and lambda: 1e99 or lambda: 1/x)() Or ... Reinhold From tjreedy at udel.edu Fri Jan 28 18:00:44 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 28 Jan 2005 18:00:44 -0500 Subject: Who should security issues be reported to? References: <1106863164.745581.11920@f14g2000cwb.googlegroups.com><1106911061.429966.303510@f14g2000cwb.googlegroups.com> Message-ID: OP: >>I find this response a bit dissappointing frankly. Open Source people >>make such a big deal about having lots of people being able to look at >>source code and from that discover security problems, thus making it >>somehow making it better than proprietary source code. OP: Did you discover this supposed security hole from black-box observation of behavior or by being one of the 'lots of people being able to look at source code', thereby giving evidence to the point? Everyone: I say 'supposed' because a) The OP has provided no info about his/her claim. b) The OP's original post is a classical troll: blast volunteer developers for not having anticipated and planned for a novel situation; argue against things not said, at least now here, not recently; imply that volunteers own him something. Most people with the expertise to detect a security hole would know better. c) The noise generated because of b) has alerted any malware writers monitering c.l.p for hints about exploitable security holes that there might be one in one of the few modules where such could reasonably be. OP: If my doubts are wrong and you really do have something to quietly report to the 'authority', then do so, and quit making a noise about it. Terry J. Reedy From hcslmf at texlife.com Mon Jan 31 16:35:04 2005 From: hcslmf at texlife.com (brolewis) Date: 31 Jan 2005 13:35:04 -0800 Subject: Spawning, and Killing, a Process Message-ID: <1107207304.586338.270080@c13g2000cwb.googlegroups.com> I am writing a program on Windows (XP Pro) that as part of the application takes advantage of rsync's ability to synchronize a client and server computer. However, because of the nature of our company's policies and our proxy, I must connect using SSH and use it as a tunnel to get to the location I need on the inside. My delimma is that I need to be able to spawn a process that uses the SSH, runs rsync, and then I need to be able to kill the SSH process and do not know a way to do that in Windows. I also would prefer to have SSH run invisible to the end user (no new window) which I get when using spawnl The commands I am running are as follows: SSH Tunnel: ssh ssh_user at proxy.example.com -i file_name -L 873:200.200.60.60:7000 -N Rsync Command: rsync -azv rsync_user at 127.0.0.1::package . I am aware that you should be able to run ssh inside of rsync but there seems to be a problem with the port of rsync that prevents me from accomplishing this. I thank you in advance for any assistance you are able to give. From gmanbauer at gmail.com Fri Jan 7 15:47:17 2005 From: gmanbauer at gmail.com (Gavin Bauer) Date: Fri, 7 Jan 2005 20:47:17 +0000 Subject: DOS problem (simple fix??) Message-ID: My DOS window (running in windows ME) closes the second it finishes running my programs. As you can imagine, this makes it hard to see the results. I've gotten in the habit of putting raw_input("Press enter to exit") at the end of every program, and in addition to being pain in the butt, it often fails to work. Being new to programming in general, I make more mistakes than most people. My programs often have errors before they get to my raw_input command. They then display the error and immediately close. It is naturally a lot easier to fix an error when you know what the error is. This makes debugging even more annoying than it ordinarily would be, if you can imagine that. I've heard that it should be a simple preference fix, but I've asked around and no one seems to know how. Thank you, and please make all answers simple enough to be understood by a highschool student and his father :) . From wcarus at comcast.net Wed Jan 12 08:45:12 2005 From: wcarus at comcast.net (Win) Date: 12 Jan 2005 05:45:12 -0800 Subject: Help Optimizing Word Search In-Reply-To: <1105486769.730769.165710@c13g2000cwb.googlegroups.com> References: <1105486769.730769.165710@c13g2000cwb.googlegroups.com> Message-ID: <1105537512.711823.225530@f14g2000cwb.googlegroups.com> Hi Case. Just in case you're really, truly looking for a fast Scrabble word-search algorithm, the classic AI/CS article here is: Andrew W. Appel and Guy J. Jacobson, The world's fastest Scrabble program, Communications of the ACM, 31(5), pp 572--578, May 1988. You can find a copy of this article at, for example: http://counties.csc.calpoly.edu/~team12fk/F02/acm_worlds_fastest_scrabble_program.pdf This algorithm uses a "dawg" (Directed Acyclic Word Graph). You can find a well-documented example of this data structure implemented in Python in the the WordUtils package: http://cedar-solutions.com/software/wordutils/ Regards, Win From ncoghlan at iinet.net.au Mon Jan 17 05:27:47 2005 From: ncoghlan at iinet.net.au (Nick Coghlan) Date: Mon, 17 Jan 2005 20:27:47 +1000 Subject: Executing a script created by the end user In-Reply-To: <41EAC49E.70209@earthlink.net> References: <41EAC49E.70209@earthlink.net> Message-ID: <41EB9323.3020805@iinet.net.au> Craig Howard wrote: > I am working on a python project where an object will have a script that > can be edited by the end user: object.script > > If the script is a simple one with no functions, I can easily execute it > using: > exec object.script Take a look at the execfile builtin. > But if the object script is a bit more complicated, such as the example > below, my approach does not work: Alternatively: Py> exec """ ... def main(): ... hello1() ... hello2() ... ... def hello1(): ... print 'hello1' ... ... def hello2(): ... print 'hello2' ... """ Py> main() hello1 hello2 'exec' is quite happy to deal with newlines and indenting. Cheers, Nick. -- Nick Coghlan | ncoghlan at email.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.skystorm.net From jelle.feringa at ezct.net Mon Jan 17 04:53:14 2005 From: jelle.feringa at ezct.net (Jelle Feringa // EZCT / Paris) Date: Mon, 17 Jan 2005 10:53:14 +0100 Subject: OCAMl a more natural extension language for python? Message-ID: <20050117095248.90B8F1C015CF@mwinf0507.wanadoo.fr> After reading about extending python with C/Fortran in the excellent Python Scripting for Computational Science book by Hans Langtangen, I'm wondering whether there's not a more pythonic way of extending python. And frankly I think there is: OCAML Fortunately there is already a project up and running allowing you to extend python with OCAMl: http://pycaml.sourceforge.net/ Since I haven't got actual experience programming CAML I'd like to speculate that OCAML would be a very pythonic way of extending python: its open-source, object oriented, as fast as C, and ! garbage collecting! Would making an effort integrating python & CAML not be very worthwhile? I think an effort such as Joe Strouts python2c would be more relevant to a language as CAMl since its conceptually more closer to python (how could you automate programming memory allocation for instance) So my question is: wouldn't there be some serious synergy in bringing python & CAML closer together? ##of course this is speculation, I'm not informed well ##enough to make an educated guess Interested in hearing your thoughts about this matter! Cheers, Jelle. From fredrik at pythonware.com Sat Jan 22 13:55:36 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 22 Jan 2005 19:55:36 +0100 Subject: rotor replacement References: <7x1xcidnp1.fsf@ruckus.brouhaha.com><41EE24F7.7030303@jessikat.fsnet.co.uk><7x1xchlpqv.fsf@ruckus.brouhaha.com><41efeb82$0$27807$9b622d9e@news.freenet.de><41f1a70b$0$25959$9b622d9e@news.freenet.de><7xbrbiqdhk.fsf@ruckus.brouhaha.com><7xllalljah.fsf@ruckus.brouhaha.com><7xekgdmpll.fsf@ruckus.brouhaha.com> <7xpszxcnfa.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Excellent. I hope you will re-read it several times a day. Doing > that might improve your attitude. you really don't have a fucking clue about anything, do you? From beliavsky at aol.com Fri Jan 7 12:38:21 2005 From: beliavsky at aol.com (beliavsky at aol.com) Date: 7 Jan 2005 09:38:21 -0800 Subject: how to extract columns like awk $1 $5 References: Message-ID: <1105119501.289155.264740@z14g2000cwz.googlegroups.com> It takes a few more lines in Python, but you can do something like for text in open("file.txt","r"): words = text.split() print words[4],words[5] (assuming that awk starts counting from zero -- I forget). From lcatalin at siadv.com Wed Jan 5 10:23:50 2005 From: lcatalin at siadv.com (Catalin Lungu) Date: Wed, 5 Jan 2005 16:23:50 +0100 Subject: Image capture Message-ID: Hi, Can anybody help me to implement the following VB code in Python. Thanks in advance. Private Declare Function SendMessage Lib "user32.dll" Alias _ "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, ByVal lParam As Long) As Long Private Const WM_PAINT = &HF Private Const WM_PRINT = &H317 Private Const PRF_CLIENT = &H4& Private Const PRF_CHILDREN = &H10& Private Const PRF_OWNED = &H20& Private Sub Command1_Click() SendMessage grid.hwnd, WM_PAINT, picture.hDC, 0 SendMessage grid.hwnd, WM_PRINT, picture.hDC, PRF_CHILDREN Or PRF_CLIENT Or PRF_OWNED picture.Picture = picture.Image picture.Refresh End Sub Catalin lcatalin at siadv.com From http Sat Jan 8 04:55:03 2005 From: http (Paul Rubin) Date: 08 Jan 2005 01:55:03 -0800 Subject: python3: accessing the result of 'if' References: <3480qqF46jprlU1@individual.net> <1105169372.800346.298830@f14g2000cwb.googlegroups.com> Message-ID: <7xd5wgs0so.fsf@ruckus.brouhaha.com> Nick Coghlan writes: > So let's use it for expression naming in 'if' statements, too. > > if someregexp.match(s) as m: > # blah using m > elif someotherregexp.match(s) as m: > # blah using m Certainly an improvement over what we have now. From jacek.generowicz at cern.ch Mon Jan 10 03:59:18 2005 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 10 Jan 2005 09:59:18 +0100 Subject: Securing a future for anonymous functions in Python References: <1105098890.358721.279550@f14g2000cwb.googlegroups.com> <1105289391.534192.74060@c13g2000cwb.googlegroups.com> Message-ID: "Anna" writes: > With class and def, I at least have a *name* to start with - class > Square pretty obviously is going to have something to do with > geometric shapes, I would hope (or maybe with boring people...). Or maybe with multiplying something by itself. Or maybe the author made some changes in his program, and forgot to rename the class sensibly, and the class' functionality has nothing to do with squares of any sort any more. Or maybe he felt the name "Square" was very appropriate for something else in his program and inadvertently gave the same name to two different entities thereby clobbering the one whose use was intended at this point. > def getfoo() tells me I'm the function is likely to go elsewhere and > get something. It's a *start*, All too often a start in the wrong direction. > a handle, to deciphering whatever the following statements are > doing. (Yes, I realize that often class and function names suck Yup. I waste quite some time because of crappily chosen names. > - but more often than not, they give *some* clue). > > Whereas, with lambda - I have *nothing* to go on. Aaah. OK, you object to lambda because it gives you no clue as to what the function does, rather than with the word "lambda" itself? Is that it? So, IIUC, you consider def add_one(x): return x+1 map(add_one, seq) to be clearer than map(lambda x:x+1, seq) ? > With lambdas, all I know is that the programmer wanted to hide > whatever it is the program is doing behind the curtain... I find this a strange way of looking at it, given that, with lambda, what the program is doing is right there in front of your very eyes at the very point at which it is doing it. Were there a name, _then_ you could argue that the functionality is hidden ... and you would have to look the name up, to make sure that it really represents what you inferred it meant (and, to be absolutely sure, you'd have to double check that it hasn't been rebound by some other part of the program in some nasty way). None of these problems arise with lambda. > IMHO, YMMV, etc etc Of course. Same here. > Personally, I like lambdas less than regular expressions (of which > I'm particularly UNfond but understand their usefulness at > times). At least with regular expressions - I know that the > gibberish I need to decipher (probably) has to do with text > parsing... Hmm, that tells you about as much as lambda does. With lambda you know that the gibberish you need to decipher has to do with functions :-) From skip at pobox.com Wed Jan 26 22:03:07 2005 From: skip at pobox.com (Skip Montanaro) Date: Wed, 26 Jan 2005 21:03:07 -0600 Subject: What's so funny? WAS Re: rotor replacement In-Reply-To: References: <7x1xchlpqv.fsf@ruckus.brouhaha.com> <41efeb82$0$27807$9b622d9e@news.freenet.de> <41f1a70b$0$25959$9b622d9e@news.freenet.de> <7xekgdmpll.fsf@ruckus.brouhaha.com> <7xpszxcnfa.fsf@ruckus.brouhaha.com> <7xllalcmqc.fsf@ruckus.brouhaha.com> <7xbrbhosh7.fsf@ruckus.brouhaha.com> <7xzmz0lw6h.fsf@ruckus.brouhaha.com> <41f4324a$0$1547$9b622d9e@news.freenet.de> <41f589f9$0$3357$9b622d9e@news.freenet.de> <41f6a8ef$0$27790$9b622d9e@news.freenet.de> <41f7efc2$0$11596$9b622d9e@news.freenet.de> Message-ID: <16888.23019.818401.742296@montanaro.dyndns.org> phr> I don't see why you can't make up your mind enough to issue simple phr> statements like "the Python lib should have a module that does phr> so-and-so, and it should meet such-and-such requirements, so if phr> someone submits one that meets the requirements and passes code phr> review and testing and doesn't have unexpected issues or otherwise phr> fail to meet reasonable expectations, we'll use it". Because good requirements specification is difficult and testing improves the breed. Better to have the major API changes and bugs taken care of, and to have its popularity demonstrated *before* it gets into the Python distribution. The best way to do something isn't always obvious at the outset. If multiple solutions exist in the community, everyone benefits. The best survive. The worst don't. If one implementation is prematurely chosen for inclusion in the Python distribution, it stifles the vetting process. Finally, what if, saints be preserved, your whizbang new module is included in the core distribution and it's just not as popular as was first thought? It just winds up as a weight around the maintainers' necks. Once included in the distribution it's difficult to remove. Even rexec and Bastion, which are both known to be inadequate from a security standpoint, are still in the distribution. So, feel free to implement whatever it is you propose. Register it with PyPI, announce it on comp.lang.python.announce, etc. Support it for awhile. Run it through a couple revisions to fix API warts and bugs. When it's the category king and there is substantial community support for inclusion, it will be considered. Python is popular in part because of its fairly conservative development strategy. That goes for the libraries as well as the language itself. Skip From steven.bethard at gmail.com Thu Jan 27 12:58:23 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 27 Jan 2005 10:58:23 -0700 Subject: String Fomat Conversion In-Reply-To: References: <1106801582.417862.293210@c13g2000cwb.googlegroups.com> Message-ID: Stephen Thorne wrote: > I did all I did in the name of clarity, considering the OP was on his > first day with python. How I would actually write it would be: > > inputfile = file('input','r') > inputfile.readline() > data = [map(float, line.split()) for line in inputfile] > > Notice how you don't have to call iter() on it, you can treat it as an > iterable to begin with. Beware of mixing iterator methods and readline: http://docs.python.org/lib/bltin-file-objects.html next( ) ...In order to make a for loop the most efficient way of looping over the lines of a file (a very common operation), the next() method uses a hidden read-ahead buffer. As a consequence of using a read-ahead buffer, combining next() with other file methods (like readline()) does not work right. I haven't tested your code in particular, but this warning was enough to make me generally avoid mixing iter methods and other methods. Steve From unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom Tue Jan 11 17:57:08 2005 From: unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom (=?iso-8859-1?Q?Michel_Claveau_-_abstraction_m=E9ta-galactique_non_trivial?= =?iso-8859-1?Q?e_en_fuite_perp=E9tuelle.?=) Date: Tue, 11 Jan 2005 23:57:08 +0100 Subject: Python & unicode References: <41e30aab$0$6434$8fcfb975@news.wanadoo.fr> <10u6347j23enuc3@news.supernews.com> <34gi0fF4c1lntU1@individual.net> <41e31f50$0$6430$8fcfb975@news.wanadoo.fr> <1105434532.132061.24030@f14g2000cwb.googlegroups.com> <1105434900.511862.54740@f14g2000cwb.googlegroups.com> Message-ID: <41e459e5$0$8025$8fcfb975@news.wanadoo.fr> ;o) Python ==. limits ,===> \________/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From ncoghlan at iinet.net.au Sun Jan 2 00:32:33 2005 From: ncoghlan at iinet.net.au (Nick Coghlan) Date: Sun, 02 Jan 2005 15:32:33 +1000 Subject: when wxPython update to python2.4? In-Reply-To: <41B930B7.4040600@163.com> References: <41B930B7.4040600@163.com> Message-ID: <41D78771.8000404@iinet.net.au> alang_yl wrote: > i can't wait. > wxPython 2.5 already has a version which works with Python 2.4 (grab it from www.wxpython.org). For the wxPython 2.4 series, I understand Robin is planning a release which will both integrate the 2.4 series into the new wxPython versioning scheme, and also include a Python 2.4 compatible version. The timeframe for that isn't entirely clear, though. Cheers, Nick. -- Nick Coghlan | ncoghlan at email.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.skystorm.net From pierre.barbier at cirad.fr Wed Jan 12 08:36:35 2005 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Wed, 12 Jan 2005 14:36:35 +0100 Subject: how to visualize symbol table? In-Reply-To: <41e5220c$0$15240$91cee783@newsreader01.highway.telekom.at> References: <41e5220c$0$15240$91cee783@newsreader01.highway.telekom.at> Message-ID: <41e52772$0$7880$626a14ce@news.free.fr> Thomas Korimort a ?crit : > Hi, > > how can i visualize the content of the symbol table in Python? > Sometimes i want to know which symbols are imported from apackage and > such kind of things > > Greetings, THomas Korimort Do you mean something like : dir(module) ??? Pierre From christian_stengel at yahoo.de Wed Jan 26 11:29:31 2005 From: christian_stengel at yahoo.de (christian_stengel) Date: Wed, 26 Jan 2005 16:29:31 -0000 Subject: unknown protocol error when connecting to an server via ssl Message-ID: Hi *, I have just started to learn python and I am having a problem with an python client connecting to a perl server using ssl (I tried this with pyOpenSSL and with the build in SSL Module). I don't want to check a cerificate, so i simply tried a from OpenSSL import SSL s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(("127.0.0.1", 2000) s.sendall("100 Hello\n") ctx = SSL.Context(SSL.SSLv23_METHOD) ctx.set_verify(SSL_VERIFY_NONE,self.verify_cb) ss = SSL.Connection(ctx,s) ss.set_connect_state() ss.sendall("101 User\n") when writeing the 101 I'll get an SSL23_GET_SERVER_HELLO unknown protocol error. If I don't do the ssl stuff, everything works. I also tried this with the socket.ssl(s,None, None) to get a secure socket - but I got the same error. The server is not written by me - so I can't change that to python. The problem is, that there is first an unencrypted socket, that is converted to a secure socket. the perl (server) code is something like this: # creating a socket $socket = IO::Socket::INET->new(Listen => 5, LocalPort => 2000, Timeout => 15, Resue => 1, Proto => 'tcp'); # some more code # accepting a remote connection $session = $socket->accept; # some more code # convert the Socket to an ssl socket $sslsocket = IO::Socket::SSL::socket_to_SSL($session, SSL_verify_mode => 0x00) # some more code Does anybody know, where the UNKNOWN PROTOCOL error comes from? I have changed the connection Mode to SSLv2_METHOD but this gave me an GET_SERVER_HELLO read wrong packet type error. I have done this with python 2.3.4 under linux - and the perl stuff is done via the IO-Socket-SSL package. Thx, Chris From http Sun Jan 30 17:50:42 2005 From: http (Paul Rubin) Date: 30 Jan 2005 14:50:42 -0800 Subject: ANNOUNCE: KirbyBase 1.7 References: Message-ID: <7xy8ea1qgt.fsf@ruckus.brouhaha.com> Jamey Cribbs writes: > KirbyBase is a simple, plain-text, database management system written > in Python. It can be used either embedded in a python script or in a > client/server, multi-user mode. You use python code to express your > queries instead of having to use another language such as SQL. > KirbyBase is disk-based, not memory-based. Database changes are > immediately written to disk. That's cute, especially the part about using Python expressions instead of SQL to express queries. I don't see anything in the info page about what happens when you have multiple clients updating the db concurrently. Do you make any attempt to handle that? From morphex at gmail.com Wed Jan 12 23:49:56 2005 From: morphex at gmail.com (morphex) Date: 12 Jan 2005 20:49:56 -0800 Subject: Creating text on images Message-ID: <1105591796.422252.190990@f14g2000cwb.googlegroups.com> Hi all, I'm trying to create a script that will superimpose text on an image. I didn't find any great examples out there on how this can be done (I presume using PIL is necessary), do you know of any examples? Thanks, Morten From peter at engcorp.com Thu Jan 13 08:37:50 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 13 Jan 2005 08:37:50 -0500 Subject: pyserial and com port interrupts In-Reply-To: <24lbu0htudrc9ir4b0na3r1m6g09qlbck4@4ax.com> References: <24lbu0htudrc9ir4b0na3r1m6g09qlbck4@4ax.com> Message-ID: engsol wrote: > I'm working on a s/w test program using python > code. Com1 and com2 play a part. The problem is that the python code > has a lot of work to do...and the results from the hardware under test can > come from either com1 or com2...at any time. It may be a few milliseconds, > or several seconds, sometimes minutes, before a response is expected. > I'm not sure what timeout value I'd use. Using threads, and re-loading the > timeout values on the fly may be a solution, but I'm not experienced with > threads....and was hoping to avoid them. I'm with Grant on this: threads in Python are really easy. If you can describe a little more about what you need/would like to do with the serial data when it *does* arrive, and how that relates to the "lot of work" that the rest of the code is doing, I'm sure there are a number of helpful replies just waiting to be written to convince you how easy it really is. For example, if you need to retrieve the data from the serial ports right away, so the sending device doesn't block or lose data, but can afford to just store it for later processing when the main thread has time, that's only a few lines of code. If you actually want to reply immediately, then the only real question is how you come up with the reply. If it needs data from the main thread, we can show you several easy and appropriate ways to do that with no thread safety issues. If you're not experienced with threads, there's almost no place better to start learning than with Python and c.l.p. :-) -Peter From michele.simionato at gmail.com Wed Jan 5 22:42:08 2005 From: michele.simionato at gmail.com (michele.simionato at gmail.com) Date: 5 Jan 2005 19:42:08 -0800 Subject: Python evolution: Unease In-Reply-To: <7xzmzo6qk0.fsf@ruckus.brouhaha.com> References: <7xacrpdxy3.fsf@ruckus.brouhaha.com> <7x652che6z.fsf@ruckus.brouhaha.com> <1104910363.381748.105670@z14g2000cwz.googlegroups.com> <7xzmzo6qk0.fsf@ruckus.brouhaha.com> Message-ID: <1104982928.527510.29630@z14g2000cwz.googlegroups.com> Did you used Tkinter and Tix? Most of my problems were there. Of course, I also got in trouble when upgrading to Python 2.2 from 1.5.2 Finally they switched to Python 2.2, but at that moment Python 2.3 came out and I got tired. I switched to Mandrake 1.5 and I am happy with it. Never had any serious trouble with urpmi and lots of Python packages are available. Michele Simionato From woetzel at AUTO Wed Jan 19 05:08:18 2005 From: woetzel at AUTO (Gerd Woetzel) Date: 19 Jan 2005 12:08:18 +0200 Subject: rotor replacement References: <7x1xcidnp1.fsf@ruckus.brouhaha.com> <41EE24F7.7030303@jessikat.fsnet.co.uk> Message-ID: <41ee3fa2$1@news.fhg.de> Robin Becker writes: >Paul Rubin wrote: >.....I'm also missing the rotor module and regret that something useful >was warned about and now removed with no plugin replacement. Hm, yes. Here is a (rather slow) replacement: """This module is derived from Modules/rotormodule.c and translated into Python. I have appended the Copyright by Lance Ellinghouse below. The rotor module has been removed from the Python 2.4 distribution because the rotor module uses an insecure algorithm and is deprecated. ============================================================== Of course, this does still hold. However, I think this module might be used and adapted for demonstration purposes and might help some poor users who have encrypted (or obfuscated) some old stuff with the rotor module and have no access to older Python versions any more. Documentation can be found in Python Library Reference, Guido van Rossum, Fred L. Drake, Jr., editor, PythonLabs, Release 2.3.4 May 20, 2004 ##################################################################### Copyright 1994 by Lance Ellinghouse, Cathedral City, California Republic, United States of America. All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Lance Ellinghouse not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. LANCE ELLINGHOUSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL LANCE ELLINGHOUSE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ##################################################################### """ class newrotor(object): def __init__(self, key, n_rotors=6): self.n_rotors = n_rotors self.setkey(key) def setkey(self, key): self.key = key self.rotors = None self.positions = [None, None] def encrypt(self, buf): # Reset (encrypt) positions and encryptmore self.positions[0] = None return self.cryptmore(buf, 0) def encryptmore(self, buf): return self.cryptmore(buf, 0) def decrypt(self, buf): # Reset decrypt positions and decryptmore self.positions[1] = None return self.cryptmore(buf, 1) def decryptmore(self, buf): return self.cryptmore(buf, 1) def cryptmore(self, buf, do_decrypt): size, nr, rotors, pos = self.get_rotors(do_decrypt) outbuf = [] append = outbuf.append for c in map(ord, buf): if do_decrypt: # Apply decrypt rotors and xor in reverse order for i in xrange(nr-1,-1,-1): c = pos[i] ^ rotors[i][c] else: # Apply xor and ecrypt rotors for i in xrange(nr): c = rotors[i][c ^ pos[i]] append(c) # Advance rotors, i.e. add the (fixed) rotor increments to the # variable rotor positions with carry. # Note: In the C-implementation, the result of the carry addition # was stored to an "unsigned char". Hence the next carry # is lost if pos[i] == size-1 and pnew >= size. # Masking with 0xff simulates this behavior. # pnew = 0 # (pnew >= size) works as "carry bit" for i in xrange(nr): pnew = ((pos[i] + (pnew >= size)) & 0xff) + rotors[i][size] pos[i] = pnew % size return ''.join(map(chr, outbuf)) def get_rotors(self, do_decrypt): # Return a tuple (size, nr, rotors, positions) where # - size is the rotor size (== 256, because of 8-bit bytes) # - nr is the number of rotors. # - rotors is a tuple of nr encrypt or nr decrypt rotors # for do_decrypt == 0 or do_decrypt == 1 respectively. # - postions is a list of nr "rotor positions". # # The rotors represent the static aspect of the rotor machine which # is initially computed from key and fixed during en/decryption. # A rotor is a random permutation of range(size) extended # by an "increment value" in range(size). # # The followng statements hold for a tuple of encrypt rotors E and # and the corresponding tuple of decrypt rotors D. # # D[i][E[i][j]] == j for i in range(nr) for j in range(size) # # E[i][D[i][j]] == j for i in range(nr) for j in range(size) # # This means that the corresponding rotors E[i] and D[i] are # inverse permutations. # The increments are equal for the corresponding encrypt and # decrypt rotors and have an odd value: # # D[i][size] == E[i][size] and E[i][size] == 1 mod 2 and # 0 < E[i][size] < size for i in range(nr) # # The position vector represents the dynamic aspect. # It changes after each en/decrypted character (the rotors # are "advanced"). The initial position vector is also computed # from the key # nr = self.n_rotors rotors = self.rotors positions = self.positions[do_decrypt] if positions is None: if rotors: positions = list(rotors[3]) else: # Generate identity permutation for 8-bit bytes plus an # (unused) increment value self.size = size = 256 id_rotor = range(size+1) # Generate nr "random" initial positions and "random" # en/decrypt rotors from id_rotor. # rand = random_func(self.key) E = [] D = [] positions = [] for i in xrange(nr): i = size positions.append(rand(i)) erotor = id_rotor[:] drotor = id_rotor[:] drotor[i] = erotor[i] = 1 + 2*rand(i/2) # increment while i > 1: r = rand(i) i -= 1 er = erotor[r] erotor[r] = erotor[i] erotor[i] = er drotor[er] = i drotor[erotor[0]] = 0 E.append(tuple(erotor)) D.append(tuple(drotor)) self.rotors = rotors = ( tuple(E), tuple(D), size, tuple(positions)) self.positions[do_decrypt] = positions return rotors[2], nr, rotors[do_decrypt], positions def random_func(key): # Generate a random number generator that is "seeded" from key. # This algorithm is copied from Python2.3 randommodule.c. # mask = 0xffff x=995 y=576 z=767 for c in map(ord, key): x = (((x<<3 | x>>13) + c) & mask) y = (((y<<3 | y>>13) ^ c) & mask) z = (((z<<3 | z>>13) - c) & mask) # Emulate (unintended?) cast to short maxpos = mask >> 1 mask += 1 if x > maxpos: x -= mask if y > maxpos: y -= mask if z > maxpos: z -= mask y |= 1 # avoid very bad seed, why not for x and z too? # Oh, dear, for compatibility, we must evaluate the first seed transition # the hard way, later it becomes much simpler x = 171 * (x % 177) - 2 * (x/177) y = 172 * (y % 176) - 35 * (y/176) z = 170 * (z % 178) - 63 * (z/178) if x < 0: x += 30269 if y < 0: y += 30307 if z < 0: z += 30323 # At least all values are > 0 by now but may be greater than expected .. def rand(n, seed=[(x, y, z)]): # Return a random number 0 <= r < n # x, y, z = seed[0] seed[0] = ((171*x) % 30269, (172*y) % 30307, (170*z) % 30323) return int((x/30269.0 + y/30307.0 + z/30323.0) * n) % n # Original code was like this: # from math import floor # val = x/30269.0 + y/30307.0 + z/30323.0 # val = val - floor(val) # if val >= 1.0: # val = 0.0 # n = int(val*n) % n return rand From aahz at pythoncraft.com Sun Jan 9 19:26:59 2005 From: aahz at pythoncraft.com (Aahz) Date: 9 Jan 2005 19:26:59 -0500 Subject: Old Paranoia Game in Python References: <2005010903390916807%spk00@coxnet> <5JcEd.1988$KJ2.907@newsread3.news.atl.earthlink.net> Message-ID: In article , Lucas Raab wrote: >Aahz wrote: >> In article <5JcEd.1988$KJ2.907 at newsread3.news.atl.earthlink.net>, >> Lucas Raab wrote: >>>Sean P. Kane wrote: >>>> >>>>Equipment: Red Reflec Armour, Laser Pistol, Laser Barrel (red), >>>> Notebook & Stylus, Knife, Com Unit 1, Jump suit, >>>> Secret Illuminati Eye-In-The-Pyramid(tm) Decoder ring, >>>> Utility Belt & Pouches >>> >>>The Illuminati really have infiltrated our society. >> >> Stay alert! >> Trust no one! >> Keep your laser handy! > >Well, I really meant "Secret Illuminati Eye-In-The-Pyramid(tm) Decoder >ring", but if you wanted to go in another direction... Trust the computer, the computer is your friend. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "19. A language that doesn't affect the way you think about programming, is not worth knowing." --Alan Perlis From tmohr at s.netic.de Fri Jan 14 01:23:53 2005 From: tmohr at s.netic.de (Torsten Mohr) Date: Fri, 14 Jan 2005 07:23:53 +0100 Subject: reference or pointer to some object? References: Message-ID: Hi, thank you all for your explanations. That's really great and helps me a lot. Thanks, Torsten. From toop82 at comcast.net Tue Jan 25 00:01:08 2005 From: toop82 at comcast.net (Robert Toop) Date: Tue, 25 Jan 2005 00:01:08 -0500 Subject: error References: Message-ID: http://www.python.org/2.4/bugs.html ...suggests that firewall running on python host (read Windows software firewall) may block the localhost TCP connection required between IDLE parent and child processes. I don't think this problem is specific to python 2.4. IDLE should work if you change firewall config to allow local (i.e. intramural) TCP connections. HTH /old goat/ "me" wrote in message news:RAfJd.37$587.2870 at news.uswest.net... > whenever i try and run my Python GUI, my computer thinks for a sec, then > drops the process, without ever displaying the window. the command prompt > window seems to work fine, but the IDLE GUI won't start. > > i'm running Windows 2K professional and python 2.4, so any advice help would > be appreciated. i've already tried reinstalling and use a thread response, > as the e-mail on this account is bogus. > > From petite.abeille at gmail.com Fri Jan 28 18:21:16 2005 From: petite.abeille at gmail.com (PA) Date: Sat, 29 Jan 2005 00:21:16 +0100 Subject: what's OOP's jargons and complexities? In-Reply-To: <1106953849.915440.134710@f14g2000cwb.googlegroups.com> References: <1106953849.915440.134710@f14g2000cwb.googlegroups.com> Message-ID: On Jan 29, 2005, at 00:10, Xah Lee wrote: > Tomorrow i shall cover more manmade jargons and complexities arising > out of the OOP hype, in particular Java. Good read. Keep them coming :) Cheers -- PA, Onnay Equitursay http://alt.textdrive.com/ From tundra at tundraware.com Fri Jan 7 05:28:31 2005 From: tundra at tundraware.com (Tim Daneliuk) Date: 07 Jan 2005 05:28:31 EST Subject: Tkinter Puzzler Message-ID: I am trying to initialize a menu in the following manner: for entry in [("Up", KeyUpDir), ("Back", KeyBackDir), ("Home", KeyHomeDir), ("Startdir", KeyStartDir), ("Root", KeyRootDir)]: func = entry[1] UI.ShortBtn.menu.add_command(label=entry[0], command=lambda: func(None)) However, at runtime, each of the menu options binds to the *last* function named in the list (KeyStartDir). Explicitly loading each entry on its own line works fine: UI........command=lambda:KeyWHATEVERDir(None) Any ideas why the first form does not fly? TIA, ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From apardon at forel.vub.ac.be Wed Jan 19 09:40:24 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 19 Jan 2005 14:40:24 GMT Subject: lambda References: <1105633239.316956.262140@f14g2000cwb.googlegroups.com> <41EBA021.5060903@holdenweb.com> <41ed8c13.1209309354@news.oz.net> Message-ID: Op 2005-01-19, Nick Coghlan schreef : > Antoon Pardon wrote: > > I can be wrong, but until now I have seen no indication that I was >> using mutable and immutable differently than other people. AFAICT >> we all refer to whether an object belongs to a mutable or immutable >> class. > > The difference is that when you take a copy of the key and stick it in the > dictionary, such that the dictionary now holds the *sole* reference to that key, > you have made that key *effectively* immutable. > > This is why no-one really batted an eyelid when you mentioned that mutable keys > can be used safely by making a copy - doing so makes the key *effectively* > immutable, and means that modifying the original key object (i.e. the > application's copy, not the dict's copy), and reusing it to look up in the > dictionary is likely to give a KeyError. > > These semantics would be understandably surprising to many users, and hence, are > not supplied by default. This seems like circle reasoning. The reason why these semantics would be surprising is that those are not the semantics supplied. > Additionally, a dictionary's keys are accessible via its API. Accordingly, to > preserve this 'effective immutability', making a copy on key input is > insufficient - keys must be copied on *output* as well (that is, dict.keys, > dict.items etc must return *copies* of the key objects, not the key objects > themselves). Yes I haven been thinking about this too. I also think not making a copy on output is less dangerous than not making a copy on input. > Since there is no reliable way in Python to tell if an object is mutable or not > (the closest equivalent is the presence of __hash__, which clearly can't be used > in this example), this copying would need to be done for *every* object. > > Alternately, the dictionary can say to the API clients, "make an immutable copy > and supply that instead. It is left to API clients to decide how best to make > the immutable version". The API client copies the key once (to make the > immutable version), and everyone lives happily ever after. > > For example: > > Py> class mylist(list): > ... def __init__(self, arg): > ... super(mylist, self).__init__(arg) > ... self._tuple = None > ... def frozen(self): > ... if self._tuple is None: > ... self._tuple = tuple(self) > ... return self._tuple > ... def unfreeze(self): > ... self._tuple = None > ... > Py> x = mylist(range(10)) > Py> x > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > Py> x.frozen() > (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) > Py> x.append(10) > Py> x.frozen() > (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) > Py> x.unfreeze() > Py> x.frozen() > (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) > > This is much safer than having a list subclass that implements __hash__, and > still lets you avoid redundant copy operations. > > Nicely, so long as you don't unfreeze the object you used to key the dictionary, > reusing the same object will always get you the correct dictionary entry, and > two lists that compare equal at the time they are frozen will also get you the > same dictionary entry. The equivalent tuples can be used for the lookup, too. Interesting idea. But I think you are wrong when you say that two lists that compare equal at the time they are frozen, will get the same dictionary entry. The problem is an object must compare equal to the key in the dictionary to get at the same entry. So if you freeze a list and its copy but then mutate them differently, they no longer are equal and so wont get you at the same entry. [ Rest snipped, this is getting into a semantic debate on what 'mutable' means. This may be interesting enough on its own but I feel it detracts too much from what I consider the more important issue. ] -- Antoon Pardon From john at grulic.org.ar Mon Jan 17 14:23:27 2005 From: john at grulic.org.ar (John Lenton) Date: Mon, 17 Jan 2005 16:23:27 -0300 Subject: strange note in fcntl docs In-Reply-To: <16875.54085.712019.524951@montanaro.dyndns.org> References: <20050117053949.GA28456@grulic.org.ar> <16875.54085.712019.524951@montanaro.dyndns.org> Message-ID: <20050117192327.GA4723@grulic.org.ar> On Mon, Jan 17, 2005 at 09:01:25AM -0600, Skip Montanaro wrote: > > I could have sworn that os.open supported the O_SHLOCK and O_EXLOCK flags. > I'm pretty sure I've used them in the past, but don't see them now. (They > aren't in 2.2 either.) > > If you try this: > > O_SHLOCK = 0x0010 > O_EXLOCK = 0x0020 > > (those are the definitions on my Mac - YMMV) does > > os.open("somefile", O_SHLOCK|) > > work? I grepped for O_..LOCK in /usr/include on my linux computer and came up barehanded. The flags you mention are not, AFAIK, part of POSIX (the open(3posix) manpage does not list them). And, even if they were, the note is *still* wrong and misleading: fcntl is available on Windows, and os.open's flags won't be. from http://www.daemon-systems.org/man/open.2.html, I gather that O_..LOCK are a BSD extension, which is why you have then on the Mac. But they do *not* belong in posix; they belong in os for your platform, and the note in fcntl should be removed. The only way this wouldn't be true is if os.open is extended to understand O_..LOCK, and call out to flock as needed. That would go against what I understand is the essence of os.open (i.e., a direct road to open(2)). Hmm, if the above sounds a little harsh, sprinkle :)s in. I've had too little sleep. -- John Lenton (john at grulic.org.ar) -- Random fortune: If you're right 90% of the time, why quibble about the remaining 3%? -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From fperez.net at gmail.com Tue Jan 25 12:37:34 2005 From: fperez.net at gmail.com (Fernando Perez) Date: Tue, 25 Jan 2005 10:37:34 -0700 Subject: Installer made with bdist_wininst segfaulting... References: Message-ID: Hi Thomas, Thomas Heller wrote: > Fernando Perez writes: >> Here is a brief summary: if the installer file is run from a windows drive >> which is different from the one where python resides (and hence where >> ipython will >> end up), the installer segfaults. No traceback, nothing, just a segfault >> (well, one of those Windows dialogs asking me to send a binary traceback to >> Redmond, but not a proper Python traceback). > > There are a couple of known bugs in bdist_wininst, and you just reported > another one. All these bugs are related to using the > post_install_script, and show up when either (thats what I currently > remember): [...] many thanks for following up on this. In my case, I realized I could avoid the chdir() call and things were then OK. But it's good to see the bug fixed. Best regards, f From roy at panix.com Fri Jan 7 20:43:03 2005 From: roy at panix.com (Roy Smith) Date: Fri, 07 Jan 2005 20:43:03 -0500 Subject: EOF for binary? References: <1105147072.909665.242360@z14g2000cwz.googlegroups.com> Message-ID: In article <1105147072.909665.242360 at z14g2000cwz.googlegroups.com>, "flamesrock" wrote: > Hi, > > So if I understand correctly, there are NO eof characters in any binary > file. If so, is there an easier way to check for the end of the file > than: > > os.path.getsize(infile) <= infile.tell() How you detect EOF depends on how you're reading the file. For example, read() indicates EOF by returning fewer characters than you asked for (possibly zero). Checking the length of a file is perilous. Files change size. File sizes don't have much meaning on things like network sockets to begin with. From mahs at telcopartners.com Tue Jan 25 19:03:11 2005 From: mahs at telcopartners.com (Michael Spencer) Date: Tue, 25 Jan 2005 16:03:11 -0800 Subject: limited python virtual machine (WAS: Another scripting language implemented into Python itself?) In-Reply-To: References: Message-ID: Cameron Laird wrote: > In article , > Michael Spencer wrote: > . > . > . > >>Right - the crux of the problem is how to identify dangerous objects. My point >>is that if such as test is possible, then safe exec is very easily implemented >>within current Python. If it is not, then it is essentially impossible. >> > > > > I'll suggest yet another perspective: add another indirection. > As the virtual machine becomes more available to introspection, > it might become natural to define a *very* restricted interpreter > which we can all agree is safe, PLUS a means to extend that > specific instance of the VM with, say, new definitions of bindings > for particular AST nodes. Then the developer has the means to > "build out" his own VM in a way he can judge useful and safe for > his own situation. Rather than the Java there-is-one-"safe"-for- > all approach, Pythoneers would have the tools to create safety. That does sound good. And evolutionary, because the very restricted VM could be implemented today (in Python), and subsequently PyPy (or whatever) could optimize it. The safe eval recipe I referred to earlier in the thread is IMO a trivial example of of this approach. Of course, its restrictions are extreme - only constant expressions, but it is straightforwardly extensible to any subset of the language. The limitation that I see with this approach is that it is not, in general, syntax that is safe or unsafe (with the notable exception of 'import' and its relatives). Rather, it the library objects, especially the built-ins, that present the main source of risk. So, if I understand your suggestion, it would require assessing the safety of the built-in objects, as well as providing an interpreter that could control access to them, possibly with fine-grain control at the attribute level. M From timj at tolisgroup.com Mon Jan 17 14:22:44 2005 From: timj at tolisgroup.com (brucoder) Date: 17 Jan 2005 11:22:44 -0800 Subject: Adjusting the 1024 byte stdin buffer limit References: <1105989047.516986.59990@z14g2000cwz.googlegroups.com> Message-ID: <1105989764.168794.113430@z14g2000cwz.googlegroups.com> Currently, when sending a data stream that exceeds 1024 bytes via stdin, the stream blocks at the 1024th byte. This precludes completion of the submission of the data stream. Tim From klapotec at chello.at Thu Jan 6 19:27:33 2005 From: klapotec at chello.at (Christopher Koppler) Date: Fri, 07 Jan 2005 00:27:33 GMT Subject: Python Operating System??? References: <10trb0mgiflcj4f@corp.supernews.com> <1105056774.393244.199250@f14g2000cwb.googlegroups.com> Message-ID: On Thu, 06 Jan 2005 16:12:54 -0800, Carl Banks wrote: > Arich Chanachai wrote: >> But >> then again, if you don't like C++, you probably won't like Java. > They >> can be very different languages, but in my experience, the reasons > why >> one does not like C++ is usually due to a quality/flaw that can also > be >> found in Java. > > Oh, brother. > > The Zen of Python says that "simple is better than complex" and > "complex is better than complicated". Java does pretty well here. C++ > didn't even get "complicated is better than convoluted" right. There's > are a ton of flaws in C++ not found in Java. Still, Java feels like C++ done right, while being more wrong >:-[ -- Christopher If there was a scheme for Lisp world domination... From michele.simionato at gmail.com Wed Jan 5 22:31:53 2005 From: michele.simionato at gmail.com (michele.simionato at gmail.com) Date: 5 Jan 2005 19:31:53 -0800 Subject: Python evolution: Unease In-Reply-To: <10to8qulnc3vke1@news.supernews.com> References: <7xacrpdxy3.fsf@ruckus.brouhaha.com> <7x652che6z.fsf@ruckus.brouhaha.com> <7xoeg4txrp.fsf@ruckus.brouhaha.com> <1104895842.200010.42720@z14g2000cwz.googlegroups.com> <7xhdlwh5qs.fsf@ruckus.brouhaha.com> <10to8qulnc3vke1@news.supernews.com> Message-ID: <1104982313.217034.308760@z14g2000cwz.googlegroups.com> John Roth: > The bottom line is that I'm not going to be writing any > extensive pieces of Python documentation. My time > is better spent elsewhere. Well, a couple of years ago I realized that some documentation on the MRO was missing. I wrote a document in reST, posted here, and Guido put it on python.org. It was as easy as it sounds. So I don't see your problem. Dave Kulhman wrote some utility to convert reST in latex using the same style of the standard library docs; I haven't used it myself, but you may check with him: http://www.rexx.com/~dkuhlman/ P.S. since you cite descriptors, what's wrong with Raimond Hetting documentation? http://users.rcn.com/python/download/Descriptor.htm The only problem I see is that it is not integrated with the official docs, but this is a minor issue, I think. Michele Simionato From rnd at onego.ru Tue Jan 4 09:06:45 2005 From: rnd at onego.ru (Roman Suzi) Date: Tue, 4 Jan 2005 17:06:45 +0300 (MSK) Subject: Python evolution: Unease In-Reply-To: References: Message-ID: On Tue, 4 Jan 2005, Batista, Facundo wrote: Maybe OP doesn't yet fully comprehend the ways of Python universe? As for his claims, I am quite surprised that Python lacks something in the docs. Concerning better hierarchy in the standard library, it is interesting that there are some movements in this direction: xml package, email package, etc. Probably Iwan thinks that letting more "hierachiesness" into std lib Python will be "cleaner". Yes, it will probably look "more organized" this way, but I do not like the idea: import time.time import time.calendar ... import web.url.openers import net.http ... import datatypes.string import textprocessing.re etc. > [Iwan van der Kleyn] > > #- need: a better standard ide, an integrated db interface with > #- a proper > #- set of db drivers (!!), a better debugger, a standard widget/windows > #- toolkit, something akin to a standard for web programming, better > #- documentation, a standard lib which is better organized, a > #- formalized > #- set of protocols and patterns for program construction. And an > #- interpreter which is fast enough to avoid using C or Pyrex in most > #- obvious cases. > > Let's take one by one: > > - IDE: Better than what? Than IDLE? Than Eclipse? Than SPE? Than Pythonwin? > > - Integrated DB interface with a proper set of db drivers (what means the > "!!"?): What do you mean with an integrated db interface? An standard API to > access different DB engines? Something like the Database API specification > (http://www.python.org/topics/database/DatabaseAPI-2.0.html)? There's a SIG > on DB at http://www.python.org/sigs/db-sig/ you may want to look at. > Regarding drivers, to what DB do you miss one? > > - Debugger: Again, better than what? I use the debugger in IDLE and it's > pretty ok. > > - Standard widget/windows toolkit: More standard than Tk? > > - Something akin to a standard for web programming: specifically? > > - Better documentation: Did you find *any* issue in the docs? And why you > didn't post a bug on that? > > - Better organization of the std lib: What do you propose (specifically)? > Please, in your proposal, take in consideration migration plans and how the > migration affect actual systems. And of course, why the new organization is > better than the old one. BTW, I also think that it should be better > organized, but don't know how. > > - a formalized set of protocols and patterns for program construction: a > what? > > - an interpreter which is fast enough to avoid using C or Pyrex in most > obvious cases: CPython is More Than Fast Enough. In which obvious cases it's > not enough for you? > > Don't misinterpret this response. I know it was a rambling. But *maybe* you > have something to contribute to Python development, even good ideas only and > no work. > > . Facundo Sincerely yours, Roman A.Suzi -- - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru - From zathras at thwackety.com Sun Jan 2 20:13:04 2005 From: zathras at thwackety.com (Michael Sparks) Date: Mon, 3 Jan 2005 01:13:04 +0000 (GMT) Subject: PEP 288 ponderings In-Reply-To: <41D794BA.8090408@colorstudy.com> Message-ID: On Sun, 2 Jan 2005, Ian Bicking wrote: > Steven Bethard wrote: > > PEP 288 was mentioned in one of the lambda threads and so I ended up > > reading it for the first time recently. I definitely don't like the > > idea of a magical __self__ variable that isn't declared anywhere. It > > also seemed to me like generator attributes don't really solve the > > problem very cleanly. An example from the PEP[1]: > > > > def mygen(): > > while True: > > print __self__.data > > yield None > > > > g = mygen() > > g.data = 1 > > g.next() # prints 1 > > g.data = 2 > > g.next() # prints 2 > > I don't get why this isn't good enough: > > def mygen(data): > while True: > print data[0] > yield None It's OK, but rather limited. IMHO a nicer approach is to use decorators to decorate a generator with extra attributes. Specifically to embed the generator inside an iterator inside an anonymous class. (We're exploring this as a alternative approach to the system we currently use at work) (Hmm... Now I describe it that sounds rather hideous, but the result is nice) First of all the decorator: import copy def wrapgenerator(bases=object, **attrs): def decorate(func): class statefulgenerator(bases): __doc__ = func.__doc__ def __init__(self,*args): super(statefulgenerator, self).__init__(*args) self.func=func(self,*args) for k in attrs.keys(): self.__dict__[k] = copy.deepcopy(attrs[k]) self.next=self.__iter__().next def __iter__(self): return iter(self.func) return statefulgenerator return decorate This would be used thus: @wrapgenerator(component) def forwarder(self): # The generator, note the explicit self for local state # for this generator "Simple data forwarding generator" while 1: if self.dataReady("inbox"): self.send("outbox",self.recv("inbox")) elif self.dataReady("control"): if self.recv("control") == "shutdown": break yield 1 self.send("signal","shutdown") yield 0 This clearly assumes a set of attributes, local methods etc. In this case our local methods, attribute etc are from this class: class component(object): def __init__(self, *args): # Default queues self.queues = {"inbox":[],"control":[],"outbox":[],"signal":[]} def send(self, box, object): self.queues[box].append(object) def dataReady(self,box): return len(self.queues[box])>0 def recv(self, box): # NB. Exceptions aren't caught X=self.queues[box][0] del self.queues[box][0] return X This then gets used in the usual way: >>> f = forwarder() >>> f <__main__.statefulgenerator object at 0x402dcccc> >>> f.send("inbox", "some data") >>> f.send("inbox", "some more data") >>> f.next() 1 >>> f.next() 1 >>> f.recv("outbox") 'some data' >>> f.recv("outbox") 'some more data' If you "just" want (arbitrary) generator attributes, then that's a lot easier (since we don't need to support an arbitrary base class): import copy def add_attrs_to_generator(**attrs): def decorate(func): class statefulgenerator: __doc__ = func.__doc__ def __init__(self,*args): self.func=func(self,*args) for k in attrs.keys(): self.__dict__[k] = copy.deepcopy(attrs[k]) self.next=self.__iter__().next def __iter__(self): return iter(self.func) return statefulgenerator return decorate @add_attrs_to_generator() def simpleGen(self): while True: print dir(self) yield None We can also add default attributes: @add_attrs_to_generator(test=1,simple=2) def simpleGen(self): while True: print dir(self) yield None >>> g=simpleGen() >>> g.next() ['__doc__', '__init__', '__iter__', '__module__', 'func', 'next', 'simple', 'test'] We've been using this general approach of giving generators local state for communications for a while now, and it's been rather interesting/fun to use. However we've been using explicit declaration of a class, and then a standard fixed name for the generator (main) instead. (we've been thinking about using decorators as syntactic sugar) Being able to pass exception in would be very nice, however we've used a "control" attribute, queue in practice, to allow for need to be able to shutdown an arbitrary generator. However, I don't think the __self__ part of the PEP is explicitly required - since you can build that onto generators using python quite happily now (@add_attrs_to_generator). The code for the stuff we're playing with (in case anyone's interested :) is at http://kamaelia.sourceforge.net/. The specific subsystem that uses this approach has been released as a separate download (Axon[1]) on the sourceforge project page[2], and the main system (obviously) uses this heavily and can be browsed via viewcvs. [3] [1] http://kamaelia.sourceforge.net/Docs/Axon.html [2] http://sourceforge.net/projects/kamaelia [3] http://cvs.sourceforge.net/viewcvs.py/kamaelia/Code/Python/Kamaelia/Kamaelia/ Best Regards, Michael. From peter at engcorp.com Mon Jan 10 19:32:48 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 10 Jan 2005 19:32:48 -0500 Subject: exceptions and items in a list In-Reply-To: References: <34g8i6F4ad39oU1@individual.net> Message-ID: <3r-dnftx4-syg37cRVn-uQ@powergate.ca> rbt wrote: > Andrey Tatarinov wrote: >> # skip bad object and continue with others >> for object in objects: >> try: >> #do something to object >> except Exception: >> pass > > Thanks Andrey. That's a great example of how to do it. Actually, it's not really a "great" example, since it catches _all_ exceptions that might happen, and quietly ignores them. For example, in the following code, you might not realize that you've made a typo and none of the items in the list are actually being checked, even though there is obviously no problem with any of these simple items (integers from 0 to 9). def fornat_value(val): return '-- %5d --' % val L = range(10) for val in L: try: print format_value(val) except Exception: pass It's almost always better to identify the *specific* exceptions which you are expecting and to catch those, or not do a simple "pass". See Vincent's response, for example, where he explicitly asks only for ValueErrors and lets others propagate upwards, to be reported. (I realize these were contrived examples, but examples that don't mention this important issue risk the propagation of buggy code...) -Peter From ncoghlan at iinet.net.au Thu Jan 20 05:32:12 2005 From: ncoghlan at iinet.net.au (Nick Coghlan) Date: Thu, 20 Jan 2005 20:32:12 +1000 Subject: Zen of Python In-Reply-To: <7xekggbrns.fsf@ruckus.brouhaha.com> References: <972ec5bd050119111359e358f5@mail.gmail.com> <797fe3d405011911465ab59acd@mail.gmail.com> <1106177050.630141.33090@c13g2000cwb.googlegroups.com> <972ec5bd0501191641166972b0@mail.gmail.com> <7xis5szpdj.fsf@ruckus.brouhaha.com> <7xekggbrns.fsf@ruckus.brouhaha.com> Message-ID: <41EF88AC.9030703@iinet.net.au> Paul Rubin wrote: > But it's often predictable at the > beginning what the final destination is going to be. So once we can > see where it's going, why not proceed to the finish line immediately > instead of bothering with the intermediate steps? Because getting there incrementally helps to make sure you end up with the features you need, without the irrelevant baggage an overengineered solution may bring with it. Cheers, Nick. -- Nick Coghlan | ncoghlan at email.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.skystorm.net From gurpreet.sachdeva at gmail.com Thu Jan 6 04:15:24 2005 From: gurpreet.sachdeva at gmail.com (Gurpreet Sachdeva) Date: Thu, 6 Jan 2005 14:45:24 +0530 Subject: file.readlines() - gives me error (bad file descriptor) In-Reply-To: <2b7d8b420501060057270f1878@mail.gmail.com> References: <1104992568.755808.326490@f14g2000cwb.googlegroups.com> <003801c4f3b9$af17fa20$0800a8c0@vishnu> <2b7d8b42050105232546083758@mail.gmail.com> <2b7d8b420501060057270f1878@mail.gmail.com> Message-ID: On Thu, 6 Jan 2005 14:27:40 +0530, Binu K S wrote: > I'm sorry, I didn't get what you trying to say here. Where do you see > a read altering the file? An example might help. Please try: logfile=file(r'test.txt','w+') logfile.write('datetime') Check the contents of test.txt, you will get what ever was required... Now Run: logfile=file(r'test.txt','w+') logfile.write('datetime') logfile.readlines() and check the contents of test.txt??? My doubt is that logfile.write('datetime') will write datetime that is universaly accepted but why all that junk is appending to that when I add logfile.readlines() Strange or Am I on drugs??? :o) Please Comment... Garry From bokr at oz.net Thu Jan 6 13:58:59 2005 From: bokr at oz.net (Bengt Richter) Date: Thu, 06 Jan 2005 18:58:59 GMT Subject: Python evolution: Unease References: <7xacrpdxy3.fsf@ruckus.brouhaha.com> <7x652che6z.fsf@ruckus.brouhaha.com> <7x4qhw859p.fsf@ruckus.brouhaha.com> <7xk6qrnbum.fsf@ruckus.brouhaha.com> <41dcaa00.102858012@news.oz.net> <7x652bnhx0.fsf@ruckus.brouhaha.com> Message-ID: <41dcf582.122188317@news.oz.net> On 05 Jan 2005 23:19:39 -0800, Paul Rubin wrote: >bokr at oz.net (Bengt Richter) writes: >> What do you think of automated secure importing/installing from a >> remote server? You know, you try to import something and it imports >> a stub that was included as a battery-place-holder and that has >> basic help info and will give you reasonable options in directing >> the installation of the full thing (or subset you are interested in). > >You mean for Python modules, in ordinary operation? I'd hate that. >For things like apt-get, used for installing nonstandard programs or >getting security updates, I guess it's about as good as one can hope >for. The user has to activate it explicitly though. I definitely >don't want my computer opening internet connections unless I >specifically ask it to. Doing otherwise is almost spyware. I agree 1000% !! Importing a stub should get you an imported stub that prints info as it imports, so you know its not functional. And just gives you the options to type help(themodule) or if you know you want to go ahead, themodule.install() -- and nothing would touch the internet until you gave a final "yes" to an "Are you sure" at the end of a what-will-happen-if-you-say-yes summary. I didn't mean any activity that you don't control. Just activity that you can control easily. > >This may sound a little extreme but my distribution philosophy is I'd >like to get closer to an environment where users normally never >install any software of any type, ever. Microsoft cornered the OS >market cornered by acheiving something pretty close to this: they >deliver Windows with no installation needed. When people buy new >computers, Windows is already on the hard drive, so the user just >turns the computer on and Windows is there. It makes a lot of sense for a "core" plus a delivered specific application base, but IMO if you try to cover the world with a monolith you will inevitably still have the problem of getting the latest version of particular packages for bug fixes or enhancements. The more you have in your giant collection the more that will be true. > >Fedora Core (what I'm running now) isn't shipped that way by any >computer makers that I know of, but it makes up for it by having lots >of applications included. So I buy a new computer, put in the >bootable Fedora DVD-ROM, and sit back for half an hour while a >one-time installation runs. That's about as close as I can get to >just turning on the new computer and having Fedora already there. > >> I don't see why every gee whiz thing has to be on your hard disk >> from the first. And for those that want a big grabbag, the stubs >> ought to be designed to to be runnable from a configured script, so >> you can turn it loose and see what's up IRL. > >If I have a 400 gig hard drive, I don't see why I need 99.99% of it >empty instead of 99.0% after I do my OS install. I don't want to >hassle over downloading stuff for hours or days at a time, or about >what components depend on other components, if the distro can just >include it. I just tried to install a Python program that uses >wxPython, except that meant I had to download both wxPython and >wxWidgets, and the installations failed because of some version >mismatch between the current wxWidgets distro and the version of GTK >included with FC3. I spent an hour or so messing with it and then >said screw it and gave up on the GUI part of that program. I'm more >technical than most users (I'm a programmer) yet this installation >stuff is too much hassle even for me. So I'd really rather that all >that stuff be pre-configured. There are several parts to those frustrations. But you are presuming that they would have been solved for you and put on a DVD with all dependency problems resolved. Ok, let's assume that. In that case, an installation stub module could just as well have the solution built into it as to what versions etc are needed to make the module work. With a large collection, you may need several versions of some support libs. To bring a large collection into version-alignment ISTM you need a version freeze across too many libraries of different kinds with different development schedules and resources to make it reliable. So you're still going to need the ability to add updates and new modules and more. I'd rather see effort going into making that process simple and reliable (and fully controlled by the user -- i.e. no unauthorized hidden internet activity!!) than to solve the same version problems for some mega DVD make file where you don't have the script and config info in a concise single-problem stub form, and can't ask here for help finding an updated stub. It's a matter of being able to limit the problem you need to solve when something particular doesn't work. When your wxPython-using program didn't work, wouldn't it have been nice to have downloaded a standard stub program (with older stub versions still available if you have an older system) and have it tell you what was missing that it needed before you decided to let it continue and get those things? Or choose not to? With broadband most apps will be ready before you can make fresh coffee, or maybe watch the Simpsons. Otherwise what? Send for a new DVD? Yes, core stuff + plenty of compatible goodies in a distro is a good idea, but problems are inevitable, and IMO it's more important to have a standard reliable way to solve problems than to have them "solved" on periodic monoliths DVDs that can't ever be problem free. > >If a system has N downloadable components that are supposedly >independent, there are 2**N combinations of them that anyone might >have installed. In reality the indepdence is never that complete, so >something can easily go wrong if you pick a combination that hasn't >been tested and debugged by someone, and there's no way to test more >than a few of the possibilities. So I'd rather that all N components >already be included with the OS so that the combination will have been >tested by the distro maintainers before the end user has to deal with You are asking a lot from these distro maintainers if you expect recent versions of everything, and for them to watch for new stuff to evaluate and include after researching compatibility problems. They aren't in the best position to do that. The author/s of the new stuff is/are. And if such authors had a standard stub module they could prepare, then distros could include those, and you would find version updates for those rather than trying to solve the integration problems yourself. And if there were still bugs, a new version would likely be posted here after some discussion. And then everyone could have an easy download of the new stub, and be able to go for coffee. I think if python.org had a trusted-software registry that could be a flat CSV text file of names, versions, urls, sizes, and md5 digests and maybe some trust level, then the stubs could access that for a standard way of finding components. Or course for a DVD distro, stubs could access the DVD rather than the internet for things at the DVD's version level. I realize this problem has been "solved" with various RPM and app-loading methods, but I think python could wrap its solution nicely. I don't think distutils and setup.py is easy enough to create (at least I have been somewhat frustrated in using it effectively), though it deals with a lot of what has to be done. >it. Hard drives and distro media (DVD) are big enough now that it's >quite reasonable for distros to include just about everything that >most users could want. Agreed for some "core" set. How shall we define what belongs in the "core?" ;-) Regards, Bengt Richter From marklists at mceahern.com Wed Jan 12 13:23:30 2005 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 12 Jan 2005 12:23:30 -0600 Subject: counting items In-Reply-To: References: Message-ID: <41E56B22.6020708@mceahern.com> It's me wrote: >Okay, I give up. > >What's the best way to count number of items in a list [that may contain lists]? > > a = [[1,2,4],4,5,[2,3]] def iterall(seq): for item in seq: try: for subitem in iterall(item): yield subitem except TypeError: yield item all = [x for x in iterall(a)] print len(all) From bokr at oz.net Mon Jan 24 23:52:12 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 25 Jan 2005 04:52:12 GMT Subject: Another scripting language implemented into Python itself? References: <1106624803.825442.73870@f14g2000cwb.googlegroups.com> Message-ID: <41f5cf0f.1750685172@news.oz.net> On 24 Jan 2005 19:46:43 -0800, "Carl Banks" wrote: [...] >> Imbed > >EMBED. > >This spelling error wouldn't bother me if I didn't work with people >whose own job title is embedded control engineer, yet who still >misspell it "imbedded." > wordnet seems to accept it as an alternative spelling (not too recent): [20:44] C:\pywk\sovm>wn imbed -over Overview of verb imbed The verb imbed has 1 sense (first 1 from tagged texts) 1. implant, engraft, embed, imbed, plant -- (to fix or set securely or deeply: "Kneeling, Cobb p lanted a sturdy knee in the small of his back,") funny that googling define:imbed gets nothing. Nor define:embed ?? I've had a number of misses in that kind of search. I wonder if it's temporarily broken (or maybe it hit a licensing snag with the various online dictionaries?) Regards, Bengt Richter From jlenton at gmail.com Wed Jan 12 12:05:14 2005 From: jlenton at gmail.com (John Lenton) Date: 12 Jan 2005 09:05:14 -0800 Subject: Iteration over two sequences In-Reply-To: <1gq9qs9.3snutr1s4mcn2N%news+0409@henrikholm.com> References: <1gq9qs9.3snutr1s4mcn2N%news+0409@henrikholm.com> Message-ID: <1105549514.563799.307030@z14g2000cwz.googlegroups.com> > Quite frequently, I find the need to iterate over two sequences at the > same time, and I have a bit of a hard time finding a way to do this in a > "pythonic" fashion. One example is a dot product. The straight-ahead > C-like way of doing it would be: > > def dotproduct(a, b): > psum = 0 > for i in range(len(a)): > psum += a[i]*b[i] > return psum for this particular example, the most pythonic way is to do nothing at all, or, if you must call it dotproduct, >>> from Numeric import dot as dotproduct From elbertlev at hotmail.com Mon Jan 31 15:03:49 2005 From: elbertlev at hotmail.com (elbertlev at hotmail.com) Date: 31 Jan 2005 12:03:49 -0800 Subject: py-xmlrpc postpone question Message-ID: <1107201829.674563.79000@z14g2000cwz.googlegroups.com> Hi! I'm trying to use py-xmlrpc. All works fine (and very fast) in one-threaded case, but I really have to serve many clients. As advertised, py-xmlrpc supports non-blocking calls (via select). When request is received the handler is called with proper parameters. As I understood from reading the source, if rpc call can't be executed immediately (or takes long time) respond can be postponed by raising postpone exception and when respond is ready, calling queueResponse() . I wanted to have a pool of worker threads listening on a queue. In the "lengthy command handlers", post data on the queue and raise postpone. Threads from the pool respond by calling queueResponse() when rpc is done. Server trace tells me that postpone was received, but client reacts as if socket was closed (got EOS while reading). I tryed to supress default error handling on the client side by returning from OnErr() xmlrpc.ONERR_KEEP_WORK, but this kills the interpreter! What am I doing wrong? From paul at prescod.net Mon Jan 31 21:27:04 2005 From: paul at prescod.net (Paul Prescod) Date: Mon, 31 Jan 2005 18:27:04 -0800 Subject: Vancouver Python/Zope/Plone: Creating OS X Cocoa Applications Using XML and Python Message-ID: <41FEE8F8.9000906@prescod.net> February 1, 2005 Creating OS X Cocoa Applications Using XML and Python, Dethe Elza This talk will cover the use of Renaissance and Python to develop programs for OS X, focussing on both rapid application development, and ease of maintenance. Renaissance is an XML dialect for describing Cocoa (or GNUstep) user interfaces, which can be used as an alternative to Apple's binary NIB format. It grew out of the GNUstep? project and is intended for use with Objective-C, but works seamlessly from Python with the PyObjC bridge. Hosted by ActiveState ("a division of Sophos") at 580 Granville St., Vancouver From me at privacy.net Fri Jan 28 16:19:36 2005 From: me at privacy.net (JanC) Date: 28 Jan 2005 21:19:36 GMT Subject: Where can I find sample "beginner" programs to study? References: <_6CdnWIOB8AaA2fcRVn-rg@speakeasy.net> Message-ID: Todd_Calhoun schreef: > I'm trying to learn Python (and programming), and I'm wondering if > there are any places where I can find small, simple programs to study. Try: -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From tjreedy at udel.edu Sat Jan 1 04:51:27 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 1 Jan 2005 04:51:27 -0500 Subject: OT: spacing of code in Google Groups References: <1104516184.077462.283350@c13g2000cwb.googlegroups.com> Message-ID: "JanC" wrote in message news:Xns95D132B172343JanC at 213.118.32.224... > I don't know if gmane keeps formating of messages intact when posting? > That could be an alternative too... Reading posts via gmane with Outlook Express preserves leading spaces just fine. However, OE deletes tabs regardless of what newsgroup does. The funny thing is that typing a tab gets converted to 4 spaces. Terry J. Reedy From jason at tishler.net Mon Jan 17 16:27:48 2005 From: jason at tishler.net (Jason Tishler) Date: Mon, 17 Jan 2005 16:27:48 -0500 Subject: Cygwin Popen object In-Reply-To: <1105994485.770313.141910@f14g2000cwb.googlegroups.com> References: <1105994485.770313.141910@f14g2000cwb.googlegroups.com> Message-ID: <20050117212748.GB2388@tishler.net> On Mon, Jan 17, 2005 at 12:41:25PM -0800, christiancoder wrote: > Is anybody else getting the following error with the Popen object in > cygwin? The code works fine in windows and linux. > > File "d:\atg\personal\python\buildroot\util.py", line 100, in System > pipe = subprocess.Popen( command, shell=True, > stdout=subprocess.PIPE, stderr=subprocess.STDOUT, > universal_newlines=True ) > File "/usr/local/lib/python2.4/subprocess.py", line 554, in __init__ > errread, errwrite) > File "/usr/local/lib/python2.4/subprocess.py", line 914, in > _execute_child > self.pid = os.fork() > OSError: [Errno 11] Resource temporarily unavailable Try rebasing your Cygwin installation. See the README: /usr/share/doc/Cygwin/python-2.4.README for more information. Does it solve your problem? Jason -- PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6 From invalidemail at aerojockey.com Fri Jan 14 11:02:19 2005 From: invalidemail at aerojockey.com (Carl Banks) Date: 14 Jan 2005 08:02:19 -0800 Subject: python and macros (again) [Was: python3: 'where' keyword] In-Reply-To: <34q69pF4dvkhqU1@individual.net> References: <1105437966.129342.304400@f14g2000cwb.googlegroups.com> <7xmzvfn096.fsf@ruckus.brouhaha.com> <7xsm559heo.fsf@ruckus.brouhaha.com> <7xacrcdhzh.fsf@ruckus.brouhaha.com> <34q69pF4dvkhqU1@individual.net> Message-ID: <1105718539.916246.174950@z14g2000cwz.googlegroups.com> Tim Jarman wrote: > IANA French person, but I believe that Belgians are traditionally > regarded as stupid in French culture, so "Belgian logic" would be > similar to "Irish logic" for an English person. (Feel free to insert > your own cultural stereotypes as required. :) Ok. http://www.urbandictionary.com/define.php?term=belgian&r=f -- CARL BANKS From jegenye2001 at HAM-ONLY-PLEASE-SO-REMOVE-THIS.parkhosting.com Sun Jan 9 17:25:19 2005 From: jegenye2001 at HAM-ONLY-PLEASE-SO-REMOVE-THIS.parkhosting.com (Miklós P) Date: Sun, 9 Jan 2005 23:25:19 +0100 Subject: Guild of Python consultants? References: Message-ID: "Peter Hansen" wrote in message news:rtednbVd1tsF4XzcRVn-oQ at powergate.ca... > I also know of many people (myself included) who restrict the term > to those who have a deep expertise in one or more areas and who > look for projects where they can be brought in to apply that > expertise, usually by telling the customer what to do (or what > not to do any more, perhaps). This sort of work can be hourly, > or quite often daily or even at a fixed price (say, for specialized > "emergency" troubleshooting, or for a design task). > > (The second type will take on jobs that the former would take, > often grudgingly if work is scarce, while the former are rarely > qualified to take on the sort of work that interests the latter.) > > Which type do you mean? Well, I consider myself a consultant of the second kind. Using Python for maths/stats (often meaning decision support systems) or science related custom software is what I prefer to do .. But I also tend to enjoy "firefighting" web projects because they pay well and they are never boring.. rather on the contrary.. :-) ...and I second what you said in parenthesis. So my interest follows. Though one could surely have two divisions of a huge guild. :-)) Best, Mikl?s From steve at holdenweb.com Mon Jan 31 14:20:10 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 31 Jan 2005 14:20:10 -0500 Subject: Relocatable binary installs.... In-Reply-To: References: <1107195180.462949.222980@z14g2000cwz.googlegroups.com> <41FE7F26.1090209@holdenweb.com> Message-ID: <41FE84EA.3030501@holdenweb.com> Fredrik Lundh wrote: > Steve Holden wrote: > > >>>>Is there a way to make a relocateable python binary... that is... a >>>>python installation that won't care where it is on the machine... and >>>>won't care if it gets put somewhere else besides / ? >>> >>> >>>the standard CPython interpreter is 100% "relocatable". If you think >>>it isn't, you have to be a bit more specific. >>> >> >>Is it possible that you are using "relocatable" in the standard sense of "code can be located >>anywhere in physical memory", where the OP is using the same term to mean "can live anywhere in >>the filestore"? > > > nope. > > >>I suspect the problem the OP is seeing is because the --prefix configuration parameter will cause >>an interpreter to look in a specific place for standard libraries. Clearly if you "relocate" the >>libraries to another directory entirely then an interpreter without any further nouse (and no >>symbolic links to help it) is going to crap out badly. > > > clearly? > > [fredrik at brain build] mv python2.3 /tmp > [fredrik at brain build] mkdir /tmp/lib > [fredrik at brain build] mv lib /tmp/lib/python2.3 > [fredrik at brain build] cd /tmp > [fredrik at brain tmp]$ ./python2.3 > >>>>import sys >>>>sys.prefix > > '/tmp' > >>>>sys.path > > ['', '/tmp/lib/python23.zip', '/tmp/lib/python2.3', ...] > > [fredrik at brain tmp]$ mkdir spam > [fredrik at brain tmp]$ mv python2.3 spam > [fredrik at brain tmp]$ mv lib spam > [fredrik at brain tmp]$ cd spam/ > [fredrik at brain spam]$ ./python2.3 > >>>>import sys >>>>sys.prefix > > '/tmp/spam' > >>>>sys.path > > ['', '/tmp/spam/lib/python23.zip', '/tmp/spam/lib/python2.3', ...] > > > [fredrik at brain spam]$ mkdir bin > [fredrik at brain spam]$ mv python2.3 bin > [fredrik at brain spam]$ bin/python2.3 > >>>>import sys >>>>sys.prefix > > '/tmp/spam' > > > [fredrik at brain spam]$ cd bin > [fredrik at brain bin]$ ./python2.3 > >>>>import sys >>>>sys.prefix > > '/tmp/spam' > > [fredrik at brain fredrik]$ export PATH=/tmp/spam/bin:$PATH > [fredrik at brain bin]$ cd > [fredrik at brain fredrik]$ python2.3 > >>>>import sys >>>>sys.prefix > > '/tmp/spam' > > > and so on... > Well, OK, maybe it's not quite as clear as I thought :-) regards Steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 From bokr at oz.net Mon Jan 24 15:35:09 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 24 Jan 2005 20:35:09 GMT Subject: specifying constants for a function (WAS: generator expressions: performance anomaly?) References: <41f325b5.1576259210@news.oz.net> <6I2dnYLoXdcTmGncRVn-vw@comcast.com> <41f490e8.1669238027@news.oz.net> Message-ID: <41f5568c.1719834331@news.oz.net> On Mon, 24 Jan 2005 00:31:17 -0700, Steven Bethard wrote: >Bengt Richter wrote: >> So, e.g., for >> >> >>> presets = dict(a=1, b=2, deftime=__import__('time').ctime()) >> >> in the decorator args, the next version will act as if the decorated >> function had the source code >> >> >>> print '%s = __frompresets__' % ', '.join(sorted(presets)) >> a, b, deftime = __frompresets__ >> >> for the current version, except that it will be hidden. > >Cool! Keep us posted. I assume you'll put this into the Cookbook? > Not ready for prime time, I guess, but I made a module that does presets and also adjusts parameters and count to do currying without nested function calling in the curried function. >>> from presets import presets, curry >>> @presets(verbose=True, a=1, b=2, deftime=__import__('time').ctime()) ... def foo(): ... print (a, b) ... print deftime ... presets: -- "name(?)" means name may be unused a = 1 b = 2 deftime = 'Mon Jan 24 12:16:07 2005' >>> foo() (1, 2) Mon Jan 24 12:16:07 2005 >>> @curry(verbose=True, y=444) ... def bar(x=3, y=4): ... return x*y ... presets: -- "name(?)" means name may be unused y = 444 >>> bar(2) 888 >>> bar(2, 3) Traceback (most recent call last): File "", line 1, in ? TypeError: bar() takes at most 1 argument (2 given) >>> bar() 1332 >>> import dis >>> dis.dis(bar) 1 0 LOAD_CONST 1 (444) 3 STORE_FAST 1 (y) 3 6 LOAD_FAST 0 (x) 9 LOAD_FAST 1 (y) 12 BINARY_MULTIPLY 13 RETURN_VALUE >>> dis.dis(foo) 1 0 LOAD_CONST 1 ((1, 2, 'Mon Jan 24 12:16:07 2005')) 3 UNPACK_SEQUENCE 3 6 STORE_FAST 0 (a) 9 STORE_FAST 1 (b) 12 STORE_FAST 2 (deftime) 3 15 LOAD_FAST 0 (a) 18 LOAD_FAST 1 (b) 21 BUILD_TUPLE 2 24 PRINT_ITEM 25 PRINT_NEWLINE 4 26 LOAD_FAST 2 (deftime) 29 PRINT_ITEM 30 PRINT_NEWLINE 31 LOAD_CONST 0 (None) 34 RETURN_VALUE Now I have to see whether I can optimize the result with Raymond's make_constants as two decorators in a row... (pre without keyword args is an alias for Raymond's make_constants, just handy for the moment) >>> from pre import pre >>> @pre(verbose=True) ... @presets(verbose=True, a=1, b=2, deftime=__import__('time').ctime()) ... def foo(): ... print (a, b) ... print deftime ... print __name__ ... presets: -- "name(?)" means name may be unused a = 1 b = 2 deftime = 'Mon Jan 24 12:29:21 2005' __name__ --> __main__ >>> foo() (1, 2) Mon Jan 24 12:29:21 2005 __main__ >>> dis.dis(foo) 1 0 LOAD_CONST 1 ((1, 2, 'Mon Jan 24 12:29:21 2005')) 3 UNPACK_SEQUENCE 3 6 STORE_FAST 0 (a) 9 STORE_FAST 1 (b) 12 STORE_FAST 2 (deftime) 3 15 LOAD_FAST 0 (a) 18 LOAD_FAST 1 (b) 21 BUILD_TUPLE 2 24 PRINT_ITEM 25 PRINT_NEWLINE 4 26 LOAD_FAST 2 (deftime) 29 PRINT_ITEM 30 PRINT_NEWLINE 5 31 LOAD_CONST 2 ('__main__') 34 PRINT_ITEM 35 PRINT_NEWLINE 36 LOAD_CONST 0 (None) 39 RETURN_VALUE Regards, Bengt Richter From steve at holdenweb.com Sun Jan 9 17:19:31 2005 From: steve at holdenweb.com (Steve Holden) Date: Sun, 09 Jan 2005 17:19:31 -0500 Subject: Python serial data aquisition In-Reply-To: References: Message-ID: Flavio codeco coelho wrote: > Hi, > > I am using pyserial to acquire data from an A/D converter plugged to > my serial port. > > my hardware represents analog voltages as 12bit numbers. So, according > to the manufacturer, this number will be stored in two bytes like > this; > |-------------bits(1-8)-----------| > Byte1: x x x n1 n2 n3 n4 n5 > Byte2: x n6 n7 n8 n9 n10 n11 n12 > > where x is some other information, and nx are the digits of my number. > > My problem is to how to recover my reading from these bytes, since > pyserial gives me a character (string) from each byte... I dont know > how to throw away the unneeded bits and concatenate the remaining > bits to form a number... > > > Fl?vio Code?o Coelho Try something like (here I'm assuming that n12 is the least-significant bit) (untested): ((ord(byte1) & 31) << 7 ) + (ord(byte2) & 127) This takes the rightmost five bits from the first byte's integer value, shifts them up seven bits, and then adds the rightmost seven bits of the second byte's integer value. regards Steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 From aaronwmail-usenet at yahoo.com Thu Jan 27 09:19:22 2005 From: aaronwmail-usenet at yahoo.com (aaronwmail-usenet at yahoo.com) Date: 27 Jan 2005 06:19:22 -0800 Subject: On benchmarks, heaps, priority queues References: Message-ID: <1106835562.598569.211370@c13g2000cwb.googlegroups.com> me> PQPython23 - the Lib implementation me> PQ0 - my insertion sort based variant me> PQueue - my "heap" based variant me> (like PQPython23, but different). Tim D: > First of all, you should be running these benchmarks using Python 2.4. > heapq is considerably faster there ... (Raymond Hettinger rewrote it all > in C). > http://www.python.org/2.4/highlights.html > Tim Delaney WHOOPS. Okay after getting past my initial embarassment I tried this, and it turns out it doesn't make much of a difference. In particular PQ0 is still always better if you intersperse many deletes with inserts or in all cases of size <10000. Of course other machines will probably have different characteristics (and yes my py24 contains the _heapq extension module). The nasty behavior of PQ0 for insertBench at >100000 I think has to do with large list reallocation. Hmmm. This makes me wonder if my bplustree implementation(s) are faster than the bsddb modules too... -- Aaron Watters === SOMETHING WENT WRONG IN AIRLINE CRASH, EXPERT SAYS -- a "real life headline" (that'll be $50,000, please) ENCLOSURE: Python 2.4 run of http://xsdb.sourceforge.net/bench/pq3.py on my machine. ======================= BENCHMARKS FOR 1000 insertBench __main__.PQPython23 on 1000 elapsed 0.0199999809265 got 1000 __main__.PQ0 on 1000 elapsed 0.00999999046326 got 1000 __main__.PQueue on 1000 elapsed 0.0300002098083 got 1000 mixBench __main__.PQPython23 on 1000 elapsed 0.0 got 502 __main__.PQ0 on 1000 elapsed 0.00999999046326 got 502 __main__.PQueue on 1000 elapsed 0.0 got 502 BENCHMARKS FOR 10000 insertBench __main__.PQPython23 on 10000 elapsed 0.260999917984 got 10000 __main__.PQ0 on 10000 elapsed 0.210000038147 got 10000 __main__.PQueue on 10000 elapsed 0.359999895096 got 10000 mixBench __main__.PQPython23 on 10000 elapsed 0.0700001716614 got 5003 __main__.PQ0 on 10000 elapsed 0.050999879837 got 5003 __main__.PQueue on 10000 elapsed 0.0699999332428 got 5003 BENCHMARKS FOR 100000 insertBench __main__.PQPython23 on 100000 elapsed 3.26499986649 got 100000 __main__.PQ0 on 100000 elapsed 7.88100004196 got 100000 __main__.PQueue on 100000 elapsed 4.81699991226 got 100000 mixBench __main__.PQPython23 on 100000 elapsed 0.65099978447 got 50000 __main__.PQ0 on 100000 elapsed 0.461000204086 got 50000 __main__.PQueue on 100000 elapsed 0.661000013351 got 50000 BENCHMARKS FOR 200000 insertBench __main__.PQPython23 on 200000 elapsed 6.99000000954 got 200000 __main__.PQ0 on 200000 elapsed 28.5010001659 got 200000 __main__.PQueue on 200000 elapsed 10.3849999905 got 200000 mixBench __main__.PQPython23 on 200000 elapsed 1.29099988937 got 100001 __main__.PQ0 on 200000 elapsed 0.922000169754 got 100001 __main__.PQueue on 200000 elapsed 1.34200000763 got 100001 BENCHMARKS FOR 300000 insertBench __main__.PQPython23 on 300000 elapsed 11.6970000267 got 300000 __main__.PQ0 on 300000 elapsed 70.3009998798 got 300000 __main__.PQueue on 300000 elapsed 16.8840000629 got 300000 mixBench __main__.PQPython23 on 300000 elapsed 1.93300008774 got 150000 __main__.PQ0 on 300000 elapsed 1.39199995995 got 150000 __main__.PQueue on 300000 elapsed 1.96300005913 got 150000 BENCHMARKS FOR 400000 insertBench __main__.PQPython23 on 400000 elapsed 15.5419998169 got 400000 __main__.PQ0 on 400000 elapsed 127.253000021 got 400000 __main__.PQueue on 400000 elapsed 23.0629999638 got 400000 mixBench __main__.PQPython23 on 400000 elapsed 2.64399981499 got 200000 __main__.PQ0 on 400000 elapsed 1.95300006866 got 200000 __main__.PQueue on 400000 elapsed 2.73399996758 got 200000 BENCHMARKS FOR 500000 insertBench __main__.PQPython23 on 500000 elapsed 20.8800001144 got 500000 __main__.PQ0 on 500000 elapsed 246.954999924 got 500000 __main__.PQueue on 500000 elapsed 35.9609999657 got 500000 mixBench __main__.PQPython23 on 500000 elapsed 3.55599999428 got 250000 __main__.PQ0 on 500000 elapsed 2.48300004005 got 250000 __main__.PQueue on 500000 elapsed 3.48500013351 got 250000 BENCHMARKS FOR 1000000 insertBench __main__.PQPython23 on 1000000 elapsed 44.6940000057 got 1000000 __main__.PQ0 on 1000000 elapsed 1400.5940001 got 1000000 __main__.PQueue on 1000000 elapsed 70.6619999409 got 1000000 mixBench __main__.PQPython23 on 1000000 elapsed 6.63000011444 got 500001 __main__.PQ0 on 1000000 elapsed 4.73600006104 got 500001 __main__.PQueue on 1000000 elapsed 6.82999992371 got 500001 From cpl.19.ghum at spamgourmet.com Thu Jan 27 04:07:09 2005 From: cpl.19.ghum at spamgourmet.com (Harald Massa) Date: Thu, 27 Jan 2005 09:07:09 +0000 (UTC) Subject: py2exe problem References: <41f7213c$0$2343$a1866201@visi.com> Message-ID: Thomas, > Would the above (include all encodings stuff by default) be a good > solution, or do you have other ideas? I assume a good solution would involve switching pythons default from "ASCII" to "UNICODE" :) But ... as far as py2exe is concerned, yeah, I think it would be helpfull to include all encoding by default (undefaultable, of course), or at least provide in the very very first simple setup.py example the include encodings.* stuff. Harald Armin From mcfletch at rogers.com Sat Jan 22 13:44:06 2005 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Sat, 22 Jan 2005 13:44:06 -0500 Subject: Class introspection and dynamically determining function arguments In-Reply-To: <41f2212f.1509565800@news.oz.net> References: <41f18d10.1471646806@news.oz.net> <41f2212f.1509565800@news.oz.net> Message-ID: <41F29EF6.7030909@rogers.com> Bengt Richter wrote: >On Fri, 21 Jan 2005 20:23:58 -0500, "Mike C. Fletcher" wrote: > > > >>>On Thu, 20 Jan 2005 11:24:12 -0000, "Mark English" wrote: >>> >>> ... >Does the BasicProperty base class effectively register itself as an observer >of subclass properties and automatically update widgets etc., a la Delphi >data-driven visual components? I've thought of doing a light-weight form >extension class that would use a text (maybe CSV) definition to control >contruction, and easy programmatic manipulation by python of the definition >parameters, like a stripped-down version of the text view of Delphi forms. >It could also be done via Tkinter, to prototype it. It would be interesting >to allow dragging widgets and edges around in Tkinter and round-trip the parameter >changes automatically into the text representation. A little (well, ok, a fair amount ;-) >further and you'd have a drag-n-drop GUI design tool. But don't hold your breath ;-) > > BasicProperty itself doesn't register as an observable/observer, BasicProperty is the lowest-level of the software stack, so it allows you to override and provide notification (e.g. using PyDispatcher) on property-setting. ConflictSolver (old project to create a room scheduler) used that to do automatic updating of widgets in the wxPython UI based on Model changes (though I don't remember if it was per-property or per-object). My goal for the wxoo project was to provide hooks in the wxPython GUI designers for dropping in property sheets and/or property-aware controls such that you would have the equivalent of "data aware" controls in VB or Access (keeping in mind that BasicProperty properties can also represent fields in database rows). Aside: The VRML97 field class in OpenGLContext does notifications for every set (using PyDispatcher), btw. It's a little more limited in its scope (focus on 3D data-types), but the effect is what allows the scenegraph to cache and then rebuild its internal rendering structures with very low overhead. ... >>Anyway, if you aren't interested in BasicProperty for this task; another >>project on which I work, PyDispatcher provides fairly robust mechanism >>(called robustApply) for providing a set of possible arguments and using >>inspect to pick out which names match the parameters for a function in >>order to pass them in to the function/method/callable object. That >>said, doing this for __init__'s with attribute values from an object's >>dictionary doesn't really seem like the proper way to approach the problem. >> >> >Sounds like a workaround for parameter passing that maybe should have been >keyword-based? > > Not as such, that is, not a workaround, and it shouldn't be keyword based ;) . The problem with using keyword-based passing is that every method needs to be written with this awareness of the keyword-handling structures. You spread pointless implementation details throughout your codebase. PyDispatcher lets you write very natural functions for dealing with events without having every function use **named parameters. I've now written quite a few such systems, and I'm currently balanced between two approaches; that taken in PyDispatcher (define only natural parameters, have the system figure out how to deliver them to you), and that taken in OpenGLContext (define an event-class hierarchy which encapsulates all information about the events). The PyDispatcher approach is nice in that it makes simple things very simple. You want access to the "lastValue" parameter in the "environment" of the event and nothing else, you define your function like so: def handler( lastValue ): print 'got last value', lastValue which works very nicely when you're early in the development of a system, or are linking multiple systems. There's no need to do all sorts of extra work defining event hierarchies, you can often leave given handlers entirely alone during refactoring if they aren't dealing with the changed properties in the event-environment. The OpenGLContext approach is more appropriate when you have a large system (such as OpenGLContext), where defining an event class is a trivial task compared to the total system expenditure. It allows for such things as putting methods on the event objects to make debugging easy, and providing common functionality. It starts to show it's worth when you start needing to reason about the phenomena of events themselves, rather than just about the phenomena the events represent (e.g. when you need to cache, delay, or reorder events). The named argument passing approach has the disadvantage that every function must be written with knowledge of that use of named arguments: def handler( lastValue, **named ): print 'got last value', lastValue when using such systems in the past I've often wound up with errors deep in an application where some seldom-called callback didn't have a **named parameter, so the system would abort (well, log an error) trying to call it. Is it a huge overhead? No. But its unnecessary if you've got a tool that takes care of that "implementation-level" detail for you. Compared to robustApply, the difference is pretty minimal. If you define a **named parameter, for instance, you will get the remainder of the robustApply environment passed in. In another lifetime, you could imagine these systems being written as wrappers that added a nested scope around the definition of the function such that the scope forwarded unresolved name references to the environment of the event (non-lexical scoping), but that would lack the explicitness of passing in the arguments from the environment and would, I suppose be evil in a quite non-trivial way. Peace, and have fun, Mike ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From itsme at yahoo.com Wed Jan 5 17:29:31 2005 From: itsme at yahoo.com (It's me) Date: Wed, 05 Jan 2005 22:29:31 GMT Subject: Python 2.4 on Windows XP References: <1104946252.430332.226930@z14g2000cwz.googlegroups.com> <10toje56oiebq24@corp.supernews.com> <10ton02dur41v0b@corp.supernews.com> Message-ID: Thanks, Jeff. That works. "Jeff Shannon" wrote in message news:10ton02dur41v0b at corp.supernews.com... > It's me wrote: > > > In my case, there is *no* error message of any kind. When I run pythonw.exe > > from the python23 directory, the screen blinked slightly and goes back to > > the command prompt. > > Right -- pythonw.exe is a console-less interpreter. Having no > console, it doesn't have an interactive mode, and since you didn't > give it a script to run, it simply started, found nothing to do, and > then terminated itself. > > You need to run idle.pyw, *not* pythonw.exe. The idle.pyw script runs > inside the pythonw.exe interpreter, but the latter can't do anything > without instructions. > > Jeff Shannon > Technician/Programmer > Credit International > From miki.tebeka at zoran.com Sun Jan 16 06:44:27 2005 From: miki.tebeka at zoran.com (Miki Tebeka) Date: Sun, 16 Jan 2005 13:44:27 +0200 Subject: video analysis with python In-Reply-To: References: Message-ID: <20050116114407.GE3276@zoran.com> Hello Ashot, > I need to write a video analysis tool which extracts statistics from > microsocope video. Essentially what I need is to translate the video data > into numerical matrices. I have been using Python for the past 1.5 years > anytime I could for absolutely everything, because it has every library > imaginable... Alas, I can not find a library for decoding video/using > codecs. The only solution I have been able to come up with is to create > an image sequence and load those in with PIL, however this is not really > feasible as the images are too large (nor is it proffessional). > > Is there a library or project that I have missed, or is there a way > to incorporate something like vfw.lib directly? If there isn't I think > this would be a pretty large whole in Python's arsenal. Thanks in advance > for any help. 1. There is PyMedia (http://pymedia.org/) 2. Maybe you can use the code from VLC (http://www.videolan.org/vlc/) (using SWIG/PyBoost/Pyrex ...) HTH. -- ------------------------------------------------------------------------ Miki Tebeka http://tebeka.bizhat.com The only difference between children and adults is the price of the toys From jzgoda at gazeta.usun.pl Thu Jan 20 15:10:35 2005 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Thu, 20 Jan 2005 21:10:35 +0100 Subject: ElementTree cannot parse UTF-8 Unicode? In-Reply-To: <1106233137.588111.216480@z14g2000cwz.googlegroups.com> References: <1106150061.169027.7010@c13g2000cwb.googlegroups.com> <1106230846.455765.7310@c13g2000cwb.googlegroups.com> <1106233137.588111.216480@z14g2000cwz.googlegroups.com> Message-ID: Erik Bethke wrote: > So why are there non-UNICODE versions of wxPython??? To save memory or > something??? Win95, Win98, WinME have problems with unicode. GTK1 does not support unicode at all. -- Jarek Zgoda http://jpa.berlios.de/ | http://www.zgodowie.org/ From steve at holdenweb.com Mon Jan 17 10:33:07 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 17 Jan 2005 10:33:07 -0500 Subject: lambda In-Reply-To: References: <1105633239.316956.262140@f14g2000cwb.googlegroups.com> <41EBA021.5060903@holdenweb.com> Message-ID: Antoon Pardon wrote: > Op 2005-01-17, Steve Holden schreef : > >>Antoon Pardon wrote: >> >> >>>I don't see a big difference between these principles >>>and the hash key principle, so in the end may be we >>>should just stick with the more general principle: >>> >>> Don't use mutables! >>> >>> >>>and be done with it. >>> >> >>http://redwing.hutman.net/~mreed/warriorshtm/tirelessrebutter.htm >> >>regards >> Steve > > > I you want to play it like this > > http://redwing.hutman.net/~mreed/warriorshtm/crybaby.htm > Hey, I'm not crying, or trying to play it any particular way. It's a free Internet, and you are (more than) welcome to your opinions. Personally I'd say I'm actually more of a combination of http://redwing.hutman.net/~mreed/warriorshtm/diplomat.htm and http://redwing.hutman.net/~mreed/warriorshtm/evilclown.htm, with added touches of http://redwing.hutman.net/~mreed/warriorshtm/garble.htm and possibly http://redwing.hutman.net/~mreed/warriorshtm/toxicgranny.htm Whereas I also detect touches of http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm in your posts. It must be nice to *never* be wrong :-). Your resemblance to http://redwing.hutman.net/~mreed/warriorshtm/filibuster.htm, however, makes me wish you could be right rather more succinctly. Mostly, though, I was trying to say that I found your nitpicking insistence on terminological exactitude, even when giving advice to those new to the language, both inappropriate and tedious in the extreme. Have a nice day :-) regards Steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 From Serge.Orlov at gmail.com Fri Jan 14 17:45:49 2005 From: Serge.Orlov at gmail.com (Serge Orlov) Date: Fri, 14 Jan 2005 22:45:49 +0000 (UTC) Subject: oddities in the datetime module References: <41e79a1a$0$264$edfadb0f@dread12.news.tele.dk> <41e84175$0$258$edfadb0f@dread12.news.tele.dk> Message-ID: Max M wrote: > Serge Orlov wrote: >> Max M wrote: > >> Yes, you did. datetime.timetuple is those who want *time module* >> format, you should use datetime.data, datetime.time, datetime.year >> and so on... As they say, if the only tool you have is timetuple, everything >> looks like tuple Try this: >> >>>>> dt = datetime(2005, 1, 1, 12, 0, 0) >>>>> dt.date() >> >> datetime.date(2005, 1, 1) > > This doesn't solve it. I don't think you understand my issue. I understand, but I don't think it's something that should be solved. Especially date(*dt.timetuple()[:3]) > class my_datetime(datetime): > > def __add__(self, other): > result = datetime.__add__(self, other) > return my_datetime(result.timetuple()[:6]) > What about: def __add__(self, other): result = datetime.__add__(self, other) return my_datetime.fromdatetime(result) Serge. From jjl at pobox.com Sat Jan 29 07:07:19 2005 From: jjl at pobox.com (John J. Lee) Date: 29 Jan 2005 12:07:19 +0000 Subject: cookielib and urllib2: thread-safe? References: Message-ID: <87vf9gv3pk.fsf@pobox.com> Alex Hunsley writes: > I'm writing a test script in python for pulling web pages from a web > server using urllib2 and cookielib. Since the main thing I am testing > is what happens when concurrent requests are made to the web server, I > need to make several requests concurrently, which I'll do from > different threads in my python script. So the important question is: > are cookielib and urllib2 thread safe? Are there any precautions that > apply to using these libs in a multi-threaded context? urllib2: For HTTP, yes, AFAIK. For other protocols, eg. FTP, perhaps not. cookielib: No. It's currently thread-broken, simply because I've never had reason to do threaded stuff with it. There is thread synchronization code in there, but I have little doubt that it's broken, because it's untested (I should have removed the synchronization code entirely, in fact, since nobody volunteered to test & fix before release: unfortunately the first beta caught me by surprise...). I won't be making it threadsafe, so don't wait for me to do it. I'm happy to help others do so. Nothing especially hard for somebody with plenty of thread experience to do, AFAIK. I had thought part of a patch had gone in which stated this thread-unsafety very prominently in the cookielib module docs, but it seems that never happened, or at least not in time for 2.4.0 -- eek! John From unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom Thu Jan 13 07:26:23 2005 From: unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom (Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.) Date: Thu, 13 Jan 2005 13:26:23 +0100 Subject: Free python server. References: Message-ID: <41e66aa0$0$25801$8fcfb975@news.wanadoo.fr> Hi ! Server, web ? Files server ? Web-services server ? XML-RPC server ? Mail-server ? Newsgroups server ? SGBD server ? Object server ? Persistance server ? Restaurant server ? or ALL ? From http Fri Jan 14 01:19:17 2005 From: http (Paul Rubin) Date: 13 Jan 2005 22:19:17 -0800 Subject: Pickled text file causing ValueError (dos/unix issue) References: <1105682410.406541.317590@c13g2000cwb.googlegroups.com> Message-ID: <7xk6qga5y2.fsf@ruckus.brouhaha.com> Open the file on windows for writing with "wb" mode, the b is for binary. From dave.benjamin at gmail.com Thu Jan 27 11:30:41 2005 From: dave.benjamin at gmail.com (Dave Benjamin) Date: Thu, 27 Jan 2005 09:30:41 -0700 Subject: python without OO In-Reply-To: <1106689788.676121.48490@c13g2000cwb.googlegroups.com> References: <1106689788.676121.48490@c13g2000cwb.googlegroups.com> Message-ID: Davor wrote: > Is it possible to write purely procedural code in Python, or the OO > constructs in both language and supporting libraries have got so > embedded that it's impossible to avoid them? Also, is anyone aware of > any scripting language that could be considered as "Python minus OO > stuff"? (As you can see I'm completely new to Python and initially > believed it's a nice&simple scripting language before seeing all this > OO stuff that was added in over time) Many people have answered your question already, but I thought I would share my opinion as well, since I think I understand where you are coming from. What attracted me to Python was not OO at all but the fact that it was somewhat similar to PHP (which I was using heavily at the time) but allowed me to encode certain higher-order programming techniques that PHP simply could not express. In short, I had become interested in functional programming after reading David Mertz's "Charming Python" tutorials, and after x attempts at trying to port the ideas to PHP, I finally gave up in frustration and started learning Python. At the time, I was decidedly anti-OO. I grew up around a very liberal, punk-rock, nonconformist culture, and the amount of hype around OO made it too easy to hate (and, I suppose, it still does). PHP at the time was 90% procedural; the prevaling attitude (which seems to have changed with the advent of PHP5) was that procedural code is all you need to solve most problems. With web scripting, it kind of makes sense, because (IMHO) objects really don't have much value unless you can hold onto them long enough for them to be useful, and many web scripts just pipe data from one place to another. Packing the data into objects is kind of like putting your possessions into boxes so that you can move them from one room to another and immediately unpack. So, I guess you could say, I learned Python in spite of its rich support for OO. =) It wasn't until I had to implement a large (to me), complex, graphical user interface, that I finally had to get off of my soapbox and realize that I had no better way to create sophisticated GUIs than OO. There are surely non-OO ways to build fancy GUIs, like functional-reactive programming, but a) I don't understand them, and b) I had to get my project done, and used the tools I had and the techniques I knew. At that time, I started learning about Smalltalk and Alan Kay's emphasis on the "messaging" aspect of OO, and it started making a lot more sense. One of the most difficult tasks sometimes is getting various parts of the screen to update when the user changes a field or clicks a button--in a way that is manageable and doesn't devolve into spaghetti. Aside from GUIs, however, I am rarely confronted with a task where I *need* OO. As a method for encoding abstract data types, it works, but it seems like more fashion than substance. As many have pointed out, the difference between "method(obj, args)" and "obj.method(args)" is subtle, and often inconsequential. In Python, you can program with just modules and functions/procedures, and never bother with the fact that you are using objects. Sure, a module is an object, and so is a procedure, but it's not all up in your face like, say, Java's arcane restriction that everything belong to some class. It has been said of Perl programmers that they often dislike abstraction. Sometimes, I really sympathize with this viewpoint. I hate having to use a class that offers no value to the problem whatsoever, merely because an API is hard-wired to use instances of that class. No abstraction can often be better than a bad abstraction, and when it comes to debugging, the last thing you want is a bunch of black boxes. These days, I do use classes and objects in Python, but mainly as a code organization technique, and only when I actually want my code organized that way. I tend to start with the problem at hand, building procedures to remove redundancy and keep my code small and simple. If I start noticing that a lot of procedures revolve around a particular data structure, I refactor them into a class. This way, I avoid creating abstractions that don't fit. It's much more mechanical than any feigned attempt at "modeling the real world". I think that functional programming (FP) is a very powerful methodology that can solve a lot of the same problems as OO, and does some things a lot better. FP and OO can live in harmony to some extent, but there are some places where they contradict each other. For instance, FP offers a mind-blowingly powerful tool called pattern matching, which is like a switch/case statement on steroids. OO dogma insists that this "violates encapsulation", and that any form of switch/case is evil... replace conditional with polymorphism... replace conditional with polymorphism... replace conditional with polymorphism... repl On the other hand, implementing something as seemingly simple as a "__str__" method in functional languages can be surprisingly non-trivial. The lesson to be learned here is that each methodology (including strctures/procedural) has its strong points and weak points, and there are always tradeoffs to be made. OO's biggest strong point is that a lot of people grok it, so it's a fashionable and friendly user interface for a programmer. Python in particular emphasizes this point with its no-nonsense, lightweight approach to defining classes and using objects. However, and this really the main point I wanted to make: *no* paradigm is sufficient to solve any interesting problem. I have gotten sucked into coutless language and paradigm pissing matches only to go back to my desk and try to finish a project I'm working on and realize that (gasp!) programming is still hard. It never stopped being hard! And sometimes the methodologies just create additional work (cf. jwz's comment on regular expressions: "now you have two problems"). The best way to crack through tough problems is to learn as many methods and techniques as you can, and develop an intuition for "the right tool for the job". What matters most is that you solve the problem at hand, in a way that people can hopefully understand and maintain later. Good luck, Dave From klachemin at comcast.net Sat Jan 22 01:08:59 2005 From: klachemin at comcast.net (Kamilche) Date: 21 Jan 2005 22:08:59 -0800 Subject: Reload Tricks In-Reply-To: References: <1106368177.530867.313610@c13g2000cwb.googlegroups.com> Message-ID: <1106374139.853129.73310@z14g2000cwz.googlegroups.com> Would it be possible to just not copy any attribute that starts and ends with '__'? Or are there some important attributes being copied? From merkosh at hadiko.de Fri Jan 28 07:30:20 2005 From: merkosh at hadiko.de (Uwe Mayer) Date: Fri, 28 Jan 2005 13:30:20 +0100 Subject: example needed: sip + Qt Message-ID: Hi, can someone provide me with a running example for subclassing QWidget (or something similarly simple) in C++ and then creating SIP (4.x+) bindings for in for Python (2.3+)? I am looking for something I can start of with and work my way towards more complicated stuff (with Qt). The QLabel example in the SIP reference manual yields syntax errors for me. Same with: http://www.pegasus.rutgers.edu/~elflord/unix/siptute/subclass_example.tgz thanks, Uwe From ehenriqu at gmail.com Thu Jan 20 10:52:27 2005 From: ehenriqu at gmail.com (Eduardo Henriquez A.) Date: Thu, 20 Jan 2005 11:52:27 -0400 Subject: Python-list Digest, Vol 16, Issue 324 In-Reply-To: <20050120144143.7F2DB1E4011@bag.python.org> References: <20050120144143.7F2DB1E4011@bag.python.org> Message-ID: <810c6a5805012007521ea04edf@mail.gmail.com> On Thu, 20 Jan 2005 15:41:43 +0100 (CET), python-list-request at python.org wrote: > Send Python-list mailing list submissions to > python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-request at python.org > > You can reach the person managing the list at > python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > > > Today's Topics: > > 1. Re: Class introspection and dynamically determining function > arguments (Diez B. Roggisch) > 2. Re: xml parsing escape characters (Luis P. Mendes) > 3. Problem in importing MySQLdb (Gurpreet Sachdeva) > 4. Re: Problem in importing MySQLdb (deelan) > 5. Re: mod_python friendly isps in europe (Daniel Bowett) > 6. Re: xml parsing escape characters (Kent Johnson) > 7. Re: Zen of Python (Steve Holden) > 8. Re: Freezing a mutable (was Re: lambda) (Antoon Pardon) > 9. Re: iteritems() and enumerate() (Steve Holden) > 10. Re: ElementTree cannot parse UTF-8 Unicode? (Erik Bethke) > 11. Re: ElementTree cannot parse UTF-8 Unicode? (Fredrik Lundh) > > > > ---------- Forwarded message ---------- > From: "Diez B. Roggisch" > To: python-list at python.org > Date: Thu, 20 Jan 2005 13:50:37 +0100 > Subject: Re: Class introspection and dynamically determining function arguments > Nick Coghlan wrote: > > > > If this only has to work for classes created for the purpose (rather than > > for an arbitrary class): > > > > Certainly a step into the direction I meant - but still missing type > declarations. And that's what at least I'd like to see - as otherwise you > don't know what kind of editing widget to use for a property. > -- > Regards, > > Diez B. Roggisch > > > > ---------- Forwarded message ---------- > From: "Luis P. Mendes" > To: python-list at python.org > Date: Thu, 20 Jan 2005 13:05:59 +0000 > Subject: Re: xml parsing escape characters > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > this is the xml document: > > > <DataSet> > ~ <Order> > ~ <Customer>439</Customer> > (... others ...) > ~ </Order> > </DataSet> > > When I do: > > print xmldoc.toxml() > > it prints: > > <DataSet> > ~ <Order> > ~ <Customer>439</Customer> > > ~ </Order> > </DataSet> > > __________________________________________________________ > with: stringNode = xmldoc.childNodes[0] > print stringNode.toxml() > I get: > <DataSet> > ~ <Order> > ~ <Customer>439</Customer> > > ~ </Order> > </DataSet> > ______________________________________________________________________ > > with: DataSetNode = stringNode.childNodes[0] > print DataSetNode.toxml() > > I get: > > <DataSet> > ~ <Order> > ~ <Customer>439</Customer> > > ~ </Order> > </DataSet> > _______________________________________________________________- > > so far so good, but when I issue the command: > > print DataSetNode.childNodes[0] > > I get: > IndexError: tuple index out of range > > Why the error, and why does it return a tuple? > Why doesn't it return: > <Order> > <Customer>439</Customer> > > </Order> > ?? > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.2.4 (GNU/Linux) > Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org > > iD8DBQFB76y3Hn4UHCY8rB8RAvQsAKCFD/hps8ybQli8HAs3iSCvRjwqjACfS/12 > 5gctpB91S5cy299e/TVLGQk= > =XR2a > -----END PGP SIGNATURE----- > > > > ---------- Forwarded message ---------- > From: Gurpreet Sachdeva > To: python-list at python.org > Date: Thu, 20 Jan 2005 18:53:06 +0530 > Subject: Problem in importing MySQLdb > I am using Mysql version 5.0.2-alpha on RedHat 9.0 (python2.2) > > When I try to import MySQldb > > I get: > Python 2.2.2 (#1, Feb 24 2003, 19:13:11) > [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import MySQLdb > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/lib/python2.2/site-packages/MySQLdb/__init__.py", line 27, in ? > import _mysql > ImportError: /usr/lib/libmysqlclient.so.10: symbol errno, version > GLIBC_2.0 not defined in file libc.so.6 with link time reference > > Is there any problem in library files?? Do I need to install anything > I have installed MySQL-shared-3.23.54a-1.i386.rpm, > MySQL-devel-5.0.2-0.i386.rpm, MySQL-client-5.0.2-0.i386.rpm, > MySQL-server-5.0.2-0.i386.rpm > > Please help, > Garry > > > > ---------- Forwarded message ---------- > From: deelan > To: python-list at python.org > Date: Thu, 20 Jan 2005 14:43:01 +0100 > Subject: Re: Problem in importing MySQLdb > Gurpreet Sachdeva wrote: > > I am using Mysql version 5.0.2-alpha on RedHat 9.0 (python2.2) > > > > When I try to import MySQldb > > i' not completely sure mysqldb works with mysql 5.0 and its > bundled client libraries. > > to be more precise: > > '' MySQL-5.0 and newer are not currently supported, > but might work.'' > > from: > > > > Is there any problem in library files?? Do I need to install anything > > I have installed MySQL-shared-3.23.54a-1.i386.rpm, > > MySQL-devel-5.0.2-0.i386.rpm, MySQL-client-5.0.2-0.i386.rpm, > > MySQL-server-5.0.2-0.i386.rpm > > are u sure you have compiled mysqldb against 5.0 > client libs? > > you may want to post on the mysqldb forum of ask > for help there: > > > > HTH, > deelan > > -- > @prefix foaf: . > <#me> a foaf:Person ; foaf:nick "deelan" ; > foaf:weblog . > > > > ---------- Forwarded message ---------- > From: Daniel Bowett > To: python-list at python.org > Date: Thu, 20 Jan 2005 08:48:37 +0000 > Subject: Re: mod_python friendly isps in europe > paulo.jpinto at gmail.com wrote: > > Hello everybody > > > > I'm thinking about improving my web site scripts > > and would like to use Python instead of PHP/Perl. > > > > Does anyone know of mod_python friendly ISPs in > > europe? With prices around 10? ? > > > > Thanks in advance, > > Paulo > > > > I would doubt you will find any commercial python ISP's out there. If > you do could you post them here? > > > > ---------- Forwarded message ---------- > From: Kent Johnson > To: python-list at python.org > Date: Thu, 20 Jan 2005 09:01:01 -0500 > Subject: Re: xml parsing escape characters > Luis P. Mendes wrote: > > -----BEGIN PGP SIGNED MESSAGE----- > > Hash: SHA1 > > > > this is the xml document: > > > > > > > > ~ > > ~ 439 > > (... others ...) > > ~ > > > > This is an XML document containing a single tag, , whose content is text containing > entity-escaped XML. > > This is *not* an XML document containing tags , , , etc. > > All the behaviour you are seeing is a consequence of this. You need to unescape the contents of the > tag to be able to treat it as structured XML. > > Kent > > > > ---------- Forwarded message ---------- > From: Steve Holden > To: python-list at python.org > Date: Thu, 20 Jan 2005 09:04:00 -0500 > Subject: Re: Zen of Python > Paul Rubin wrote: > > > Tim Peters writes: > > > >>>Huh? [1,2,[3,4,5],[6,[[[[7]],8]]]] is a perfectly valid Python list. > >> > >>You're claiming not to know any relevant difference between Python > >>lists and Lisp lists? Heh. > > > > > > Python doesn't provide syntactic sugar for [1,[2,[3,[4,[]]]]] if > > that's what you mean. In Lisp you'd say (1 2 3 4). It's still > > a perfectly valid list in Python. Python by convention uses > > multi-element arrays instead of lists of conses. > > > But how, in Lisp, would you transliterate the Python list [1, 2, 3, 4]? > Clearly the Python list *is* different, and the tradeoff was to obtain > speed of random access, presumably (I wasn't taking an interest in > Python in its early days) anticipating that non-recursive algorithms > would be the norm. > > > >>>And you can break out of a containing loop from a nested loop > >>>with try/raise. > >> > >>Heh heh. Yes, you can. I've never seen a real Python program that > >>did, but there's nothing to stop you. > > > > > I do that on a fairly routine basis. I won't say "often", but it's a > > standard technique that finds a use now and then. > > > Well, I blush to say I have done that (once, if my memory serves me > correctly), but it was an ugly program, and I did eventually refactor > the code so that the loops were in separate scopes, which made it much > cleaner. > > [...] > > > > There's a technique in numerical analysis called Richardson > > extrapolation, where you compute an integral by [...] > > Wow. Anyone who feels the need to explain numerical analysis techniques > to Tim Peters is wasting keystrokes big-time. Anyway, Richardson > extrapolation is merely one of many successive approximation techniques, > which is what you are talking about, no? > > > > > I see the same thing happening in Python. It's going through > > successively better approximations to get closer to a limit. Python > > has it harder than some other languages, because it tries to serve the > > needs of both throwaway scripts and large-scale development projects. > > The result is that feature after feature starts out with an > > implementation sufficient for small scripts, and then edges towards > > the needs of large-scale projects. But it's often predictable at the > > beginning what the final destination is going to be. So once we can > > see where it's going, why not proceed to the finish line immediately > > instead of bothering with the intermediate steps? > > Perhaps because we don't all have your psychic powers? > > regards > Steve > -- > Steve Holden http://www.holdenweb.com/ > Python Web Programming http://pydish.holdenweb.com/ > Holden Web LLC +1 703 861 4237 +1 800 494 3119 > > > > ---------- Forwarded message ---------- > From: Antoon Pardon > To: python-list at python.org > Date: 20 Jan 2005 14:07:57 GMT > Subject: Re: Freezing a mutable (was Re: lambda) > Op 2005-01-20, Nick Coghlan schreef : > > Antoon Pardon wrote: > >> I missed that you would use it with the idiom: dct[x.frozen()] > > > > The list itself isn't hashable with this approach, so you don't have much > > choice. I wasn't particularly clear about that point, though. > > > >> I have two problems with this approach. > >> > >> 1) It doesn't work when you get your keys via the keys/items > >> methods. > > > > True - the frozen object has no link back to the original object. That could be > > added though (by returning a tuple subtype with the extra attribute) > > > >> 2) This is rather minor, but a user could still unfreeze > >> untimely > > > > True - doing that is less likely than mutating a hashable list though :) > > > > I'm just noting this as a way to avoid copying data more than once when storing > > immutable copies of mutable data in a dictionary. You're quite right that there > > isn't a really clean idiom for doing that in Python (aside from moving to a > > different data structure that works natively as a dict key, naturally). > > The problem here is IMO is the, we are all consenting adults (which we > are not but I wont start on this now), approach. > > I have been thinking a bit in your freeze direction, but more thorough. > The idea i had was that freeze would replace all mutating methods > with methods that would throw an exception. a thaw method would inverse > the proces. It would then be the responsibilty of the dictionary to > freeze an object on entry and thaw it when removed. However this > wouldn't work with ordinary python objects, since there is no easy way > to have readonly or private variables. > > -- > Antoon Pardon > > > > ---------- Forwarded message ---------- > From: Steve Holden > To: python-list at python.org > Date: Thu, 20 Jan 2005 09:07:39 -0500 > Subject: Re: iteritems() and enumerate() > Xah Lee wrote: > > > Python has iteritems() and enumerate() to be used in for loops. > > > > can anyone tell me what these are by themselves, if anything? > > > > are they just for idiom? > > No, anyone can use them, not just idioms like you. > > regards > Steve > -- > Steve Holden http://www.holdenweb.com/ > Python Web Programming http://pydish.holdenweb.com/ > Holden Web LLC +1 703 861 4237 +1 800 494 3119 > > > > ---------- Forwarded message ---------- > From: "Erik Bethke" > To: python-list at python.org > Date: 20 Jan 2005 06:20:46 -0800 > Subject: Re: ElementTree cannot parse UTF-8 Unicode? > There is something wrong with the physical file... I d/l a trial > version of XML Spy home edition and built an equivalent of the korean > test file, and tried it and it got past the element tree error and now > I am stuck with the wxEditCtrl error. > > To build the xml file in the first place I had code that looked like > this: > > d=wxFileDialog( self, message="Choose a file", > defaultDir=os.getcwd(), defaultFile="", wildcard="*.xml", style=wx.SAVE > | wxOVERWRITE_PROMPT | wx.CHANGE_DIR) > if d.ShowModal() == wx.ID_OK: > # This returns a Python list of files that were selected. > paths = d.GetPaths() > layout = '\n' > L1Word = self.t1.GetValue() > L2Word = 'undefined' > > layout += '\n' > layout += ' \n' > layout += '' > open( paths[0], 'w' ).write(layout) > d.Destroy() > > So apprantly there is something wrong with physically constructing the > file in this manner? > > Thank you, > -Erik > > > > ---------- Forwarded message ---------- > From: "Fredrik Lundh" > To: python-list at python.org > Date: Thu, 20 Jan 2005 15:40:35 +0100 > Subject: Re: ElementTree cannot parse UTF-8 Unicode? > Erik Bethke wrote: > > > layout += '\n' > > layout += ' \n' > > what does "print repr(L1Word)" print (that is, what does wxPython return?). > it should be a Unicode string, but that would give you an error when you write > it out: > > >>> f = open("file.txt", "w") > >>> f.write(u'\uc5b4\ub155\ud558\uc138\uc694!') > Traceback (most recent call last): > File "", line 1, in ? > UnicodeEncodeError: 'ascii' codec can't encode characters > in position 0-4: ordinal not in range(128) > > have you hacked the default encoding in site/sitecustomize? > > what happens if you replace the L1Word term with L1Word.encode("utf-8") > > can you post the repr() (either of what's in your file or of the thing, whatever > it is, that wxPython returns...) > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Atte, Eduardo Henr?quez A. 9-6975236 From kartic.krishnamurthy at gmail.com Wed Jan 26 16:55:52 2005 From: kartic.krishnamurthy at gmail.com (Kartic) Date: 26 Jan 2005 13:55:52 -0800 Subject: wx.Image: Couldn't add an image to the image list. References: Message-ID: <1106776552.518189.147400@c13g2000cwb.googlegroups.com> Laszlo, If you are using PIL just for scaling, you can do away with PIL. Even if you do other things with PIL, you can use the Rescale method of the wx.Image instance to resize. Here is the code (adapted from the Demo): data = open('C:/TEMP/test.bmp'), "rb").read() stream = cStringIO.StringIO(data) img = wx.ImageFromStream( stream ) img.Rescale(32, 32) # Resize your image to 32x32 bmp = wx.BitmapFromImage( img ) # Convert Image to Bitmap # Now display Bitmap in Panel wx.StaticBitmap(self, -1, bmp, (bmp.GetWidth(), bmp.GetHeight())) Try this and see if this works for you. Thank you, --Kartic From support at convertzone.com Tue Jan 4 11:22:08 2005 From: support at convertzone.com (support at convertzone.com) Date: 4 Jan 2005 08:22:08 -0800 Subject: Using python to convert PDF document to MSWord documents In-Reply-To: References: <20040928161317.88987.qmail@web8401.mail.in.yahoo.com> Message-ID: <1104855728.542769.220760@c13g2000cwb.googlegroups.com> You can use "pdf to word", it can help you to batch convert pdf to word or text at one time, keeping source layout, and Standalone software, MS Word, Adobe Acrobat and Reader NOT required! and you can get more information from http://www.convertzone.com/net/cz-PDF%20to%20Word-1-1.htm. ConvertZone Support team ConvertZone Software Co,.ltd http://www.convertzone.com support at convertzone.com ************************************************************ ConvertZone provides office(PDF, Word, Excel, PowerPoint, AutoCAD etc), video(DVD, VCD, SVCD etc), audio(MP3, WAV, MIDI etc), image(JPG, GIF, TIF, BMP etc) file converter. ************************************************************ From klachemin at comcast.net Fri Jan 21 23:29:37 2005 From: klachemin at comcast.net (Kamilche) Date: 21 Jan 2005 20:29:37 -0800 Subject: Reload Tricks Message-ID: <1106368177.530867.313610@c13g2000cwb.googlegroups.com> I want my program to be able to reload its code dynamically. I have a large hierarchy of objects in memory. The inheritance hierarchy of these objects are scattered over several files. I find that after reloading the appropriate files, and overwriting the __class__ of object instances, one more thing is necessary: reloading the __bases__ of each reloaded class. If I don't do this, the modules reloaded first point to old versions of the classes from later modules, and when the later module is reloaded, it doesn't update the inheritance hierarchy of classes already loaded. This appears to be working... but now I'm wondering, what else did it not change? Can I expect more toes to be blown off? --Kamilche From dave at pythonapocrypha.com Sun Jan 23 23:17:09 2005 From: dave at pythonapocrypha.com (Dave Brueck) Date: Sun, 23 Jan 2005 21:17:09 -0700 Subject: Determining if a client PC has an Internet connection In-Reply-To: <1106364768.871474.92810@z14g2000cwz.googlegroups.com> References: <1095578301.31957.263.camel@devilbox.devilnet.internal> <1106364768.871474.92810@z14g2000cwz.googlegroups.com> Message-ID: <41F476C5.6020007@pythonapocrypha.com> torment wrote: [snip] > Have you tried just parsing the output from the command "ipconfig"? > > It's pretty obvious from the output that might give you if a connection > is availible. It's tempting to use ipconfig's output, but the info it gives you is unreliable - you can incorrectly infer the presence of an net connection when you don't really have one (if you also run VMWare, if you have installed a loopback adapter, if you have a static public IP, etc.). -Dave From michele.simionato at gmail.com Mon Jan 31 00:42:22 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 30 Jan 2005 21:42:22 -0800 Subject: future of computing languages In-Reply-To: <1107003465.707681.161950@f14g2000cwb.googlegroups.com> References: <1107003465.707681.161950@f14g2000cwb.googlegroups.com> Message-ID: <1107150142.589225.85200@z14g2000cwz.googlegroups.com> I found that page very shallow and superficial. What they call "the language of the future" is actually the language of the present. Python (but also, Ruby, Perl, Smalltalk, Lisp, Scheme, ...) have already most of the features they list. Then they claim "the language of the future will be so different from the languages we have now that we cannot imagine how it will be". This is pretty naive. A Lisper would say that nothing new happened in the last 40 years. Actually, I think that something new happened, but not that much. The progress was more in the technology than in the programming paradigms. I mean, OO was already there in Simula. It this very possible that the language of 2045 will not be very different from the current dynamic languages. The all page reminds me of the excitation of 60's about the space program (affirmations such "in the year 2000 we will have colonies on Mars") We all know how it ended :-( Michele Simionato From aleaxit at yahoo.com Fri Jan 7 05:55:08 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 7 Jan 2005 11:55:08 +0100 Subject: Python evolution: Unease References: <7xacrpdxy3.fsf@ruckus.brouhaha.com> <7x652che6z.fsf@ruckus.brouhaha.com> <7x4qhw859p.fsf@ruckus.brouhaha.com> <7xk6qrnbum.fsf@ruckus.brouhaha.com> <41dcaa00.102858012@news.oz.net> <7x652bnhx0.fsf@ruckus.brouhaha.com> <41dcf582.122188317@news.oz.net> <7xd5wh7qdf.fsf@ruckus.brouhaha.com> Message-ID: <1gq0odo.1x1uyr2kgdgiyN%aleaxit@yahoo.com> Paul Rubin wrote: > Really, I just want to buy a new > computer, turn it on, and have everything there. That's generally > impossible without running satanware from Redmond The princes of insufficient light from Cupertino will in fact be very happy to sell you such computers, and _their_ definition of "everything" includes a bit more than the Redmonders' (e.g., Python is there, perl is there, gcc is there, so is Apache, a good development GUI-based IDE, emacs, a solid firewall, a _usable_ Terminal/commandline program to run bash or tcsh on, ...), though it's no doubt still missing many pieces that you or I might want as parts of *our* "everything" (gvim rather than just vim, GUI/IDEs for Python, Python add-ons such as numarray, gmpy, ctypes, ...) -- all of those you still have to download and install, just as you would for the satanware. Alex From fredrik at pythonware.com Fri Jan 21 12:17:11 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 21 Jan 2005 18:17:11 +0100 Subject: circular iteration References: Message-ID: "Flavio codeco coelho" wrote: > is there a faster way to build a circular iterator in python that by doing this: > > c=['r','g','b','c','m','y','k'] > > for i in range(30): > print c[i%len(c)] have you benchmarked this, and found it lacking, or are you just trying to optimize prematurely? From Serge.Orlov at gmail.com Fri Jan 14 16:23:27 2005 From: Serge.Orlov at gmail.com (Serge Orlov) Date: Fri, 14 Jan 2005 21:23:27 +0000 (UTC) Subject: oddities in the datetime module References: <41e79a1a$0$264$edfadb0f@dread12.news.tele.dk> Message-ID: Max M wrote: > # -*- coding: latin-1 -*- > > """ > > I am currently using the datetime package, but I find that the design > is oddly > asymmetric. I would like to know why. Or perhaps I have misunderstood > how it should be used? Yes, you did. datetime.timetuple is those who want *time module* format, you should use datetime.data, datetime.time, datetime.year and so on... [snip a lot of timetuple wrestling] > The other way around is also easy. > >>>> dt = datetime(2005, 1, 1, 12, 0, 0) >>>> date(*dt.timetuple()[:3]) > datetime.date(2005, 1, 1) As they say, if the only tool you have is timetuple, everything looks like tuple Try this: >>> dt = datetime(2005, 1, 1, 12, 0, 0) >>> dt.date() datetime.date(2005, 1, 1) Serge. From aahz at pythoncraft.com Fri Jan 7 16:05:43 2005 From: aahz at pythoncraft.com (Aahz) Date: 7 Jan 2005 16:05:43 -0500 Subject: Software archeology (was Re: Developing Commercial Applications in Python) References: <1104750017.235937.181370@c13g2000cwb.googlegroups.com> <87pt0iegga.fsf@localhost.localdomain.i-did-not-set--mail-host-address--so-tickle-me> Message-ID: In article , Stephen Waterbury wrote: >> eeykay at gmail.com writes: >>> >>>Can somebody there to point me any good commercial applications >>>developed using python ? > >Also see Python Success Stories: http://pythonology.org/success > >A notable example is Verity's search engine -- see >http://python.oreilly.com/news/PythonSS.pdf Actually, your statement is slightly inaccurate. The Verity search engine is more than fifteen years old in its core technology; it was started as a LISP project at IIRC MIT. (At one point I was much amused to look at the C source code and find car() and cdr() functions.) As of my last information, Python isn't used at all in or with the Verity search engine. What you're referring to is the Verity Ultraseek engine, originally written and owned by Infoseek before getting transferred to Verity through a series of dot-bomb transactions. The Ultraseek engine doesn't use Python, but Python is used to control the engine, and I think much of the spider is written in Python. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "19. A language that doesn't affect the way you think about programming, is not worth knowing." --Alan Perlis From __peter__ at web.de Sat Jan 22 03:56:45 2005 From: __peter__ at web.de (Peter Otten) Date: Sat, 22 Jan 2005 09:56:45 +0100 Subject: default value in a list References: <1106349263.943972.72710@f14g2000cwb.googlegroups.com> Message-ID: Paul McGuire wrote: >> Is there an elegant way to assign to a list from a list of unknown >> size? For example, how could you do something like: >> >> >>> a, b, c = (line.split(':')) >> if line could have less than three fields? > I asked a very similar question a few weeks ago, and from the various > suggestions, I came up with this: > > line = "AAAA:BBB" > expand = lambda lst,default,minlen : (lst + [default]*minlen)[0:minlen] > a,b,c = expand( line.split(":"), "", 3 ) Here is an expand() variant that is not restricted to lists but works with arbitrary iterables: from itertools import chain, repeat, islice def expand(iterable, length, default=None): return islice(chain(iterable, repeat(default)), length) Peter From lee at example.com Tue Jan 25 17:57:16 2005 From: lee at example.com (Lee Harr) Date: Tue, 25 Jan 2005 22:57:16 GMT Subject: Another scripting language implemented into Python itself? References: